Grammar Set of variables Set of terminal symbols Start variable Set of Production rules
Example Grammar :
Definition: Context-Free Grammars Grammar Productions of the form: String of variables and terminals VariablesTerminal symbols Start variable Variable
Leftmost derivation: Rightmost derivation:
Derivation Tree
yield Derivation Tree
Simplifications of Context-Free Grammars
Example
Normal Forms for Context-free Grammars
Chomsky Normal Form Each productions has form: variable or terminal
Introduce variables for terminals:
Introduce intermediate variable:
Final grammar in Chomsky Normal Form: Initial grammar
Then, for every symbol : In productions: replace with Add production New variable:
Replace any production with New intermediate variables:
Greinbach Normal Form All productions have form: symbolvariables
Pushdown Automata PDAs
Pushdown Automaton -- PDA Input String Stack States
The States Input symbol Pop symbol Push symbol
top input stack Replace
Push top input stack
Pop top input stack
No Change top input stack
Pop top input stack Empty Stack empty The automaton HALTS No possible transition after
Pop top input stack A Possible Transition
Non-Determinism PDAs are non-deterministic Allowed non-deterministic transitions
Formalities for PDAs
Transition function:
Formal Definition Pushdown Automaton (PDA) States Input alphabet Stack alphabet Transition function Final states Stack start symbol Initial state
Instantaneous Description Current state Remaining input Current stack contents
A computation:
Deterministic PDAs - DPDAs
Deterministic PDA: DPDA Allowed transitions: (deterministic choices)
Allowed transitions: (deterministic choices)
Not allowed: (non deterministic choices)
PDAs Have More Power than DPDAs
Positive Properties of Context-Free languages
Context-free languages are closed under: Union is context free is context-free Union
Context-free languages are closed under: Concatenation is context free is context-free Concatenation
Context-free languages are closed under: Star-operation is context freeis context-free Star Operation
Negative Properties of Context-Free Languages
Context-free languages are not closed under: intersection is context free not necessarily context-free Intersection
Context-free languages are not closed under: complement is context freenot necessarily context-free Complement
Intersection of Context-free languages and Regular Languages
The intersection of a context-free language and a regular language is a context-free language context free regular context-free
An Application of Regular Closure Prove that: is context-free
Decidable Properties of Context-Free Languages
Membership Question: for context-free grammar find if string Membership Algorithms: Parsers Exhaustive search parser CYK parsing algorithm
Empty Language Question: for context-free grammar find if Algorithm: 1.Remove useless variables 2.Check if start variable is useless
Infinite Language Question: for context-free grammar find if is infinite Algorithm: 1. Remove useless variables 3. Create dependency graph for variables 4. If there is a loop in the dependency graph then the language is infinite 2. Remove unit and productions