Example Grammar

Grammars and Languages


Parts of a Grammar


Alternative Representation for Grammars

Defining a Language

Parse Trees

Simple Languages

Sentences with Arbitrary Length

A Recursive Grammar

Notation for Representing Languages

Showing that a Grammar Generates a Language

More Recursive Grammars

  1. Example: S --> abS| ab
  2. Example: S --> aSb | ab
  3. Example: S --> AB A --> aA | a B --> bB | b

One More Language

Context Sensitive Grammar

Context Free Grammar

Order of Substitution

Leftmost and Rightmost Derivations

Ambiguous Grammars

A Grammar for Expressions

Issues with Simple Expression Grammar

Abstract and Concrete Parse Trees

Expressions and Tree Depth

Expression Precedence

Precedence Grammar

Expression Associativity

Expressions with Parentheses

Grammar for Identifiers and Integers

<integer> -->  <digit><integer> | <digit>
<digit> -->  0 | 1 | 2 | 3 ... | 9

<ident> -->  <letter>|<letter><letterOrDigitSeq>

<letterOrDigitSeq> -->  <letterOrDigit>|<letterOrDigit><letterOrDigitSeq>

<letterOrDigit> -->  <letter> | <digit>

<letter> -->  a | b | c ...

Partial Grammar for Programs

Another Program Grammar

Ambiguous If - Other Solutions

EBNF: Extended BNF

Expression Grammar in EBNF

EBNF Grammar for If Statements

Issues with EBNF Grammar