0
votes

I have the following grammar for basic arithmetic expressions

E -> E + T
E -> T
T -> T * F
T -> F
F -> (E)
F -> id

Where E is expression, T is term, F is factor. I'm wondering how I can extend this grammar to support further arithmetic operations such exponents possibly represented with ^ or logarithm.

Thanks

1

1 Answers

2
votes

Since exponentation has higher precedence you could use the following grammar:

E -> E + T
E -> T
T -> T * F
T -> F
F -> G ^ F
F -> G
G -> log(E)
G -> (E)
G -> id