Mercurial > lcfOS
diff python/c3/parser.py @ 251:6ed3d3a82a63
Added another c3 example. First import attempt
author | Windel Bouwman |
---|---|
date | Mon, 29 Jul 2013 20:23:13 +0200 |
parents | e621e3ba78d2 |
children | bd26dc13f270 |
line wrap: on
line diff
--- a/python/c3/parser.py Sun Jul 28 19:07:51 2013 +0200 +++ b/python/c3/parser.py Mon Jul 29 20:23:13 2013 +0200 @@ -51,9 +51,11 @@ def addDeclaration(self, decl): self.currentPart.declarations.append(decl) - def parseUses(self): - # TODO: parse uses - pass + def parseImport(self): + self.Consume('import') + name = self.Consume('ID').val + self.mod.imports.append(name) + self.Consume(';') def parsePackage(self): self.Consume('package') @@ -61,22 +63,23 @@ self.Consume(';') self.mod = astnodes.Package(name.val, name.loc) self.currentPart = self.mod - self.parseUses() while self.Peak != 'END': self.parseTopLevel() self.Consume('END') def parseTopLevel(self): - if self.Peak == 'function': - self.parseFunctionDef() - elif self.Peak == 'var': - self.parseVarDef() - elif self.Peak == 'const': - self.parseConstDef() - elif self.Peak == 'type': - self.parseTypeDef() - else: - self.Error('Expected function, var, const or type') + if self.Peak == 'function': + self.parseFunctionDef() + elif self.Peak == 'var': + self.parseVarDef() + elif self.Peak == 'const': + self.parseConstDef() + elif self.Peak == 'type': + self.parseTypeDef() + elif self.Peak == 'import': + self.parseImport() + else: + self.Error('Expected function, var, const or type') def parseDesignator(self): """ A designator designates an object """