Java Reference
In-Depth Information
(a) Construct First and Follow sets for eachnonterminal in the grammar.
(b) Construct the Predict sets for the grammar.
(c) Construct a recursive-descent parser based on the grammar.
(d) Add code into the parser to compute sums andproducts as indicated
by the grammar.
Note that a sum always involves exactly two Values, while
a product is formed over 0 or more Values.
(e) Build an LL(1) parse table based on the grammar.
3. Construct the LL(1) parse table for the following grammar:
1 Expr
→−
Expr
2
|
(Expr)
3
|
Var ExprTai l
4 ExprTail
→−
Expr
5
| λ
6 Var
id VarTail
7 VarTai l
(Expr)
8
| λ
4. Trace the operation of an LL(1)parserforthegrammarofExercise3on
the following input:
id
−−
id((id))
5. Transform the following grammar into LL(1) form using the techniques
presented in Section 5.5:
1 DeclList
DeclList ; Decl
2
|
Decl
3 Decl
IdList : Type
4 IdList
IdList , id
5
|
id
6 Ty pe
ScalarType
7
|
array ( ScalarTypeList ) of Type
8 ScalarType
id
9
|
Bound . . Bound
10 Bound
Sign intconstant
11
|
id
12 Sign
→ +
13
|−
14
| λ
15 ScalarTypelist
ScalarTypeList , ScalarType
16
|
ScalarType
Search WWH ::




Custom Search