6.4 SYNTAX-DIRECTED TRANSLATION SCHEMES


6.3 L-ATTRIBUTED DEFINITIONS

A syntax-directed definition is L -attributed if each inherited attribute of X j for i between 1 and n , and on the right side of production A X 1 X 2 , X n , depends only on:

  1. The attributes (both inherited as well as synthesized ) of the symbols X 1 , X 2 , , X j ˆ’ 1 (i.e., the symbols to the left of X j in the production, and

  2. The inherited attributes of A .

The syntax-directed definition above is an example of the L -attributed definition, because the inherited attribute L .type depends on T .type, and T is to the left of L in the production D TL . Similarly, the inherited attribute L 1 .type depends on the inherited attribute L .type, and L is parent of L 1 in the production L L 1 ,id.

When translations carried out during parsing, the order in which the semantic rules are evaluated by the parser must be explicitly specified. Hence, instead of using the syntax-directed definitions, we use syntax-directed translation schemes to specify the translations. Syntax-directed definitions are more abstract specifications for translations; therefore, they hide many implementation details, freeing the user from having to explicitly specify the order in which translation takes place. Whereas the syntax-directed translation schemes indicate the order in which semantic rules are evaluated, allowing some implementation details to be specified.




Algorithms for Compiler Design
Algorithms for Compiler Design (Electrical and Computer Engineering Series)
ISBN: 1584501006
EAN: 2147483647
Year: 2005
Pages: 108
Authors: O G Kakde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net