Eliminate left recursion from the following grammar:
P in Program
K in Block
D in Declaration
C in Command
E in Arithmetic Expression
B in Boolean Expresion
I in Identifier
N in Number
P ::= K.
K ::= begin D; C end
D ::= D ; D | const I = N | var I
C ::= C ; C | I := E | if B then C else C | while B do
C | K
B ::= true | false | E = E | not B
E ::= E + E | I | N
I ::= x | y | z | u | v
N ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Program the resulting grammar as a Definite Clause
Grammar.
Your grammar should produce parse trees for the input
programs.
An example input program:
begin
const x = 8;
var y;
var z;
z := 0;
if x = y + 2 then
z := 5 else z := 3;
while not x = z
do
z := z + 2
end.