[DevState] tested rply

This commit is contained in:
Sven Heidemann 2020-09-25 17:07:20 +02:00
parent c537a95043
commit 9812f8a210
7 changed files with 41 additions and 25 deletions

View File

@ -1,8 +1,8 @@
from typing import Optional from typing import Optional
from CCLang.Parser import Parser from CCLang_sly.Parser import Parser
from Interpreter.Validator import Validator from Interpreter.Validator import Validator
from CCLang.Lexer import Lexer from CCLang_sly.Lexer import Lexer
from Interpreter.Repo import Repo from Interpreter.Repo import Repo
from Interpreter.Utils import Utils from Interpreter.Utils import Utils
from Models.AbstractSyntaxTree.AbstractSyntaxTree import AbstractSyntaxTree from Models.AbstractSyntaxTree.AbstractSyntaxTree import AbstractSyntaxTree

View File

@ -79,12 +79,12 @@ class Lexer(SlyLexer):
FOR = TokenDefinition.For.value FOR = TokenDefinition.For.value
PUBLIC = TokenDefinition.Public.value PUBLIC = TokenDefinition.Public.value
THIS = TokenDefinition.This.value THIS = TokenDefinition.This.value
LBRACE = TokenDefinition.Left_Brace.value LBRACE = TokenDefinition.LeftBrace.value
RBRACE = TokenDefinition.Right_Brace.value RBRACE = TokenDefinition.RightBrace.value
LPARAN = TokenDefinition.Left_Parenthesis.value LPARAN = TokenDefinition.LeftParenthesis.value
RPARAN = TokenDefinition.Right_Parenthesis.value RPARAN = TokenDefinition.RightParenthesis.value
LBRACKET = TokenDefinition.Left_Bracket.value LBRACKET = TokenDefinition.LeftBracket.value
RBRACKET = TokenDefinition.Right_Bracket.value RBRACKET = TokenDefinition.RightBracket.value
SEMICOLON = TokenDefinition.Semicolon.value SEMICOLON = TokenDefinition.Semicolon.value
COLON = TokenDefinition.Colon.value COLON = TokenDefinition.Colon.value
COMMA = TokenDefinition.Comma.value COMMA = TokenDefinition.Comma.value

View File

@ -1,6 +1,6 @@
from sly import Parser as SlyParser from sly import Parser as SlyParser
from CCLang.Lexer import Lexer from CCLang_sly.Lexer import Lexer
class Parser(SlyParser): class Parser(SlyParser):

View File

@ -10,12 +10,14 @@ class TokenDefinition(Enum):
Variable = r'var' Variable = r'var'
Use = r'use' Use = r'use'
From = r'from' From = r'from'
As = r'as'
# builtin functions # builtin functions
Output = r'output' Output = r'output'
Input = r'input' Input = r'input'
Length = r'length' Length = r'length'
Range = r'range' Range = r'range'
Round = r'round'
Exit = r'exit' Exit = r'exit'
# normal keywords # normal keywords
@ -23,12 +25,12 @@ class TokenDefinition(Enum):
ElseIf = r'elseif' ElseIf = r'elseif'
Else = r'else' Else = r'else'
Continue = r'continue' Continue = r'continue'
In = r'in'
Return = r'return' Return = r'return'
# loops # loops
While = r'while' While = r'while'
For = r'for' For = r'for'
In = r'in'
# access # access
Public = r'public' Public = r'public'
@ -36,12 +38,12 @@ class TokenDefinition(Enum):
""" Chars """ """ Chars """
# format # format
Left_Brace = r'\{' LeftBrace = r'\{'
Right_Brace = r'\}' RightBrace = r'\}'
Left_Parenthesis = r'\(' LeftParenthesis = r'\('
Right_Parenthesis = r'\)' RightParenthesis = r'\)'
Left_Bracket = r'\[' LeftBracket = r'\['
Right_Bracket = r'\]' RightBracket = r'\]'
Semicolon = r'\;' Semicolon = r'\;'
Colon = r'\:' Colon = r'\:'
Comma = r'\,' Comma = r'\,'
@ -55,13 +57,21 @@ class TokenDefinition(Enum):
Caret = r'\^' Caret = r'\^'
""" Values """ """ Values """
ValueString = r'\".*?\"'
ValueNumber = r'\d+'
# bool # bool
BoolTrue = r'true' BoolTrue = r'true'
BoolFalse = r'false' BoolFalse = r'false'
Name = r'[a-zA-Z_][a-zA-Z0-9_]*'
String = r'\".*?\"'
Number = r'\d+'
""" Datatypes """ """ Datatypes """
Empty = r'empty' Empty = r'empty'
Number = r'Number'
String = r'string'
Bool = r'bool'
List = r'list'
Dict = r'dict'
Void = r'void'
""" other """
Name = r'[a-zA-Z_][a-zA-Z0-9_]*'

View File

@ -1,6 +1,7 @@
from Interpreter.Validator import Validator from Interpreter.Validator import Validator
from Interpreter.Interpreter import Interpreter from Interpreter.Interpreter import Interpreter
from CCLang.Interpreter import Interpreter as CCLangInterpreter from CCLang_sly.Interpreter import Interpreter as SlyCCLangInterpreter
from CCLang_rply.Interpreter import Interpreter as RplyCCLangInterpreter
from Interpreter.Utils import Utils from Interpreter.Utils import Utils
from Interpreter.Repo import Repo from Interpreter.Repo import Repo
@ -11,4 +12,5 @@ class ServiceInitializer:
self.repo = Repo() self.repo = Repo()
self.utils = Utils(self.repo) self.utils = Utils(self.repo)
self.interpreter = Interpreter(self.repo, self.utils) self.interpreter = Interpreter(self.repo, self.utils)
self.cclang_interpreter = CCLangInterpreter(self.repo, self.utils) self.sly_cclang_interpreter = SlyCCLangInterpreter(self.repo, self.utils)
self.rply_cclang_interpreter = RplyCCLangInterpreter(self.repo, self.utils)

View File

@ -12,7 +12,8 @@ class Main:
self.__utils = self.__services.utils self.__utils = self.__services.utils
self.__repo = self.__services.repo self.__repo = self.__services.repo
self.__interpreter = self.__services.interpreter self.__interpreter = self.__services.interpreter
self.__cclang_interpreter = self.__services.cclang_interpreter self.__sly_cclang_interpreter = self.__services.sly_cclang_interpreter
self.__rply_cclang_interpreter = self.__services.rply_cclang_interpreter
def console(self) -> None: def console(self) -> None:
""" """
@ -22,7 +23,9 @@ class Main:
i = 0 i = 0
while self.__repo.error is None: while self.__repo.error is None:
self.__repo.line_number = i + 1 self.__repo.line_number = i + 1
self.__interpreter.interpret(input('> ')) #self.__interpreter.interpret(input('> '))
self.__sly_cclang_interpreter.interpret(input('> '))
#self.__rply_cclang_interpreter.interpret(input('> '))
i += 1 i += 1
def files(self, file: str) -> None: def files(self, file: str) -> None:
@ -43,7 +46,8 @@ class Main:
for i in range(0, len(f)): for i in range(0, len(f)):
self.__repo.line_number = i + 1 self.__repo.line_number = i + 1
# self.__interpreter.interpret(f[i]) # self.__interpreter.interpret(f[i])
self.__cclang_interpreter.interpret(f[i]) # self.__sly_cclang_interpreter.interpret(f[i])
self.__rply_cclang_interpreter.interpret(f[i])
if __name__ == '__main__': if __name__ == '__main__':