edited by
4,049 views
14 votes
14 votes

Consider the following grammar for arithmetic expressions using binary operators $-$ and $/$ which are not associative

  • $E \rightarrow E -T\mid T$
  • $T \rightarrow T/F\mid F$  
  • $F \rightarrow (E) \mid id$

($E$ is the start symbol)

Does the grammar allow expressions with redundant parentheses as in $({id}/{id})$ or in $id -({id}/{id})$ ? If so, convert the grammar into one which does not generate expressions with redundant parentheses. Do this with minimum number of changes to the given production rules and adding at most one more production rule.

edited by

5 Answers

0 votes
0 votes
@Sachin Sir

E → E-T | T

T → T/F | F

F →  (G) | G

G → G-id | id

By this we can reduce the redundancy

Related questions

22 votes
22 votes
3 answers
3