6.2 IMPLEMENTATION OF THE TRANSLATIONS SPECIFIED BY SYNTAX-DIRECTED DEFINITIONS


6.1 SPECIFICATION OF TRANSLATIONS

The specification of a construct's translation in a programming language involves specifying what the construct is, as well as specifying the translating rules for the construct. Whenever a compiler encounters that construct in a program, it will translate the construct according to the rules of translation. Here, the term "translation" is used in a much broader sense. Translation does not necessarily mean generating either intermediate code or object code. Translation also involves adding information into the symbol table as well as performing construct-specific computations . For example, if a construct is a declarative statement, then its translation adds information about the construct's type attribute into the symbol table. Whereas, if the construct is an expression, then its translation generates the code for evaluating the expression.

When we specify what the construct is, we specify the syntactic structure of the construct; hence, syntactic specification is the part of the specification of the construct's translation. Therefore, if we suitably extend the notation that we use for syntactic specification so that it will allow for both the syntactic structure and the rules of translation that go along with it, then we can use this notation as a framework for the specification of the construct translation.

Translation of a construct involves manipulating the values of various quantities . For example, when translating the declarative statement int a , b , c , the compiler needs to extract the type int and add it to the symbol records of a , b , and c . This requires that the compiler keep track of the type int, as well as the pointers to the symbol records containing a , b , and c .

Since we use a context-free grammar to specify the syntactic structure of a programming language, we extend that context-free grammar by associating sets of attributes with the grammar symbols. These sets hold the values of the quantities, which a compiler is required to track, as well as the associated set of production rules of the grammar that specify the how the attributed values of the grammar symbols of the production are manipulated. These extensions allow us to specify the translations. Syntax-directed definitions and translation schemes are examples of these extensions of context-free grammars, allowing us to specify the translations.

Syntax-directed definitions use CFG to specify the syntactic structure of the construct. It associates a set of attributes with each grammar symbol; and with each production, it associates a set of semantic rules for computing the values of the attributes of the grammar symbols appearing in that production. Therefore, the grammar and the set of semantic rules constitute syntax-directed definitions.




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