Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following BNF grammar that we saw in class: EXP ::= EXP + TERM | EX

ID: 3723471 • Letter: C

Question

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 make right choice?
   (d) Compute First and Follow sets for each of the non-terminals
   (e) Prove that the grammar satisfy the two requirements defined in (c).

Explanation / Answer

(c) The two requirements for a grammar to be predictive parser is the following,

i) it should not have left recursion

ii) the grammar should not be non-deterministic

if a grammar is left recursivr, then that left recursion should remove by a method of left factoring. similarly the grammar should be deterministic.

   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote