Mercurial > lcfOS
comparison python/c3/parser.py @ 225:1c7364bd74c7
Fixed pointer deref
author | Windel Bouwman |
---|---|
date | Thu, 11 Jul 2013 07:42:30 +0200 |
parents | c3f1ce8b638f |
children | 240111e0456f |
comparison
equal
deleted
inserted
replaced
224:5af52987f5bd | 225:1c7364bd74c7 |
---|---|
73 self.parseTypeDef() | 73 self.parseTypeDef() |
74 else: | 74 else: |
75 self.Error('Expected function, var, const or type') | 75 self.Error('Expected function, var, const or type') |
76 | 76 |
77 def parseDesignator(self): | 77 def parseDesignator(self): |
78 """ A designator designates an object """ | 78 """ A designator designates an object """ |
79 name = self.Consume('ID') | 79 name = self.Consume('ID') |
80 d = astnodes.Designator(name.val, name.loc) | 80 return astnodes.Designator(name.val, name.loc) |
81 return d | |
82 | 81 |
83 # Type system | 82 # Type system |
84 def parseTypeSpec(self): | 83 def parseTypeSpec(self): |
85 # For now, do simple type spec, just parse an ID: | 84 # For now, do simple type spec, just parse an ID: |
86 #return self.parseDesignator() | 85 #return self.parseDesignator() |
107 | 106 |
108 def parseTypeDef(self): | 107 def parseTypeDef(self): |
109 self.Consume('type') | 108 self.Consume('type') |
110 newtype = self.parseTypeSpec() | 109 newtype = self.parseTypeSpec() |
111 typename = self.Consume('ID') | 110 typename = self.Consume('ID') |
112 # TODO: action here :) | |
113 self.Consume(';') | 111 self.Consume(';') |
114 return astnodes.DefinedType(typename, newtype) | 112 df = astnodes.DefinedType(typename.val, newtype, typename.loc) |
113 self.addDeclaration(df) | |
115 | 114 |
116 # Variable declarations: | 115 # Variable declarations: |
117 def parseVarDef(self): | 116 def parseVarDef(self): |
118 self.Consume('var') | 117 self.Consume('var') |
119 t = self.parseTypeSpec() | 118 t = self.parseTypeSpec() |
317 | 316 |
318 def UnaryExpression(self): | 317 def UnaryExpression(self): |
319 if self.Peak in ['&', '*']: | 318 if self.Peak in ['&', '*']: |
320 op = self.Consume(self.Peak) | 319 op = self.Consume(self.Peak) |
321 ce = self.CastExpression() | 320 ce = self.CastExpression() |
322 return astnodes.Unop(op.typ, ce, op.loc) | 321 if op.val == '*': |
322 return astnodes.Deref(ce, op.loc) | |
323 else: | |
324 return astnodes.Unop(op.typ, ce, op.loc) | |
323 else: | 325 else: |
324 return self.PostFixExpression() | 326 return self.PostFixExpression() |
325 | 327 |
326 def PostFixExpression(self): | 328 def PostFixExpression(self): |
327 pfe = self.PrimaryExpression() | 329 pfe = self.PrimaryExpression() |
335 args.append(self.Expression()) | 337 args.append(self.Expression()) |
336 while self.hasConsumed(','): | 338 while self.hasConsumed(','): |
337 args.append(self.Expression()) | 339 args.append(self.Expression()) |
338 self.Consume(')') | 340 self.Consume(')') |
339 pfe = astnodes.FunctionCall(pfe, args, pfe.loc) | 341 pfe = astnodes.FunctionCall(pfe, args, pfe.loc) |
342 elif self.hasConsumed('->'): | |
343 field = self.Consume('ID') | |
344 pfe = astnodes.Deref(pfe, pfe.loc) | |
345 pfe = astnodes.FieldRef(pfe, field.val, field.loc) | |
346 elif self.hasConsumed('.'): | |
347 field = self.Consume('ID') | |
348 pfe = astnodes.FieldRef(pfe, field.val, field.loc) | |
340 else: | 349 else: |
341 rrrr | 350 raise Exception() |
342 return pfe | 351 return pfe |
343 | 352 |
344 def PrimaryExpression(self): | 353 def PrimaryExpression(self): |
345 if self.hasConsumed('('): | 354 if self.hasConsumed('('): |
346 e = self.Expression() | 355 e = self.Expression() |