[DevState] Changed Parsing
This commit is contained in:
@@ -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] = []
|
||||
|
@@ -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
|
@@ -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
|
@@ -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()
|
@@ -1,10 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class InstructionTypes(Enum):
|
||||
|
||||
Unknown = 0
|
||||
Expression = 1
|
||||
Bool_Expression = 2
|
||||
Assignment = 3
|
||||
Call = 4
|
@@ -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
|
@@ -1,9 +0,0 @@
|
||||
from typing import List
|
||||
|
||||
from Models.AbstractSyntaxTree.Library import Library
|
||||
|
||||
|
||||
class RuntimeAbstractSyntaxTree:
|
||||
|
||||
def __init__(self):
|
||||
self.libs: List[Library] = []
|
@@ -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
|
@@ -1,4 +0,0 @@
|
||||
class Booleans:
|
||||
|
||||
Right = 'true'
|
||||
Wrong = 'false'
|
22
src/Models/Interpreter/Datatypes.py
Normal file
22
src/Models/Interpreter/Datatypes.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Datatypes(Enum):
|
||||
|
||||
Empty = 0
|
||||
Any = 1
|
||||
Number = 2
|
||||
String = 3
|
||||
Bool = 4
|
||||
List = 5
|
||||
Dict = 6
|
||||
|
||||
strings = [
|
||||
'empty',
|
||||
'any',
|
||||
'number',
|
||||
'string',
|
||||
'bool',
|
||||
'list',
|
||||
'dict'
|
||||
]
|
@@ -1,7 +1,7 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ErrorCode(Enum):
|
||||
class ErrorCodes(Enum):
|
||||
StartFailed = 'Start failed'
|
||||
FileNotFound = 'File not found'
|
||||
|
||||
@@ -21,7 +21,7 @@ class ErrorCode(Enum):
|
||||
|
||||
class Error:
|
||||
|
||||
def __init__(self, code: ErrorCode, msg: str = ''):
|
||||
def __init__(self, code: ErrorCodes, msg: str = '') -> None:
|
||||
self.code = code
|
||||
|
||||
self.msg = code.value.format(msg)
|
||||
|
@@ -1,19 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ExpressionCharacters(Enum):
|
||||
Plus = 0
|
||||
Minus = 1
|
||||
Asterisk = 2
|
||||
Slash = 3
|
||||
Equal = 4
|
||||
Caret = 5
|
||||
|
||||
chars = [
|
||||
'+',
|
||||
'-',
|
||||
'*',
|
||||
'/',
|
||||
'=',
|
||||
'^'
|
||||
]
|
@@ -1,27 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class FormatCharacters(Enum):
|
||||
Left_Brace = 0
|
||||
Right_Brace = 1
|
||||
Left_Parenthesis = 2
|
||||
Right_Parenthesis = 3
|
||||
Left_Bracket = 4
|
||||
Right_Bracket = 5
|
||||
Semicolon = 6
|
||||
Colon = 7
|
||||
Comma = 8
|
||||
Point = 9
|
||||
|
||||
chars = [
|
||||
'{',
|
||||
'}',
|
||||
'(',
|
||||
')',
|
||||
'[',
|
||||
']',
|
||||
';',
|
||||
':',
|
||||
',',
|
||||
'.'
|
||||
]
|
@@ -1,30 +0,0 @@
|
||||
class Keywords:
|
||||
# define keywords
|
||||
Library: str = 'lib'
|
||||
Class: str = 'class'
|
||||
Function: str = 'func'
|
||||
Variable: str = 'var'
|
||||
Use: str = 'use'
|
||||
From: str = 'from'
|
||||
|
||||
# builtin functions
|
||||
Output: str = 'output'
|
||||
Input: str = 'input'
|
||||
Length: str = 'length'
|
||||
Range: str = 'range'
|
||||
Exit: str = 'exit'
|
||||
|
||||
# normal keywords
|
||||
If: str = 'if'
|
||||
ElseIf: str = 'elseif'
|
||||
Else: str = 'else'
|
||||
Pass: str = 'pass'
|
||||
In: str = 'in'
|
||||
Return: str = 'return'
|
||||
|
||||
# loops
|
||||
While: str = 'while'
|
||||
For: str = 'for'
|
||||
|
||||
# access
|
||||
Public: str = 'public'
|
@@ -1,24 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Types(Enum):
|
||||
|
||||
Any = 0
|
||||
Number = 1
|
||||
String = 2
|
||||
Bool = 3
|
||||
List = 4
|
||||
Dict = 5
|
||||
Empty = 6
|
||||
Void = 7
|
||||
|
||||
strings = [
|
||||
'any',
|
||||
'number',
|
||||
'string',
|
||||
'bool',
|
||||
'list',
|
||||
'dict',
|
||||
'empty',
|
||||
'void'
|
||||
]
|
@@ -1,11 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class UnresolvedTokenTypes(Enum):
|
||||
Empty = 0
|
||||
Word = 1
|
||||
Number = 2
|
||||
String = 3
|
||||
Expression_Character = 4
|
||||
Bool_Expression_Character = 5
|
||||
Format_Character = 6
|
@@ -1,8 +1,8 @@
|
||||
from Models.Interpreter import TokenTypes
|
||||
from Models.Token import TokenTypes
|
||||
|
||||
|
||||
class Token:
|
||||
|
||||
def __init__(self, token_type: TokenTypes, value: str) -> None:
|
||||
self.type: TokenTypes = token_type
|
||||
self.value = value
|
||||
self.value: str = value
|
@@ -12,3 +12,13 @@ class TokenTypes(Enum):
|
||||
Expression_Character = 7
|
||||
Bool_Expression_Character = 8
|
||||
Format_Character = 9
|
||||
|
||||
|
||||
class UnresolvedTokenTypes(Enum):
|
||||
Empty = 0
|
||||
Word = 1
|
||||
Number = 2
|
||||
String = 3
|
||||
Expression_Character = 4
|
||||
Bool_Expression_Character = 5
|
||||
Format_Character = 6
|
82
src/Models/Token/TokenValueTypes.py
Normal file
82
src/Models/Token/TokenValueTypes.py
Normal file
@@ -0,0 +1,82 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Keywords:
|
||||
# define keywords
|
||||
Library: str = 'lib'
|
||||
Class: str = 'class'
|
||||
Function: str = 'func'
|
||||
Variable: str = 'var'
|
||||
Use: str = 'use'
|
||||
From: str = 'from'
|
||||
|
||||
# builtin functions
|
||||
Output: str = 'output'
|
||||
Input: str = 'input'
|
||||
Length: str = 'length'
|
||||
Range: str = 'range'
|
||||
Exit: str = 'exit'
|
||||
|
||||
# normal keywords
|
||||
If: str = 'if'
|
||||
ElseIf: str = 'elseif'
|
||||
Else: str = 'else'
|
||||
Continue: str = 'continue'
|
||||
In: str = 'in'
|
||||
Return: str = 'return'
|
||||
|
||||
# loops
|
||||
While: str = 'while'
|
||||
For: str = 'for'
|
||||
|
||||
# access
|
||||
Public: str = 'public'
|
||||
|
||||
|
||||
class Booleans:
|
||||
Right = 'true'
|
||||
Wrong = 'false'
|
||||
|
||||
|
||||
class ExpressionCharacters(Enum):
|
||||
Plus = 0
|
||||
Minus = 1
|
||||
Asterisk = 2
|
||||
Slash = 3
|
||||
Equal = 4
|
||||
Caret = 5
|
||||
|
||||
chars = [
|
||||
'+',
|
||||
'-',
|
||||
'*',
|
||||
'/',
|
||||
'=',
|
||||
'^'
|
||||
]
|
||||
|
||||
|
||||
class FormatCharacters(Enum):
|
||||
Left_Brace = 0
|
||||
Right_Brace = 1
|
||||
Left_Parenthesis = 2
|
||||
Right_Parenthesis = 3
|
||||
Left_Bracket = 4
|
||||
Right_Bracket = 5
|
||||
Semicolon = 6
|
||||
Colon = 7
|
||||
Comma = 8
|
||||
Point = 9
|
||||
|
||||
chars = [
|
||||
'{',
|
||||
'}',
|
||||
'(',
|
||||
')',
|
||||
'[',
|
||||
']',
|
||||
';',
|
||||
':',
|
||||
',',
|
||||
'.'
|
||||
]
|
0
src/Models/Token/__init__.py
Normal file
0
src/Models/Token/__init__.py
Normal file
Reference in New Issue
Block a user