I have a rule in my grammar such as
A -> B C D E {: ...some actions... :}
;
D -> /*empty*/ {: some actions using attributes of B and C :}
;
To implement the actions associated with production rule of D, I need to access the parser stack. How can I do that in CUP?
Rewrite your grammar:
A -> A1 E
A1 -> B C D
If the action for the first production requires B
and C
as well, then the semantic value of A1
will have to be more complicated in order to pass the semantic values through.