5.3 Action Symbols

The action terms specify the semantic rules by which value of LHS of a grammar rule is computed in terms of the values on the RHS. The augmented grammar simultaneously specifies two aspects – syntax and semantics – bare grammar rules specify the syntax and the action symbols specify the semantic rules.

For example, for the partial grammar for expr, the action symbols for generating RPN as the Intermediate code can be shown as below:

E : T { + <pop> T <out>}
T : F { * <pop> F <out>} 
F : a <pop> <out> |( E )

with a proviso that Terminals ‘+’, ‘*’ and ‘a’ push themselves. Compare this against the example code given in Section 5.2. Note that the nature of interpretation and position of the action symbols depend upon the output ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.