![Page 1: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/1.jpg)
CS 3240: Languages and Computation
Context-Free Languages
![Page 2: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/2.jpg)
Context-Free Languages
A single step derivation “” consist of the substitution of a variable by a string according to a substitution rule in R
Note that rules use single arrows “”, while derivations themselves use double arrows “”
A sequence of several derivations (or none) is indicated by “ * ” Previous example: “S * aabbaa”
L is a Context Free Language if and only if there is a context free grammar G=(V, Σ, P, S) such that
L = L(G) = { w | w Σ * and S * w }
![Page 3: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/3.jpg)
The language generated by a grammar
![Page 4: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/4.jpg)
Some Remarks
The language L(G) = { w | w Σ* and S * w } contains only strings of terminals, not variables.
Notation: We can agglomerate several rules for one variable:A B
A 01 by A B | 01 | AAA AA
What is the CFG ({S},{(,)},P, S) that produces the language of correct parentheses like (), (()), or ()(())? Answer: S→ (S) | SS |
![Page 5: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/5.jpg)
Parse trees
![Page 6: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/6.jpg)
Yield of a parse tree
![Page 7: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/7.jpg)
![Page 8: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/8.jpg)
From tree to derivation
![Page 9: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/9.jpg)
![Page 10: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/10.jpg)
From derivations to recursive inference
![Page 11: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/11.jpg)
ambiguity
![Page 12: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/12.jpg)
Removing ambiguity
![Page 13: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/13.jpg)
Ambiguity and leftmost derivations
![Page 14: CS 3240: Languages and Computation Context-Free Languages](https://reader036.vdocument.in/reader036/viewer/2022082217/56649ed45503460f94be4e35/html5/thumbnails/14.jpg)
Inherent ambiguity