Chapter 5:Semantic Analysis

General algorithm

. Algorithm : Bottom up parsing and translation with inherited attributes

. Inpu t: L attributed definitions

. Output : A bottom up parser

. Assume every non terminal has one inherited attribute and every grammar symbol has a synthesized attribute

. For every production A X 1 . X n introduce n markers M 1 ..Mn and replace the production by

A M 1 X 1 ... M n X n

M1 . M n ε

. Synthesized attribute Xj ,s goes into the value entry of X j

. Inherited attribute Xj,i goes into the value entry of M j

General Algorithm for bottom-up parsing and translation with inherited attributes Input. An L-attributed definition with an underlying LL(1) grammar. Output: A bottom up parser that computes the values of all attributes on its parsing stack. Method: Assume every nonterminal A has one inherited attribute, A.i and every grammar symbol X has a synthesized attribute, X.s. For every production A -> X1.Xn introduce n markers M1.Mn and replace the production by A -> M1X1.MnXn. The synthesized attribute Xj.s goes into the value entry of Xj and inherited attribute Xj.i goes into the value entry of Mj .