CS314 Fall 2014 Assignment 2 Due Wednesday, September 24, 11:59pm Submission: PDF File Through Sakai - Rutgers.edu
CS314 Fall 2014 Assignment 2 Due Wednesday, September 24, 11:59pm Submission: PDF File Through Sakai - Rutgers.edu
Assignment 2
Due Wednesday, September 24, 11:59pm
Submission: pdf file through sakai.rutgers.edu
1
Are the following languages context-free or not? If yes, specify a context-free grammar in
BNF notation that generates the language. If not, give an informal argument.
1. { an bm co | m > n 0, o > 0} , with alphabet = {a, b, c}
2. { an b2n | n 0 }, with alphabet = {a, b}
3. { ww R | w and w R is w in reverse }, with alphabet ={a, b}
4. { an bm cm dn | n 0, m 0 }, with alphabet = {a, b, c, d}
5. { w | w has more than 4 symbols}, with alphabet ={a, b}
A language that is a subset of the language of propositional logic may be defined as follows:
<start> ::= <expr>
<expr> :: = <expr> <expr> |
<expr> <expr> |
<expr> <expr> |
<const> | <var>
<const> :: = true | false
<var> :: = a | b | c | . . . | z
1. Give a leftmost and a rightmost derivation for the sentence
a true b false .
2. Give the corresponding parse trees for the derivations.
3. Give the corresponding abstract syntax tree (AST).
4. Show that the above grammar is ambiguous.
5. Give an unambiguous grammar for the same language that enforces the following precedence and associativity:
has highest precedence (binds strongest), followed by , and then
and are right associative, and is left associative
6. Give the parse tree and AST for your new, unambiguous grammar for the sentence
a false b true true .