


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Beyond Syntax, Attribute grammars, Context sensitive analysis, Ad hoc Techniques, Set of rules, Signed binary numbers, Derivation, Attribute version, Decimal value are the points from this lecture. You can find series of lecture notes for compiler construction here.
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Beyond Syntax
These questions are part of context-sensitive analysis. Answers depend on values, not parts of speech. Answers may involve computation.
These questions can be answered by using formal methods such as context-sensitive grammars and attribute grammars or by using ad-hoc techniques.
One of the most popular is the use of attribute grammars.
Attribute Grammars
A CFG is augmented with a set of rules. Each symbol in the derivation has a set of values or attributes. Rules specify how to compute a value for each attribute
Consider the grammar for signed binary numbers (SBN)
Number โ Sign List Sign โ + ๏ฃด โ List โ List Bit | Bit Bit โ 0 ๏ฃด 1
The string โโ1โ can be derived as follows:
Number โ Sign List โ โ List โ โ Bit โ โ 1
Similarly, the derivation for โ-101โ is
Number โ Sign List โ Sign List Bit โ Sign List 1 โ Sign List Bit 1 โ Sign List 0 1 โ Sign Bit 0 1 โ Sign 1 0 1 โ โ 1 0 1
For an attributed version of SBN , the following attributes are needed
Symbol Attributes Number val Sign neg List pos, val Bit pos, val
We will add rules to compute decimal value of a signed binary number
Productions Attribution Rules Number โ Sign List (^) List.pos โ 0 if Sign.neg then Number.val โ โ List.val else Number.val โ List.val Sign โ + (^) Sign.neg โ false Sign โ โ (^) Sign.neg โ true List0 โ List1 Bit (^) List1.pos โ List0.pos + 1 Bit.pos โ List0.pos List0.val โ List1.val + Bit.val List โ Bit (^) Bit.pos โ List.pos List.val โ Bit.val Bit โ (^0) Bit.val โ 0 Bit โ (^1) Bit.val โ 2 Bit.pos
Attributes are associated with nodes in parse tree. Rules are value assignments associated with productions. Rules and parse tree define an attribute dependence graph which must be acyclic.
When the parse tree is peeled away, we get the attribute dependence graph