Mercurial > lcfOS
diff python/c3/semantics.py @ 149:74241ca312cc
Fixes on parser and semantics
author | Windel Bouwman |
---|---|
date | Fri, 01 Mar 2013 11:43:52 +0100 |
parents | e5263f74b287 |
children | 4ae0e02599de |
line wrap: on
line diff
--- a/python/c3/semantics.py Fri Mar 01 10:24:01 2013 +0100 +++ b/python/c3/semantics.py Fri Mar 01 11:43:52 2013 +0100 @@ -5,6 +5,8 @@ def __init__(self, parent=None): self.symbols = {} self.parent = parent + def __iter__(self): + return iter(self.symbols.values()) def getType(self, name): t = self.getSymbol(name) print(t) @@ -39,11 +41,28 @@ self.mod.loc = loc self.mod.scope = self.curScope = Scope() createBuiltins(self.curScope) - def handleBinop(self, lhs, op, rhs): - pass - def actOnLocal(self, t, name, ival): - s = astnodes.Variable(name, t, False) + def actOnBinop(self, lhs, op, rhs, loc): + bo = astnodes.Binop(lhs, op, rhs) + bo.loc = loc + return bo + def actOnNumber(self, num, loc): + n = astnodes.Constant(num) + n.loc = loc + return n + def actOnVarDef(self, name, loc, t, ival): + s = astnodes.Variable(name, t) + s.loc = loc self.curScope.addSymbol(s) + def actOnFuncDef1(self, name, loc): + self.curFunc = astnodes.Procedure(name) + self.curFunc.loc = loc + self.curScope.addSymbol(self.curFunc) + self.curScope = self.curFunc.scope = Scope(self.curScope) + def actOnFuncDef2(self, parameters, returntype, body): + self.curFunc.body = body + self.curFunc.typ = astnodes.FunctionType(parameters, returntype) + self.curFunc = None + self.curScope = self.curScope.parent def actOnType(self, tok): # Try to lookup type, in case of failure return void pass