Mercurial > lcfOS
comparison python/c3/parser.py @ 155:b28a11c01dbe
Simplified IR classes
author | Windel Bouwman |
---|---|
date | Sun, 03 Mar 2013 13:20:03 +0100 |
parents | b73bc14a3aa3 |
children | 8f3924b6076e |
comparison
equal
deleted
inserted
replaced
154:81e08e2e7777 | 155:b28a11c01dbe |
---|---|
122 if not self.hasConsumed(')'): | 122 if not self.hasConsumed(')'): |
123 args.append(self.parseExpression()) | 123 args.append(self.parseExpression()) |
124 while self.hasConsumed(','): | 124 while self.hasConsumed(','): |
125 args.append(self.parseExpression()) | 125 args.append(self.parseExpression()) |
126 self.Consume(')') | 126 self.Consume(')') |
127 return ProcedureCall(procedure, args) | 127 return astnodes.ProcedureCall(procedure, args) |
128 | 128 |
129 def parseIfStatement(self): | 129 def parseIfStatement(self): |
130 self.Consume('if') | 130 self.Consume('if') |
131 self.Consume('(') | 131 self.Consume('(') |
132 condition = self.parseExpression() | 132 condition = self.parseExpression() |
152 | 152 |
153 def parseCompoundStatement(self): | 153 def parseCompoundStatement(self): |
154 self.Consume('{') | 154 self.Consume('{') |
155 statements = [self.parseStatement()] | 155 statements = [self.parseStatement()] |
156 while self.hasConsumed(';'): | 156 while self.hasConsumed(';'): |
157 if self.Peak == '}': break # Permit last ';' | |
157 statements.append(self.parseStatement()) | 158 statements.append(self.parseStatement()) |
158 self.Consume('}') | 159 self.Consume('}') |
159 return astnodes.CompoundStatement(statements) | 160 return astnodes.CompoundStatement(statements) |
160 | 161 |
161 def parseStatement(self): | 162 def parseStatement(self): |
164 return self.parseIfStatement() | 165 return self.parseIfStatement() |
165 elif self.Peak == 'while': | 166 elif self.Peak == 'while': |
166 return self.parseWhileStatement() | 167 return self.parseWhileStatement() |
167 elif self.Peak == '{': | 168 elif self.Peak == '{': |
168 return self.parseCompoundStatement() | 169 return self.parseCompoundStatement() |
170 elif self.Peak == ';': | |
171 return astnodes.EmptyStatement() | |
169 elif self.Peak == 'var': | 172 elif self.Peak == 'var': |
170 return self.parseVarDef() | 173 return self.parseVarDef() |
171 elif self.Peak == 'return': | 174 elif self.Peak == 'return': |
172 return self.parseReturnStatement() | 175 return self.parseReturnStatement() |
173 elif self.Peak == 'ID': | 176 elif self.Peak == 'ID': |
189 elif self.Peak == 'NUMBER': | 192 elif self.Peak == 'NUMBER': |
190 val = self.Consume('NUMBER') | 193 val = self.Consume('NUMBER') |
191 return self.sema.actOnNumber(val.val, val.loc) | 194 return self.sema.actOnNumber(val.val, val.loc) |
192 elif self.Peak == 'ID': | 195 elif self.Peak == 'ID': |
193 d = self.parseDesignator() | 196 d = self.parseDesignator() |
194 return self.sema.actOnVariableUse(d) | 197 if self.Peak == '(': |
198 return self.parseProcedureCall(d) | |
199 else: | |
200 return self.sema.actOnVariableUse(d) | |
195 self.Error('Expected NUM, ID or (expr), got {0}'.format(self.Peak)) | 201 self.Error('Expected NUM, ID or (expr), got {0}'.format(self.Peak)) |
196 | 202 |
197 def parseBinopRhs(self, lhs, min_prec): | 203 def parseBinopRhs(self, lhs, min_prec): |
198 while self.PeakPrec >= min_prec: | 204 while self.PeakPrec >= min_prec: |
199 op_prec = self.PeakPrec | 205 op_prec = self.PeakPrec |