comparison python/c3/parser.py @ 158:9683a4cd848f

Added some functions for code generation
author Windel Bouwman
date Fri, 08 Mar 2013 16:52:44 +0100
parents 8f3924b6076e
children 8104fc8b5e90
comparison
equal deleted inserted replaced
157:8f3924b6076e 158:9683a4cd848f
109 body = self.parseCompoundStatement() 109 body = self.parseCompoundStatement()
110 self.sema.actOnFuncDef2(parameters, returntype, body) 110 self.sema.actOnFuncDef2(parameters, returntype, body)
111 111
112 # Statements: 112 # Statements:
113 def parseAssignment(self, lval): 113 def parseAssignment(self, lval):
114 lval = astnodes.VariableUse(lval) 114 lval = self.sema.actOnVariableUse(lval)
115 self.Consume('=') 115 self.Consume('=')
116 rval = self.parseExpression() 116 rval = self.parseExpression()
117 self.Consume(';') 117 self.Consume(';')
118 return astnodes.Assignment(lval, rval) 118 return astnodes.Assignment(lval, rval)
119 119
134 self.Consume(')') 134 self.Consume(')')
135 yes = self.parseCompoundStatement() 135 yes = self.parseCompoundStatement()
136 if self.hasConsumed('else'): 136 if self.hasConsumed('else'):
137 no = self.parseCompoundStatement() 137 no = self.parseCompoundStatement()
138 return astnodes.IfStatement(condition, yes, no) 138 return astnodes.IfStatement(condition, yes, no)
139 return astnodes.IfStatement(condition, yes) 139 return astnodes.IfStatement(condition, yes, astnodes.EmptyStatement())
140 140
141 def parseWhileStatement(self): 141 def parseWhileStatement(self):
142 self.Consume('while') 142 self.Consume('while')
143 self.Consume('(') 143 self.Consume('(')
144 condition = self.parseExpression() 144 condition = self.parseExpression()
165 return self.parseIfStatement() 165 return self.parseIfStatement()
166 elif self.Peak == 'while': 166 elif self.Peak == 'while':
167 return self.parseWhileStatement() 167 return self.parseWhileStatement()
168 elif self.Peak == '{': 168 elif self.Peak == '{':
169 return self.parseCompoundStatement() 169 return self.parseCompoundStatement()
170 elif self.Peak == ';': 170 elif self.hasConsumed(';'):
171 self.Consume(';')
172 return astnodes.EmptyStatement() 171 return astnodes.EmptyStatement()
173 elif self.Peak == 'var': 172 elif self.Peak == 'var':
174 return self.parseVarDef() 173 self.parseVarDef()
174 return astnodes.EmptyStatement()
175 elif self.Peak == 'return': 175 elif self.Peak == 'return':
176 return self.parseReturnStatement() 176 return self.parseReturnStatement()
177 elif self.Peak == 'ID': 177 elif self.Peak == 'ID':
178 designator = self.parseDesignator() 178 designator = self.parseDesignator()
179 if self.Peak == '(': 179 if self.Peak == '(':