diff options
-rw-r--r-- | src/front/__init__.py | 7 | ||||
-rw-r--r-- | src/front/inter/__init__.py | 0 | ||||
-rw-r--r-- | src/front/lexer.py | 62 | ||||
-rw-r--r-- | src/front/lexer/__init__.py | 0 | ||||
-rw-r--r-- | src/front/parser.py | 96 | ||||
-rw-r--r-- | src/front/parser/__init__.py | 0 | ||||
-rw-r--r-- | src/front/symbols.py | 9 | ||||
-rw-r--r-- | src/front/symbols/__init__.py | 0 |
8 files changed, 174 insertions, 0 deletions
diff --git a/src/front/__init__.py b/src/front/__init__.py index e69de29..63529ef 100644 --- a/src/front/__init__.py +++ b/src/front/__init__.py @@ -0,0 +1,7 @@ +from front.lexer import Lexer +from front.parser import Parser + +def main(): + lex = Lexer() + parse = Parser(lex) + parse.program() diff --git a/src/front/inter/__init__.py b/src/front/inter/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/src/front/inter/__init__.py +++ /dev/null diff --git a/src/front/lexer.py b/src/front/lexer.py new file mode 100644 index 0000000..aca7473 --- /dev/null +++ b/src/front/lexer.py @@ -0,0 +1,62 @@ +class Lexer: + line = 1 + + def __init__(self): + return + + def reserve(self, word): + return + + def scan(): + return + +class Tag: + # lexer tokens + NUMBER = 1 + TRUE = 2 + FALSE = 3 + IDENT = 4 + WHILE = 5 + IF = 6 + ELSE = 7 + END = 8 + LBRAK = 9 + RBRAK = 10 + LPAREN = 11 + RPAREN = 12 + NEWLINE = 13 + COMMA = 14 + FUN = 15 + ASSIGNMENT = 16 + RETURN = 17 + OPERATOR = 18 + + # parser tokens + BOOL = 19 + JOIN = 20 + EQUALITY = 21 + RELATION = 22 + EXPRESSION = 23 + TERM = 24 + UNARY = 25 + FACTOR = 26 + IDENT_LIST = 27 + EXPRESSION_LIST = 28 + PROGRAM = 29 + FUNCTION = 30 + STATEMENT = 31 + STATEMENTS = 32 + IF_STATEMENT = 33 + WHILE_STATEMENT = 34 + RETURN_STATEMENT = 35 + ASSIGN_STATEMENT = 36 + FUNCTION_CALL = 37 + +class Token: + tag = None + + def __init__(self, tag): + return + + def __str__(self): + return diff --git a/src/front/lexer/__init__.py b/src/front/lexer/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/src/front/lexer/__init__.py +++ /dev/null diff --git a/src/front/parser.py b/src/front/parser.py new file mode 100644 index 0000000..950a77c --- /dev/null +++ b/src/front/parser.py @@ -0,0 +1,96 @@ +class Parser: + lexer = None + + def __init__(self, lexer): + return + + def parse(self): + return self.program() + + def move(self): + return + + def error(self, msg): + return + + def match(tag): + return + + # bool = bool "||" join | join. + def bool(self): + return + + # join = join "&&" equality | equality. + def join(self): + return + + # equality = equality "==" relation | equality "!=" relation | relation. + def equality(self): + return + + # relation = expression "<" expression | expression "<=" expression | expression ">=" expression | expression ">" expression | expression. + def relation(self): + return + + # expression = expression "+" term | expression "-" term | term. + def expression(self): + return + + # term = term "*" unary | term "/" unary | unary. + def term(self): + return + + # unary = "!" unary | "-" unary | factor. + def unary(self): + return + + # factor = "(" bool ")" | ident | integer | "true" | "false". + def factor(self): + return + + # ident_list = ident { "," ident }. + def ident_list(self): + return + + # expression_list = expression { "," expression }. + def expression_list(self): + return + + # program = function { function }. + def program(self): + return + + # function = "fun" ident "[" [ ident_list ] "]" statements "end". + def function(self): + return + + # statements = statement { nl statement }. + def statements(self): + return + + # statement = [ if_statement | while_statement | assignment | function_call | return_statement ]. + def statement(self): + return + + # if_statement = "if" expression statements [ "else" statements ] "end". + def if_statement(self): + return + + # while_statement = "while" expression statements "end". + def while_statement(self): + return + + # assignment = ident "=" expression. + def assignment(self): + return + + # function_call = ident "[" [ expression_list ] "]". + def function_call(self): + return + + # return_statement = "@" expression. + def return_statement(self): + return + +class ParseTree: + diff --git a/src/front/parser/__init__.py b/src/front/parser/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/src/front/parser/__init__.py +++ /dev/null diff --git a/src/front/symbols.py b/src/front/symbols.py new file mode 100644 index 0000000..f4ab40e --- /dev/null +++ b/src/front/symbols.py @@ -0,0 +1,9 @@ +class SymbolTable: + def __init__(self): + return + + def put(token, id): + return + + def get(token): + return diff --git a/src/front/symbols/__init__.py b/src/front/symbols/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/src/front/symbols/__init__.py +++ /dev/null |