Question

If someone can help me with the recursive descent parsing, it woule be very helpful. This...

If someone can help me with the recursive descent parsing, it woule be very helpful.

This problem should be completed with only c without using lex or yacc.

Problem — LL(1) Grammars and Recursive Descent Parsing

The Grammar::

<program> ::=      program <block> .

<block> ::=            begin <stmtlist> end

<stmtlist> ::=        <stmt> <morestmts>

<morestmts> ::= ; <stmtlist

<stmt> ::=             <assign> | <ifstmt> | <whilestmt> | <block>

<assign> ::=          <variable> = <expr>

<ifstmt> ::=           if <testexpr> then <stmt> else <stmt>

<whilestmt> ::=    while <testexpr> do <stmt>

<testexpr> ::=       <variable> <= <expr>

<expr> ::=             + <expr> <expr> | ∗ <expr> <expr> | <variable> | <digit>

<variable> :: =      a | b | c

<digit> :: =            0 | 1 | 2

Write a recursive descent parser for the above grammar.

Modify your recursive descent parser so that it prints the number of assignment statements in the input program after it successfully parsed the program, and the number of variable references. For the program listed below, your parser should print ”4 assignments, 13 variable references”. Note that a statement such as “a = + a a” has three references, not just one.

program

begin

if b <= 0 then

while a <= 1 do

begin

a = + a b;

c = + a 1

end

else

begin

a = * a b

end;

c = + a b

end.

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

procedure <assign>() <variable> if (lookahead-) match (- expr else error O procedure <ifstmt>) if (<testexpr> ( ) ) ; thenprocedure くtestexpr>() <variable> (); if (lookahead = <- ) match (<-) <expr〉 () ; else error (); procedure <expr> () if (procedure <variable match (-) match.(a) match (bc) if (lookahead- a) else error.) procedure <digit> if (lookahead-- matcelse error ( procedure match (token t) if (lookahead=t) lookahead - next token; else error ) procedure error print (ERROR

Add a comment
Know the answer?
Add Answer to:
If someone can help me with the recursive descent parsing, it woule be very helpful. This...
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
  • 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...

  • Please write a recursive descent parser (including a lexical analyzer) for the following EBNF in C....

    Please write a recursive descent parser (including a lexical analyzer) for the following EBNF in C. Your program codes should be runnable. <exprs> -> <expr>; {<expr>;} <expr> -> <term> { (+ | -) <term> } <term> -> <factor> { (*|/ ) <factor> } <factor> -> <exp> {^ <exp>} <exp> -> id | int_lit | real_lit | (<expr>) where, ^ indicates the power operation, id is a legal identifier name, int_lit represents any positive integer number, and real_lit represents any positive...

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

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

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

  • Please help me with the coding for LL(1)!! The given grammar was: P → PL |...

    Please help me with the coding for LL(1)!! The given grammar was: P → PL | L L → N; | M; | C N → print E M → print "W" W → TW | ε C → if E {P} | if E {P} else {P} E → (EOE) | V (note: this has a variable O) O → + | - | * V → 0 | 1 | 2 | 3 (note: this has a terminal...

  • Check if i did the conversion correct or else please send me the correct Context Free...

    Check if i did the conversion correct or else please send me the correct Context Free Gramer Ambigious CFG : S -> PROGRAM identifier SEMI Block Block -> Declarations BlockStatements Declarations -> VAR (VariableDeclarions SEMI)+ | eps VariableDeclarions -> identifier (COMMA identifier)* COLON TypeSpec TypeSpec -> INTEGER | REAL BlockStatements -> BEGIN Statements END Statements -> Statement | Statement Statements Statement -> Assignment | eps Assignment -> identifier ASSIGN Expr SEMI Expr -> Term (ADD Term)* | Term (SUB Term)*...

  • Hello, can someone help me solve the remove function since when I try to remove it...

    Hello, can someone help me solve the remove function since when I try to remove it doesn't work, please and thank you. #include <iostream> #include <cstdlib> #include <string> using namespace std; class node { public:    typedef int data_t;    node *next;    data_t data;    node(data_t d) { next = NULL; data = d; } }; class linked_list { private:    node *head; public:    linked_list()    {        head = NULL;    }    // Get the...

  • can someone please double check my code here are the requirements please help me fulfill the...

    can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...

  • C++ Can someone please help me with this problem- commenting each line of code so I...

    C++ Can someone please help me with this problem- commenting each line of code so I can understand how to solve this problem using the C++ programming language? I really need help understanding how to create a file for the program to read. Do I create the file in Visual basic or create a text file? I have the code, just need to know how to create the file for it to read. #include<fstream> #include<iostream> using namespace std; int main()...

  • Can someone help me with part b of this question? Class Management I Help Chapter 19...

    Can someone help me with part b of this question? Class Management I Help Chapter 19 Begin Date: 8/20/2018 12:00:00 AM-Due Date: 1/25/2019 11:5900 PM End Date: 5/52019 11:59:00 PM (13%) Problem 7: A uniform electric field of magnitude E 22 NC points along the x- axis. A circular loop of radius R 29 cm is centered at the origin with the normal to the loop pointing θ = 15 degrees above the x-axis. Otheexpertta.com q) 50% Part (a) Calculate...

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
ADVERTISEMENT