Question

Consider the following grammar expr- term term_tail term_tail -add_op term term_tail | term - factor factor_tail...

Consider the following grammar

expr- term term_tail

term_tail -add_op term term_tail |

term - factor factor_tail

factor_tail-mult_op factor factor _tail |

factor -(expr) |id|literal

add_op -+|-

mult_op-*|/

Draw syntax tree for parsing each of cdf+(a25+84),(a25+84)*cdf,84*cdf+a25,a25+84*cdf,a25*84*cdf.Note that a25 and cdf are identifiers and 84 is a literal.You are not asked to do the tedious parsing process with stack snapshots.Instead you only need to draw sysntax trees,but you do need to do lexical analysis

N.B: I need only lexical analysis for this question

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

Dear student, according to the above question, the solution is as follows:

Please note that you haven't mentioned the epsilon (ε) in the term_tail and factor_tail Non-terminals in the grammar.

So, I have included that and solved the question (There should be epsilon in the grammar).

Solutions for the Syntax Trees :

Thank You, All the Best.

Any doubts in this, feel free to contact through the comment section.

Add a comment
Know the answer?
Add Answer to:
Consider the following grammar expr- term term_tail term_tail -add_op term term_tail | term - factor factor_tail...
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
  • 3. Consider the following grammar: expr term term tail term-tail-) add-op term term-ail 1 ε term ...

    3. Consider the following grammar: expr term term tail term-tail-) add-op term term-ail 1 ε term → factor factor-tail factor. tain ε factor (expr) id literal add-op → +1 Draw a syntax tree for parsing each of cdf + (a25 + 84), (a25 + 84)*cdf, 84*cdf+ a25, a25+84 cdf a25*84*cdf. Note that a25 and cdf are identifiers and 84 is a literal You are not asked to do the tedious parsing process with stack snapshots. Instead you only need to...

  • Question 3: Given the following grammar: assign → id := expr expr → expr + term \ term term -term *factor lfactor factor-(expr) id Using the above grammar, show a leftmost derivation (first five step...

    Question 3: Given the following grammar: assign → id := expr expr → expr + term \ term term -term *factor lfactor factor-(expr) id Using the above grammar, show a leftmost derivation (first five steps) for the following assignment statement: A ((A B)+ C) a. [3 marks] b. Using the above grammar, show a rightmost derivation (first five steps) for the following assignment statement: A:-A+B+C)+A [3 marks] Draw the abstract syntax tree for each of the above statements [4 marks]...

  • Using the following grammar: Expr -> Expr + Term I Expr * Term I Term Term->...

    Using the following grammar: Expr -> Expr + Term I Expr * Term I Term Term-> 0 I ... I 9 I (Expr) Draw a parse tree for each of the following: (a) 5 + 4 * 3 (b) 5 * 4 + 3 using the following grammar: Expr -> Term+ Expr I Term * Expr I Term Term -> 0 I …. 9 I (Expr) Draw a parse tree for each of the following: (a) 5 + 4 *...

  • 9. Using the following grammar: Expr -> Term + Expr | Term * Expr | Term...

    9. Using the following grammar: Expr -> Term + Expr | Term * Expr | Term Term -> 0| ... | 9 | ( Expr ) draw a parse tree for each of the following (a) 5 + 4 * 3 (b) 5 * 4 + 3

  • ) Using the following grammar, show a parse tree and a leftmost derivation for the following...

    ) Using the following grammar, show a parse tree and a leftmost derivation for the following sentence (make sure you do not omit parentheses in your derivation):          Grammar          <assign> → <id> = <expr>    <id> → A | B | C    <expr> → <expr> + <term> | <term>    <term> → <term> * <factor> | <factor>    <factor> → (<expr>) | <id> Derive C = (A+B)*(C+A)*(C+B)

  • Considering the following BNF grammar, answer the questions. <prog> - <assign> | <expr> <assign> = <id>...

    Considering the following BNF grammar, answer the questions. <prog> - <assign> | <expr> <assign> = <id> = <expr> <expr> := <expr> + <term> | <expr> - <term> | <term> <term> := <factor> | <factor> * <term> <factor> ::= ( <expr> ) | <id> | <num> <id>::= ABC <num> := 0|1|2|3 2a - What is the associativity of the * operator? (5 points) 2b - For the * and + operators, do they have the same precedence, does the * operator...

  • The questions in this section are based on the grammar given as the following: prog ->...

    The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...

  • The questions in this section are based on the grammar given as the following: prog ->...

    The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...

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

  • What is the output of the following Code? Develop a complete scanner. Write a short report...

    What is the output of the following Code? Develop a complete scanner. Write a short report describing the work performed. Include the source program, input and output. You must show the execution of this program by using several relevant source lines as input, the program must show a list of the tokens scanned. Grammar for the (subset of Lua) language Syntax Analyzer <program> → function id ( ) <block> end <block> → <statement> | <statement> <block> <statement> → <if_statement> |...

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