Shared Flashcard Set

Details

Comp2010 - Flashcard Set 5 -Attribute Grammars and Attribute
Comp2010 - Flashcard Set 5 - Attribute Grammars and Attribute Evaluation
7
Computer Science
Undergraduate 2
05/27/2013

Additional Computer Science Flashcards

 


 

Cards

Term
What are attributes?
Definition
  • Conceptually, attributes are functions on entire ASTs
    • attr: AST x Node -> AVal
    • Needs restrictions for efficient evaluation
  • In practice, attributes are evaluated by
    • Scanner: attached to tokens (e.g. source locations) - too restrictive
    • Parser: integrated with AST construction - common use
    • Attribute Evaluator: extra AST traversals - Common in later phases(e.g. code generation)
Term
What does attribute evaluation consist of?
Definition
  • An attribute at a node can only be computed form attributes at parents, siblings and children
    • Synthesized attributes are computed from children
    • Inherited attributes are computed from parents and siblings
Term
What are some characteristics of Attribute evalutaion order?
Definition
[image]
Term
How can it be dealt with Attribute evaluation rules?
Definition
  • Attribute evaluation rules can be added to parse rules
  • decl returns [String type, List vars]:
    • t = type ids+=ID (',' ids+=ID)*
    • {$type = $t.text; $vars = $ids};
Term
What is the difference between synthesized and inherited attributes?
Definition

Synthesized attribute for non-terminal A at node N 

  • Defined by evaluation rule associated with production at N
  • Production must have A as its head
  • Defined in terms of N's children and N itself

Inherited attribute for non-terminal B at a node N

  • Defined by evaluation rule associated with production at parent of N
  • Production must have B in its body
  • Defined in terms of N's parents and siblings, and N itself
Term
What are the principles of Attributed Grammars?
Definition
  • We can limit the use Synthesized an  inherited attributes to guarantee that the attribute evaluation is cycle-free:
    • A grammar is S-attributed if every attribute is synthesized
    • A grammar is L-attributed if every attribute is 
      • Synthesized or
      • Inherited, with the restriction that the evaluation rule uses only:
        • Attributes inherited from the parent or
        • Attributes (Synthesized or inherited) form left siblings

 

Term
In attribute evaluation, what is the comparison ov Order Vs. Parsing?
Definition
  • S-attributed grammars are well suited for LR-parsing (bottom-up):
    • When applying a reduce operation, all values are available to calculate the attributes of the parent
  • L-attributed grammars are well-suited for LL-parsing (top-down, left-to-right):
    • When calling a parse rule function, all attribute values are available to calculate the attributes of the non-terminal
  • L-attribute grammars can be used for LR parsing
    • inheritance from above is tricky
Supporting users have an ad free experience!