From 6d2b0eeb5018013fb8ba6e8c2e31d637cc04f72c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=BC=C3=9Flein?= Date: Fri, 15 May 2009 20:42:19 +0200 Subject: added Classes.py --- Classes.py | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 Classes.py diff --git a/Classes.py b/Classes.py new file mode 100644 index 0000000..c969395 --- /dev/null +++ b/Classes.py @@ -0,0 +1,141 @@ +class KlassType: + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + + def __repr__(self): + return "" % self + +KlassType.CONST = KlassType("const") +KlassType.VAR = KlassType("var") +KlassType.FUNCNAME = KlassTupe("function name") + +class OperatorType: + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + + def __repr__(self): + return "" % self + +OperatorType.EQ = OperatorType("==") +OperatorType.NE = OperatorType("!=") +OperatorType.GE = OperatorType(">=") +OperatorType.LE = OperatorType("<=") +OperatorType.GT = OperatorType(">") +OperatorType.LT = OperatorType("<") +OperatorType.ADD = OperatorType("+") +OperatorType.SUB = OperatorType("-") +OperatorType.MUL = OperatorType("*") +OperatorType.DIV = OperatorType("/") +OperatorType.MOD = OperatorType("%") +OperatorType.AND = OperatorType("&&") +OperatorType.OR = OperatorType("||") + +class TokenType: + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + + def __repr__(self): + return "" % self + +TokenType.FUN = TokenType("fun") +TokenType.IDENT = TokenType("identifier") +TokenType.LBRAK = TokenType("[") +TokenType.RBRAK = TokenType("]") +TokenType.LPAREN = TokenType("(") +TokenType.RPAREN = TokenType(")") +TokenType.NEWLINE = TokenType("newline") +TokenType.IF = TokenType("if") +TokenType.TAB = TokenType("tab") +TokenType.OPERATOR = TokenType("operator") +TokenType.NUMBER = TokenType("number") +TokenType.RETURN = TokenType("return") +TokenType.END = TokenType("end") + +class NonTerminalType: + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + + def __repr__(self): + return "" % self + +NonTerminalType.FACTOR = NonTerminalType("factor") +NonTerminalType.TERM = NonTerminalType("term") +NonTerminalType.SIMPLE_EXPRESSION = NonTerminalType("simple_expression") +NonTerminalType.EXPRESSION = NonTerminalType("expression") +NonTerminalType.IDENT_LIST = NonTerminalType("ident_list") +NonTerminalType.EXPRESSION_LIST = NonTerminalType("expression_list") +NonTerminalType.PROGRAM = NonTerminalType("program") +NonTerminalType.FUNCTION = NonTerminalType("function") +NonTerminalType.STATEMENT = NonTerminalType("statement") +NonTerminalType.STATEMENTS = NonTerminalType("statements") +NonTerminalType.IF_STATEMENT = NonTerminalType("if_statement") +NonTerminalType.WHILE_STATEMENT = NonTerminalType("while_statement") +NonTerminalType.RETURN_STATEMENT = NonTerminalType("return_statement") +NonTerminalType.ASSIGNMENT = NonTerminalType("assignment") +NonTerminalType.FUNCTION_CALL = NonTerminalType("function_call") + +class NonTerminal: + # bsp: + def __init__(self,type,code=None): + self.type = type + self.code = code + +class Token: + # bsp: + def __init__(self,type,value=None): + self.type = type + self.value = value + +class Tokenlist: + tokenlist = [] + + def __init__(self,source): + self.source = source + + def getNextToken(self): + #... irgendwann.. + return tokenlist.next() + + def getValue(self,key) + # ... blublub + return somevalue + +class Symbol: + name = None + value = None + type = None # int, string,.. + klass = None # const, var, functionName + + def __init__(self, name): + self.name = name + +class ParseTree: + def __init__(self, root): + self.root = root + +class ParseTreeNode: + children = [] + value = None # Token oder NonTerminal + + def __init__(self, value): + self.value = value + + +############################### + +class Lexer: + +class Parser: + -- cgit v1.2.3