Recall the unambiguous grammar for arithmetic expressions di

Recall the unambiguous grammar for arithmetic expressions discussed in class:

Modify this grammar to allow an exponentiation operator, ^, so that we can write expressions like i+i^i*i. Of course, your modified grammar should be unambiguous. Give exponentiation higher precedence than the other binary operators and (unlike the other binary operators) make it associate to the right.

Solution

E -> E+T | E-T | T

T -> T*Y | T/Y | Y

Y -> F^Y | F

F -> i | (E)

with the above modified grammer you can easily write expresions like i+i^i*i and

Recall the unambiguous grammar for arithmetic expressions discussed in class: Modify this grammar to allow an exponentiation operator, ^, so that we can write e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site