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.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.