Section: Pushdown Automata
Closure Properties
Context-Free Languages are closed under:
- Union
- Concat
- Star
- Regular Intersection (←think: you have states & one stack to combine. It makes sense)
Pumping Lemma
thm. Pumping Lemma for CFL.
v,y
. Divide it up into different cases and derive contradictions in all of them.
Transforming Context-Free Languages for Easy Parsing
You can do the following modifications on CFLs:
- Add Lambda
- Remove -productions. ← Every CFG with productions can be made into one w/o -productions.
- Substitution from and into
- Removing Left-Recursion [e.g. ] ← Left-recursion is bad, because top-down parsers will get into an infinite loop
Use the above modifications to produce CFLs that do not have useless productions.
alg. Removing useless productions in CFLs. These steps must go in order!
- Identify useless variables Useless variables are ones that: 1. cannot be reached by the start symbol 2. cannot derive a terminal
- Remove useless productions i.e. remove all productions that contain a useless variable
- Remove all -rules
- create a set of variables that can ultimately derive a
- for every production that uses those variables on the RHS, derive the now.
- Remove unit productions
- draw the variable dependency graph (1 level)
- For every production that uses unit production on the RHS, consolidate all into one; i.e. derive it now.
Normal Forms
-
def. Chompsky Normal Form Either: one terminal, or two variables. Easy to convert any grammar into CNF.
-
def. Geribach Normal Form All rules are the form:
- All -free CFGs can be expressed in GNF.