Belgin Fish
Belgin Fish

Reputation: 19827

Extending Grammar for LR Parser

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

Upvotes: 0

Views: 143

Answers (1)

JuniorCompressor
JuniorCompressor

Reputation: 20005

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

Upvotes: 2

Related Questions