From 49df60f32aca6428706bc895b7e48ab2d68444b5 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 12 Jul 2021 12:32:15 +0400 Subject: Added ability to set variables. --- consts.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'consts.py') diff --git a/consts.py b/consts.py index 86a8eef..0a595c2 100644 --- a/consts.py +++ b/consts.py @@ -4,18 +4,43 @@ class State: class TokenType: ( - LEFT_PARENTHESIS, RIGHT_PARENTHESIS, NUMBER, OPERATOR, SEMICOLON, COMMA, SYMBOL, *_ + LEFT_PARENTHESIS, RIGHT_PARENTHESIS, + LEFT_BRACE, RIGHT_BRACE, + NUMBER, OPERATOR, SYMBOL, KEYWORD, UNARY, + SEMICOLON, COMMA, EQUALS, *_ ) = range(100) -UNARY = "unary" -FUNCALL = "funcall" +class NodeType: + ( + NUMBER, OPERATOR, SYMBOL, FUNCALL, UNARY, ASSIGNMENT, *_ + ) = range(100) + + +class Keyword: + LET, STRUCT, FN, RETURN, IF, ELSE, FOR, WHILE, CONTINUE, BREAK, *_ = range(100) + + +keywords = { + "let": Keyword.LET, "struct": Keyword.STRUCT, + "fn": Keyword.FN, "return": Keyword.RETURN, + "if": Keyword.IF, "else": Keyword.ELSE, + "for": Keyword.FOR, "while": Keyword.WHILE, "continue": Keyword.CONTINUE, "break": Keyword.BREAK, +} + +keywords_repr = {keywords[i]: i for i in keywords} + +types = [ + "i8", "i16", "i32", "i64", + "f32", "f64", +] + PRECEDENCE = { "+": 10, "-": 10, "*": 20, "^": 30, - UNARY: 40, + NodeType.UNARY: 40, } OPERATOR_CHARS = "*+-/%&~^|#$.:<=>@" -- cgit v1.2.3