Shift / reduce conflicts in grammar of arithmetic expression with n-ary sums / products

Posted by aioobe on Stack Overflow See other posts from Stack Overflow or by aioobe
Published on 2010-02-18T12:39:03Z Indexed on 2010/05/03 11:48 UTC
Read the original article Hit count: 428

Parsing binary sums / products are easy, but I'm having troubles defining a grammar that parses

a + b * c + d + e

as

sum(a, prod(b, c), d, e)

My initial (naive) attempt generated 61 shift / reduce conflicts.

I'm using java cup (but I suppose a solution for any other parser generator would be easily translated).

© Stack Overflow or respective owner

Related posts about parsing

Related posts about grammar