diff options
author | Benedikt Böhm <bb@xnull.de> | 2009-05-16 12:33:35 +0200 |
---|---|---|
committer | Benedikt Böhm <bb@xnull.de> | 2009-05-16 12:33:35 +0200 |
commit | 144258f0196b69cbdd2f29bd501276942efc3182 (patch) | |
tree | 7077e686fc85415724a4777443bf081abc9b7de7 | |
parent | ad571051416123ac1b86ce05dbf199b6d084dbc2 (diff) | |
parent | 4960da6d71504d9639da2537ddb6f22b7ae64120 (diff) | |
download | swppy-144258f0196b69cbdd2f29bd501276942efc3182.tar.gz swppy-144258f0196b69cbdd2f29bd501276942efc3182.tar.xz swppy-144258f0196b69cbdd2f29bd501276942efc3182.zip |
Merge branch 'master' of git@git.animux.de:swppy
-rw-r--r-- | Classes.py | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/Classes.py b/Classes.py new file mode 100644 index 0000000..f144e77 --- /dev/null +++ b/Classes.py @@ -0,0 +1,145 @@ +class KlassType: + def __init__(self, name): + self.name = name + + def __str__(self): + return self.name + + def __repr__(self): + return "<KlassType: %s>" % 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 "<OperatorType: %s>" % 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 "<TokenType: %s>" % 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 "<NonTerminalType: %s>" % 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: <FUNCTION, Zwischencode> + def __init__(self,type,code=None): + self.type = type + self.code = code + +class Token: + # bsp: <identifier,0> + 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 ThreeAddressCodeToken: + + +class ThreeAddressCode: + codelist = [] + + # returns code or -1 if end of list + getNextCode(): + return someCode + +############################### |