[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 CCLang.Parser import Parser
from CCLang_sly.Parser import Parser
from Interpreter.Validator import Validator
from CCLang.Lexer import Lexer
from CCLang_sly.Lexer import Lexer
from Interpreter.Repo import Repo
from Interpreter.Utils import Utils
from Models.AbstractSyntaxTree.AbstractSyntaxTree import AbstractSyntaxTree

View File

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

View File

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

View File

@ -10,12 +10,14 @@ class TokenDefinition(Enum):
Variable = r'var'
Use = r'use'
From = r'from'
As = r'as'
# builtin functions
Output = r'output'
Input = r'input'
Length = r'length'
Range = r'range'
Round = r'round'
Exit = r'exit'
# normal keywords
@ -23,12 +25,12 @@ class TokenDefinition(Enum):
ElseIf = r'elseif'
Else = r'else'
Continue = r'continue'
In = r'in'
Return = r'return'
# loops
While = r'while'
For = r'for'
In = r'in'
# access
Public = r'public'
@ -36,12 +38,12 @@ class TokenDefinition(Enum):
""" Chars """
# format
Left_Brace = r'\{'
Right_Brace = r'\}'
Left_Parenthesis = r'\('
Right_Parenthesis = r'\)'
Left_Bracket = r'\['
Right_Bracket = r'\]'
LeftBrace = r'\{'
RightBrace = r'\}'
LeftParenthesis = r'\('
RightParenthesis = r'\)'
LeftBracket = r'\['
RightBracket = r'\]'
Semicolon = r'\;'
Colon = r'\:'
Comma = r'\,'
@ -55,13 +57,21 @@ class TokenDefinition(Enum):
Caret = r'\^'
""" Values """
ValueString = r'\".*?\"'
ValueNumber = r'\d+'
# bool
BoolTrue = r'true'
BoolFalse = r'false'
Name = r'[a-zA-Z_][a-zA-Z0-9_]*'
String = r'\".*?\"'
Number = r'\d+'
""" Datatypes """
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.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.Repo import Repo
@ -11,4 +12,5 @@ class ServiceInitializer:
self.repo = Repo()
self.utils = Utils(self.repo)
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.__repo = self.__services.repo
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:
"""
@ -22,7 +23,9 @@ class Main:
i = 0
while self.__repo.error is None:
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
def files(self, file: str) -> None:
@ -43,7 +46,8 @@ class Main:
for i in range(0, len(f)):
self.__repo.line_number = i + 1
# 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__':