Question

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 can be parsed with a recursive-descent parser with one token lookahead. Make as few changes to the grammar as possible. Do not use EBNF.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The problem here is that return is done from right to left here.

the following is the recursive descent parser grammar expression

<E> --> <T> <E*>

<E*> --> + <T> <E*> | - <T> <E*> | epsilon

<T> --> <F> <T*>

<T*> --> * <F> <T*> | / <F> <T*> | epsilon

<F> --> ( <E> ) | number

Add a comment
Know the answer?
Add Answer to:
Consider the following grammar for variable and class declarations in Java: <Decl> -> <VarDecl> | <ClassDecl>...
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
  • please provide good explanation. Consider the following grammar for variable and class declarations in Java: <Decl>...

    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...

  • Consider the following BNF grammar that we saw in class:        EXP    ::= EXP + TERM  ...

    Consider the following BNF grammar that we saw in class:        EXP    ::= EXP + TERM   | EXP - TERM    | TERM        TERM   ::= TERM * FACTOR | TERM / FACTOR | FACTOR        FACTOR ::= ( EXP ) | DIGIT        DIGIT ::= 0 | 1 | 2 | 3    (a) Translate into EBNF.    (b) Draw syntax diagrams.    (c) What are the two requirements on a grammar for a predictive parser to be able to...

  • NEED THIS SOON. Recursive Descent Parsing Consider the following BNF grammar: A -> I = E...

    NEED THIS SOON. Recursive Descent Parsing Consider the following BNF grammar: A -> I = E E -> P O P | P O -> + | - | * | / | ** P -> I | L | UI | UL | (E) U -> + | - | ! I -> C | CI C -> a | b | ... | y | z L -> D | DL D -> 0 | 1 | ......

  • 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...

  • Input hello, I need help completing my assignment for java,Use the following test data for input...

    Input hello, I need help completing my assignment for java,Use the following test data for input and fill in missing code, and please screenshot output. 1, John Adam, 3, 93, 91, 100, Letter 2, Raymond Woo, 3, 65, 68, 63, Letter 3, Rick Smith, 3, 50, 58, 53, Letter 4, Ray Bartlett, 3, 62, 64, 69, Letter 5, Mary Russell, 3, 93, 90, 98, Letter 6, Andy Wong, 3, 89,88,84, Letter 7, Jay Russell, 3, 71,73,78, Letter 8, Jimmie Wong,...

  • 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