comparison python/c3/parser.py @ 165:598d3888a11c

Added front class and fided AST view
author Windel Bouwman
date Fri, 22 Mar 2013 15:12:38 +0100
parents e023d3ce1d63
children da0087b82fbe
comparison
equal deleted inserted replaced
164:e023d3ce1d63 165:598d3888a11c
124 body = self.parseCompoundStatement() 124 body = self.parseCompoundStatement()
125 self.sema.actOnFuncDef2(parameters, returntype, body) 125 self.sema.actOnFuncDef2(parameters, returntype, body)
126 126
127 # Statements: 127 # Statements:
128 def parseAssignment(self, lval): 128 def parseAssignment(self, lval):
129 lval = self.sema.actOnVariableUse(lval) 129 lval = self.sema.actOnVariableUse(lval, lval.loc)
130 loc = self.Consume('=').loc 130 loc = self.Consume('=').loc
131 rval = self.parseExpression() 131 rval = self.parseExpression()
132 self.Consume(';') 132 self.Consume(';')
133 return self.sema.actOnAssignment(lval, rval, loc) 133 return self.sema.actOnAssignment(lval, rval, loc)
134 134
141 args.append(self.parseExpression()) 141 args.append(self.parseExpression())
142 self.Consume(')') 142 self.Consume(')')
143 return astnodes.ProcedureCall(procedure, args) 143 return astnodes.ProcedureCall(procedure, args)
144 144
145 def parseIfStatement(self): 145 def parseIfStatement(self):
146 self.Consume('if') 146 loc = self.Consume('if').loc
147 self.Consume('(') 147 self.Consume('(')
148 condition = self.parseExpression() 148 condition = self.parseExpression()
149 self.Consume(')') 149 self.Consume(')')
150 yes = self.parseCompoundStatement() 150 yes = self.parseCompoundStatement()
151 if self.hasConsumed('else'): 151 if self.hasConsumed('else'):
152 no = self.parseCompoundStatement() 152 no = self.parseCompoundStatement()
153 return astnodes.IfStatement(condition, yes, no) 153 else:
154 return astnodes.IfStatement(condition, yes, astnodes.EmptyStatement()) 154 no = astnodes.EmptyStatement()
155 return self.sema.actOnIfStatement(condition, yes, no, loc)
155 156
156 def parseWhileStatement(self): 157 def parseWhileStatement(self):
157 self.Consume('while') 158 self.Consume('while')
158 self.Consume('(') 159 self.Consume('(')
159 condition = self.parseExpression() 160 condition = self.parseExpression()
214 elif self.Peak == 'ID': 215 elif self.Peak == 'ID':
215 d = self.parseDesignator() 216 d = self.parseDesignator()
216 if self.Peak == '(': 217 if self.Peak == '(':
217 return self.parseProcedureCall(d) 218 return self.parseProcedureCall(d)
218 else: 219 else:
219 return self.sema.actOnVariableUse(d) 220 return self.sema.actOnVariableUse(d, d.loc)
220 self.Error('Expected NUM, ID or (expr), got {0}'.format(self.Peak)) 221 self.Error('Expected NUM, ID or (expr), got {0}'.format(self.Peak))
221 222
222 def parseBinopRhs(self, lhs, min_prec): 223 def parseBinopRhs(self, lhs, min_prec):
223 while self.PeakPrec >= min_prec: 224 while self.PeakPrec >= min_prec:
224 op_prec = self.PeakPrec 225 op_prec = self.PeakPrec