Improved parsing
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
from Models.AbstractSyntaxTree.RuntimeAbstractSyntaxTree import RuntimeAbstractSyntaxTree
|
||||
from Models.Interpreter.Booleans import Booleans
|
||||
from Models.Interpreter.FormatCharacters import FormatCharacters
|
||||
from Models.Interpreter.Keywords import Keywords
|
||||
from Models.Interpreter.Types import Types
|
||||
|
||||
|
||||
class Repo:
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -5,56 +12,58 @@ class Repo:
|
||||
|
||||
# interpreter
|
||||
self.keywords = [
|
||||
# define keys
|
||||
'lib',
|
||||
'class',
|
||||
'func',
|
||||
'var',
|
||||
'use',
|
||||
'from',
|
||||
# define keywords
|
||||
Keywords.Library,
|
||||
Keywords.Class,
|
||||
Keywords.Function,
|
||||
Keywords.Variable,
|
||||
Keywords.Use,
|
||||
Keywords.From,
|
||||
# builtin functions
|
||||
'output',
|
||||
'input',
|
||||
'length',
|
||||
'range',
|
||||
'exit',
|
||||
Keywords.Output,
|
||||
Keywords.Input,
|
||||
Keywords.Length,
|
||||
Keywords.Range,
|
||||
Keywords.Exit,
|
||||
# normal keywords
|
||||
'if',
|
||||
'elseif',
|
||||
'else',
|
||||
'pass',
|
||||
'in',
|
||||
Keywords.If,
|
||||
Keywords.ElseIf,
|
||||
Keywords.Else,
|
||||
Keywords.Pass,
|
||||
Keywords.If,
|
||||
Keywords.Return,
|
||||
# loops
|
||||
'while',
|
||||
'for',
|
||||
Keywords.While,
|
||||
Keywords.For,
|
||||
# access
|
||||
'public'
|
||||
Keywords.Public
|
||||
]
|
||||
self.types = [
|
||||
'any',
|
||||
'number',
|
||||
'string',
|
||||
'bool',
|
||||
'list',
|
||||
'dict',
|
||||
'emptyType',
|
||||
'void'
|
||||
Types.strings.value[Types.Any.value],
|
||||
Types.strings.value[Types.Number.value],
|
||||
Types.strings.value[Types.String.value],
|
||||
Types.strings.value[Types.Bool.value],
|
||||
Types.strings.value[Types.List.value],
|
||||
Types.strings.value[Types.Dict.value],
|
||||
Types.strings.value[Types.Empty.value],
|
||||
Types.strings.value[Types.Void.value]
|
||||
]
|
||||
self.format_chars = [
|
||||
FormatCharacters.chars.value[FormatCharacters.Left_Brace.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Right_Brace.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Left_Parenthesis.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Right_Parenthesis.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Left_Bracket.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Right_Bracket.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Semicolon.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Colon.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Comma.value],
|
||||
FormatCharacters.chars.value[FormatCharacters.Point.value]
|
||||
]
|
||||
self.format_chars = ['{', '}', '(', ')', ';', ':', ',', '.']
|
||||
self.expr_chars = ['+', '-', '*', '/', '=', '^']
|
||||
self.bool_expr_chars = ['<', '>', '!', '!=', '==', '>=', '<=', '&&', '||']
|
||||
self.bool_values = ['true', 'false']
|
||||
self.bool_values = [Booleans.Right, Booleans.Wrong]
|
||||
|
||||
# runtime
|
||||
self.error = None
|
||||
self.ast = []
|
||||
|
||||
def output_tokens(self, toks: list) -> None:
|
||||
if self.debug and len(toks) > 0:
|
||||
outp_toks = []
|
||||
for tok in toks:
|
||||
outp_toks.append({tok.value: tok.type})
|
||||
# print({tok.value: tok.type})
|
||||
|
||||
print(outp_toks)
|
||||
# print('\n')
|
||||
self.is_error = None
|
||||
self.AST: RuntimeAbstractSyntaxTree = RuntimeAbstractSyntaxTree()
|
||||
|
Reference in New Issue
Block a user