Mercurial > lcfOS
diff python/c3/parser.py @ 163:8104fc8b5e90
Added visitor to c3
author | Windel Bouwman |
---|---|
date | Mon, 18 Mar 2013 20:13:57 +0100 |
parents | 9683a4cd848f |
children | e023d3ce1d63 |
line wrap: on
line diff
--- a/python/c3/parser.py Sun Mar 10 11:36:55 2013 +0100 +++ b/python/c3/parser.py Mon Mar 18 20:13:57 2013 +0100 @@ -61,6 +61,8 @@ self.parseFunctionDefinition() elif self.Peak == 'var': self.parseVarDef() + elif self.Peak == 'const': + self.parseConstDef() else: self.Error('Expected function or variable') @@ -89,6 +91,19 @@ parseVar() self.Consume(';') + def parseConstDef(self): + self.Consume('const') + t = self.parseType() + def parseConst(): + name = self.Consume('ID') + self.Consume('=') + val = self.parseExpression() + self.sema.actOnConstDef(name.val, name.loc, t, val) + parseConst() + while self.hasConsumed(','): + parseConst() + self.Consume(';') + # Procedures def parseFunctionDefinition(self): self.Consume('function') @@ -193,6 +208,9 @@ elif self.Peak == 'NUMBER': val = self.Consume('NUMBER') return self.sema.actOnNumber(val.val, val.loc) + elif self.Peak == 'REAL': + val = self.Consume('REAL') + return self.sema.actOnNumber(val.val, val.loc) elif self.Peak == 'ID': d = self.parseDesignator() if self.Peak == '(':