Problem 1. Given the following Grammar G1, where is a start symbol. < stat >→ 𝐢𝐟 (< 𝑏𝑜&#
Posted: Fri May 20, 2022 1:41 pm
Problem 1. Given the following Grammar G1, where is
a start symbol.
< stat >→ 𝐢𝐟 (< 𝑏𝑜𝑜𝑙 >) < stat > 𝐞𝐥𝐬𝐞 < stat
>
| 𝐰𝐡𝐢𝐥𝐞 (< bool >) < stat >
|{< stats >}
| < assign >
< assign >→ 𝐢𝐝 = ;
< stats >→< stat >< stats >
| ε
< exp > → < exp > +< term >
| < term >
< term >→ < term >∗ < factor >
| < Factor >
< Factor >→ 𝐢𝐝
| num
|( < exp > )
|− < factor >
< bool > → < bool > 𝐚𝐧𝐝 < bterm >
| < bterm >
< bterm >→ < bterm > 𝐨𝐫 < bfactor >
| < bfactor >
< bfactor >→ 𝐭𝐫𝐮𝐞
| false
|( < bool > )
|𝐧𝐨𝐭 < bfactor >
Part-1: LL(1) Recursive descent parser:
1) Transform the grammar G1 into LL(1) grammar G2, then compute
First/Follow/Predict sets.
2) Construct the LL(1) top-down predictive parser. (Hint. write one
procedure for each variable.)
3) Write the procedures in one of your favorite programming
languages C++/Java or Python.
4) Parse the following input, using predictive parser
program:
Input The Output
if (not false) a=10; else while ( true ) a=-b; Sample output: input
parsed successfully,
print/ runtime stack
Part-2: LL(1) Parse Table:
1) Compute LL(1) parse table for G2.
2) Parse the following input using the LL(1) parse table;
a start symbol.
< stat >→ 𝐢𝐟 (< 𝑏𝑜𝑜𝑙 >) < stat > 𝐞𝐥𝐬𝐞 < stat
>
| 𝐰𝐡𝐢𝐥𝐞 (< bool >) < stat >
|{< stats >}
| < assign >
< assign >→ 𝐢𝐝 = ;
< stats >→< stat >< stats >
| ε
< exp > → < exp > +< term >
| < term >
< term >→ < term >∗ < factor >
| < Factor >
< Factor >→ 𝐢𝐝
| num
|( < exp > )
|− < factor >
< bool > → < bool > 𝐚𝐧𝐝 < bterm >
| < bterm >
< bterm >→ < bterm > 𝐨𝐫 < bfactor >
| < bfactor >
< bfactor >→ 𝐭𝐫𝐮𝐞
| false
|( < bool > )
|𝐧𝐨𝐭 < bfactor >
Part-1: LL(1) Recursive descent parser:
1) Transform the grammar G1 into LL(1) grammar G2, then compute
First/Follow/Predict sets.
2) Construct the LL(1) top-down predictive parser. (Hint. write one
procedure for each variable.)
3) Write the procedures in one of your favorite programming
languages C++/Java or Python.
4) Parse the following input, using predictive parser
program:
Input The Output
if (not false) a=10; else while ( true ) a=-b; Sample output: input
parsed successfully,
print/ runtime stack
Part-2: LL(1) Parse Table:
1) Compute LL(1) parse table for G2.
2) Parse the following input using the LL(1) parse table;