[DevState] Changed Parsing

This commit is contained in:
Sven Heidemann
2020-09-23 06:48:38 +02:00
parent dfc4b44b25
commit 7058927970
29 changed files with 224 additions and 541 deletions

View File

@@ -1,9 +1,30 @@
from typing import List
from Models.Interpreter.Token import Token
from Models.Interpreter.Datatypes import Datatypes
from Models.Token.Token import Token
from Models.Token.TokenTypes import TokenTypes
from Models.Token.TokenValueTypes import ExpressionCharacters
class AbstractSyntaxTree:
class ValueNode:
def __init__(self, value: Token = 'empty', datatype: Token = Token(TokenTypes.Type, Datatypes.strings.value[Datatypes.Empty.value])):
self.value = value
self.type = datatype
class BinaryOperationNode:
def __init__(self, left: Token, op_token: Token, right: Token):
self.left = left
self.op_token = op_token
self.right = right
self.operation_chars = [
ExpressionCharacters.chars.value[ExpressionCharacters.Plus.value],
ExpressionCharacters.chars.value[ExpressionCharacters.Minus.value],
ExpressionCharacters.chars.value[ExpressionCharacters.Asterisk.value],
ExpressionCharacters.chars.value[ExpressionCharacters.Slash.value],
ExpressionCharacters.chars.value[ExpressionCharacters.Caret.value]
]
def eval(self):
if self.op_token.value not in self.operation_chars:
return eval(f'{self.left.value} {self.op_token.value} {self.right.value}')
def __init__(self):
self.tokens: List[Token] = []

View File

@@ -1,13 +0,0 @@
from typing import List
from Models.AbstractSyntaxTree.Function import Function
from Models.AbstractSyntaxTree.Variable import Variable
class Class:
def __init__(self):
self.name: str = ''
self.variables: List[Variable] = []
self.functions: List[Function] = []
self.is_public = False

View File

@@ -1,14 +0,0 @@
from typing import List
from Models.AbstractSyntaxTree.Variable import Variable
from Models.Interpreter.Types import Types
class Function:
def __init__(self) -> None:
self.name: str = ''
self.variables: List[Variable] = []
self.instructions: [] = []
self.return_type: Types = Types.Any
self.is_public = False

View File

@@ -1,9 +0,0 @@
from Models.AbstractSyntaxTree.AbstractSyntaxTree import AbstractSyntaxTree
from Models.AbstractSyntaxTree.InstructionTypes import InstructionTypes
class Instruction:
def __init__(self):
self.type: InstructionTypes = InstructionTypes.Unknown
self.ast: AbstractSyntaxTree = AbstractSyntaxTree()

View File

@@ -1,10 +0,0 @@
from enum import Enum
class InstructionTypes(Enum):
Unknown = 0
Expression = 1
Bool_Expression = 2
Assignment = 3
Call = 4

View File

@@ -1,11 +0,0 @@
from typing import List
from Models.AbstractSyntaxTree.Class import Class
class Library:
def __init__(self):
self.name: str = ''
self.classes: List[Class] = []
self.is_public = False

View File

@@ -1,9 +0,0 @@
from typing import List
from Models.AbstractSyntaxTree.Library import Library
class RuntimeAbstractSyntaxTree:
def __init__(self):
self.libs: List[Library] = []

View File

@@ -1,12 +0,0 @@
from typing import List
from Models.Interpreter.Token import Token
class Variable:
def __init__(self):
self.name: str = ''
self.type: str = ''
self.value: List[Token] = []
self.is_public = False