Context Free Grammar
Definition
| Component | Definition | Notation |
|---|---|---|
| Terminal | aka. Token | , , , … |
| Non-Terminal | A non-literal structure | , , , … |
| Sentence | A valid sequence of terminals | |
| Sentential Form | A 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 + Tis left-associativeE -> T + Eis right-associative
- See the dangling else problem