comparison 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
comparison
equal deleted inserted replaced
250:f5fba5b554d7 251:6ed3d3a82a63
49 self.token = self.tokens.__next__() 49 self.token = self.tokens.__next__()
50 50
51 def addDeclaration(self, decl): 51 def addDeclaration(self, decl):
52 self.currentPart.declarations.append(decl) 52 self.currentPart.declarations.append(decl)
53 53
54 def parseUses(self): 54 def parseImport(self):
55 # TODO: parse uses 55 self.Consume('import')
56 pass 56 name = self.Consume('ID').val
57 self.mod.imports.append(name)
58 self.Consume(';')
57 59
58 def parsePackage(self): 60 def parsePackage(self):
59 self.Consume('package') 61 self.Consume('package')
60 name = self.Consume('ID') 62 name = self.Consume('ID')
61 self.Consume(';') 63 self.Consume(';')
62 self.mod = astnodes.Package(name.val, name.loc) 64 self.mod = astnodes.Package(name.val, name.loc)
63 self.currentPart = self.mod 65 self.currentPart = self.mod
64 self.parseUses()
65 while self.Peak != 'END': 66 while self.Peak != 'END':
66 self.parseTopLevel() 67 self.parseTopLevel()
67 self.Consume('END') 68 self.Consume('END')
68 69
69 def parseTopLevel(self): 70 def parseTopLevel(self):
70 if self.Peak == 'function': 71 if self.Peak == 'function':
71 self.parseFunctionDef() 72 self.parseFunctionDef()
72 elif self.Peak == 'var': 73 elif self.Peak == 'var':
73 self.parseVarDef() 74 self.parseVarDef()
74 elif self.Peak == 'const': 75 elif self.Peak == 'const':
75 self.parseConstDef() 76 self.parseConstDef()
76 elif self.Peak == 'type': 77 elif self.Peak == 'type':
77 self.parseTypeDef() 78 self.parseTypeDef()
78 else: 79 elif self.Peak == 'import':
79 self.Error('Expected function, var, const or type') 80 self.parseImport()
81 else:
82 self.Error('Expected function, var, const or type')
80 83
81 def parseDesignator(self): 84 def parseDesignator(self):
82 """ A designator designates an object """ 85 """ A designator designates an object """
83 name = self.Consume('ID') 86 name = self.Consume('ID')
84 return astnodes.Designator(name.val, name.loc) 87 return astnodes.Designator(name.val, name.loc)