Question

please provide good explanation.

Consider the following grammar for variable and class declarations in Java:

      <Decl>      -> <VarDecl>
                   | <ClassDecl>
      <VarDecl>   -> <Modifiers> <Type> <VarDec> SEM
      <ClassDecl> -> <Modifiers> CLASS ID LBRACE <DeclList> RBRACE
      <DeclList>  -> <Decl>
                   | <DeclList> <Decl>
      <VarDec>    -> ID
                   | ID ASSIGN <Exp>
                   | <VarDec> COMMA ID
                   | <VarDec> COMMA ID ASSIGN <Exp>

Indicate any problems in this grammar that prevent it from being parsed by a recursive-descent parser with one token lookahead. You can simply circle the offending parts of the grammar above.

Transform the rules for <Decl> and <DeclList> so they can be parsed by a recursive-descent parser with one token lookahead (you don’t need to transform the rules for <VarDec>). I.e., remove any left-recursion and left-factor the grammar. Make as few changes to the grammar as possible, but do not use Extended BNF. The nonterminals <Decl> and <DeclList> of the modified grammar should describe the same language as the original nonterminals.

3. (25 pts) Consider the following grammar for variable and class declarations in Java: <Decl> -<VarDecl> <VarDec1〉 -> <Modifiers> <Type> <VarDee> SEM <ClassDecl> -> <Modifiers» CLASS ID LBRACE <DeclList> RBRACE <VarDec> ->ID ID ASSIGN <Exp> | <VarDec> COMMA ID ASSIGN <Exp> Indicate any problems in this grammar that prevent it from being parsed by a recursive-descent parser with one token lookahead. You can simply circle the offending parts of the grammar above. Transform the rules for <Decl> and <DeclList> so they can be parsed by a recursive-descent parser with one token lookahead (you dont need to transform the rules for <VarDec>). Le., remove any left-recursion and left-factor the grammar. Make as few changes to the grammar as possible, but do not use Extended BNF. The nonterminals <Decl> and <Decllist> of the modified grammar should describe the same language as the original nonterminals.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
please provide good explanation. Consider the following grammar for variable and class declarations in Java: <Decl>...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following grammar for variable and class declarations in Java: <Decl> -> <VarDecl> | <ClassDecl>...

    Consider the following grammar for variable and class declarations in Java: <Decl> -> <VarDecl> | <ClassDecl> <VarDecl> -> <Modifiers> <Type> <VarDec> SEM <ClassDecl> -> <Modifiers> CLASS ID LBRACE <DeclList> RBRACE <DeclList> -> <Decl> | <DeclList> <Decl> <VarDec> -> ID | ID ASSIGN <Exp> | <VarDec> COMMA ID | <VarDec> COMMA ID ASSIGN <Exp> Indicate any problems in this grammar that prevent it from being parsed by a recursive-descent parser with one token lookahead. Transform this grammar into a form that...

  • Write a parser program for cSub using the method of recursive descent. The main program here...

    Write a parser program for cSub using the method of recursive descent. The main program here will effectively be the main program of the compiler as a whole. The input to the program will be a Csub source file, specified on the command line. The program will construct a parse tree for the program, with one interior node for every nonterminal in the derivation of the program, and one leaf node for each of the id, num, and real tokens...

  • 1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming...

    1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming languages according to Sebesta? a. Increased capacity to express ideas. b. Improved background for choosing appropriate languages. c. Increased ability to design new languages. d. Increased ability to learn new languages. 2. (p. 5-6.) What programming language has dominated scientific computing over the past 50 years? a. FORTRAN b. ALGOL c. SNOBOL d. PL/I 3. (p. 6.) What programming language has dominated artificial intelligence...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT