Chapter 5:Semantic Analysis

Top down Translation

Use predictive parsing to implement L-attributed definitions

E E 1 + T E.val := E 1 .val + T.val
E E 1 - T E.val := E 1 .val - T.val
E T E.val := T.val
T (E) T.val := E.val
T num T.val := num.lexval

We now come to implementation. We decide how we use parse tree and L-attribute definitions to construct the parse tree with a one-to-one correspondence. We first look at the top-down translation scheme. The first major problem is left recursion. If we remove left recursion by our standard mechanism, we introduce new symbols, and new symbols will not work with the existing actions. Also, we have to do the parsing in a single pass.