Attribute Grammar

Formal definition

Context Free Grammar:

Formal definition

  • V: vocabulary:
    • N: set of non-terminal symbols
    • T: set of terminal symbols
  • P: set of grammar production rules
  • S: the starting symbol
Link to original

Extended by:

  • : set of attributes
    • : set of inherited attributes
      • : set of inherited attributes for
    • : set of synthesized attributes
      • : set of synthesized attributes for
  • : semantic rules bound to and
    • has to be defined
      • → for every inherited attribute
    • and
      • → for every synthesized attribute
    • parameters:
      • evaluates the attribute of the production rule at the position

Norms

  • normal form: an attribute only appears on one side
  • well-formed: an attribute grammar AG contains no cycle for every possible derivation tree

Example definition

  1. Nonterminals & Terminals
  2. Attributes
  3. Rules
    • ,

Example min amount of f

  • 2p: A → XA
  • AG G:
    • = {i1}
    • = {i2}
    • = {s1}
    • = {s2}

LL-attributed grammar

  • S-attributed grammar = L attributed grammar with only synthesized attributes