AttributeGrammars - Attribute Grammars Prabhaker Mateti...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style CS784 Attribute Grammars Prabhaker Mateti ACK: Assembled from many sources
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784 About Attribute Grammars Attribute grammars (AGs) have additions to underlying context-free grammars (CFGs) to carry some semantic info on parse tree nodes Primary value of AGs: Used for semantic checking and other compile-time analyses, e.g., type checking in a compiler Used for translation, e.g., parse tree to assembly code 22
Background image of page 2
CS784 Examples Two Examples First Syntactic representation of a number and its sematics Type checking as partial semantics 33
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784 Example-1 Productions N ::= 0 Semantics of N. val := 0 44
Background image of page 4
CS784 Example-2: Type Checking E ::= n E ::= x E ::= E1  +  E2  E ::= E1  *  E2  E. type = int E. type = real if E1. type = E2. type then E .type = E1 .type 55
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784 Attribute Grammars: Definition An attribute grammar is a context- free grammar G = (S, N, T, P) with the following additions: For each grammar symbol X there is a set A(X) of attribute values Each rule has a set of functions that define certain attributes of the symbols in the rule Each rule has a (possibly empty) set of predicates/ conditions to check for 66
Background image of page 6
CS784 Attribute Grammars: Definition Let X0 ::= X1 . .. Xn be a production of G. Synthesized attributes S(X0) = f(I(X0), A(X1), . .. , A(Xn)) depends on the values of attributes of children. inherited attribute of X0 ( X.y or y(<X>) means y is an attribute of 77
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784 Synthesized vs. Inherited Attributes Each terminal and non-terminal X: two disjoint sets Syn(X) and Inh(X) Attr(X) = Syn(X) ∪ Inh(X) X ::= Y1 Y2 … Yn Each attribute in Syn(X) is defined from Attr(X) ∪ Attr(Y1) ∪… ∪ Attr(Yn) Each attribute in Inh(Yk) is defined from Attr(X) ∪ Attr(Y1) ∪… ∪ Attr(Yn) 88
Background image of page 8
CS784 Attribute Value Computation If all attributes were inherited, the tree could be decorated in top-down order. If all attributes were synthesized, the
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/02/2011 for the course CS 784 taught by Professor Tkprasad during the Spring '11 term at New York Institute of Technology-Westbury.

Page1 / 33

AttributeGrammars - Attribute Grammars Prabhaker Mateti...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online