Context Free Grammar

Definition

ComponentDefinitionNotation
Terminalaka. Token, , , …
Non-TerminalA non-literal structure, , , …
SentenceA valid sequence of terminals
Sentential FormA valid sequence of (non-)terminals, , ;
  • Each grammar describes/generates/produces a language.
  • Rule () versus derivation ()
  • Top-down versus bottom-up derivation

Ambiguity

Ambiguity comes from symmetry! Eliminate ambiguity by breaking

symmetry.

  • Ambiguity = more than one way to parse a sentence
  • In binary operator:
    • E -> E + T is left-associative
    • E -> T + E is right-associative
  • See the dangling else problem

Categories