I have uploaded the homework in word file.
assignment_2.doc

Unformatted Attachment Preview

1 Using the grammar Ginteger• develop a leftmost derivation for the integer 4520. How many
.steps are required for this derivation? In general, how many steps are required to derive an
integer with an arbitrary number, say d, of Digits’?
2 Using the grammar Gimeger, develop a rightmost derivation for the integer 4520.
3 Develop a leftmost derivation for the Jdenl{fier value a2i, using the BNF syntax given in
Figure 2.7.
4 Develop a rightmost derivation for the Jdent{fier value a2i, using the BNF syntax given in
Figure 2.7.
5 Using the grammar of Figure 2.7, draw parse trees for each of the following:
(a) x x + a 1;
(b) a b * c I d;
(c) i i + j * k – 3;
P1·ogran~ —–+ int main ( ) { Declarations Statenwnts }
Declarations —–+ { Declaration }
Declaration–> Type Identifier [ [ Integer] ] { , Ident’ifier [ [ Integer] ] }
Type –> int I bool I float I char
Statements –> { Statement }
Staternent –> ; I Block I Assigmnent I IfStatement I WhileStatement
Block –> {Statements}
Assignrnent –> Identifier’ [ [ EJ:pression ] ] = E:r;pression ;
If Statement –> if ( Exwession ) Statement [ else
Statement

Purchase answer to see full
attachment