Problem 1
Transform the following grammar to Chomsky Normal Form:
Please give the detailed steps of the algorithm.
Solution
Elimination of non-productive non-terminals:
There are none.
Elimination of unreachable non-terminals:
There are none.
Making non-terminals non-nullable:
- We create production: and
- We eliminate all on the right side of rules, removing
- Because S is nullable, we introduce a new initial symbol S' and add rule
- We obtain the following new grammar:
Eliminating single productions:
Making non-terminals alone on the right hand side:
Eliminating non-binary productions:
Problem 2
Consider the following grammar:
E ::= E+E E ::= E*E E ::= E=E E ::= Num | true | false
Where Num represents integers.
Run Earley's parsing algorithm on the following input: 1=2*3=true
How many parse trees do you obtain?
Write down those parse trees that are correct according to the following types:
+ : Int x Int→Int
* : Int x Int→Int
= : Bool x Bool → Bool
= : Int x Int → Bool
Solution
We got 5 parse trees:
According to types, only one is valid: