$24
This homework will be due beginning of class Monday Feb. 1st at the beginning of class. It should be handwritten, you can turn it in or you can upload by scanning in your documents and putting it in the Dropbox on D2L…….before class the Dropbox will shutdown at 9am September
23rd and there will be no late assignments accepted.
Answer the following four questions:
1. Write EBNF descriptions for the following:
a. Java switch statement
b. Python while statement, just the definition line
2. Rewrite the following BNF to give + precedence over * associative.
and force
+
to be right
An Unambiguous Grammar for Expressions
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> + <term>
| <term>
<term> → <term> *
| <factor>
<factor>
<factor> → ( <expr> )
| <id>
3. Using the grammar given below show a parse tree and a leftmost derivation for the following statement:
B=C*(A*C+B)
A Grammar for Simple Assignment Statements
<assign> → <id> = <expr>
<id> → A| B | C
<expr> → <id>
+
<expr>
| <id> * <expr>
| ( <expr> )
|
<id>
4. Prove that the following grammar is ambiguous:
<S> → <A>
<A> → <A> + <A> |
<id> → a | b | c
<id>