> One way to handle something like this is to modify the grammar slightly.
> Instead of having a rule like this:
>
> def p_whatever_statement(p):
> "statement : whatever SEMI"
> pass
>
> You split it into two rules:
>
> def p_whatever_statement(p):
> "statement : whatever_part SEMI"
> pass
>
> def p_whatever_part(p):
> "whatever_part : whatever"
> # Do whatever (modify symbol tables, etc.)
>
> This will force the code in the second rule (whatever_part) to run before the
> semicolon at the end gets reduced along with the rule. There's more
> information in section 5.11 of
> the PLY documentation (Embedded Actions).
>
Thanks a lot, David - problem solved !
I used to have this rule:
def p_declaration(self, p):
""" declaration : declaration_specifiers
init_declarator_list_opt SEMI
"""
Where I would add the new type to the symbol table.
I split it to:
def p_decl_body(self, p):
""" decl_body : declaration_specifiers
init_declarator_list_opt
"""
<<<handle declaration here>>>
def p_declaration(self, p):
""" declaration : decl_body SEMI
"""
p[0] = p[1]
And now it works, because decl_body is always reduced prior to
shifting in the token after SEMI.
I just hope there are no hidden gotchas in it. No new conflicts were
created, at least.
Eli
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---