precedence!
Here's the problem I'm having right now:
- "a b.c" correctly parses as "a(b.c)"
- "a(b).c" also - incorrectly - parses as "a(b.c)"
Since I'm relatively a novice at building parsers (this is my first), I'll try to step through my muddled fixing of the situation. I'm looking at the output of the various parser states that bison's given me, and here, I think, is the s/r conflict that needs to be fixed: (correct me if I'm wrong)
As it says, it's state 29. Hello, state 29. First the matching rules are listed. Anything after the `expr:' or `|' is part of the rule that's matched, and the lone `.' indicates where it matches.. for example:
- expr . '.' funccall -- we've just seen an expr, and there's a full stop followed by a function call ahead
- expr . '*' expr -- we just saw an expr, and we're seeing an asterisk and another expr afterward.
- '-' expr . -- we just saw a negation operator and an expr (what lies ahead is irrelevant)
The evil here is that '.' is also shifting. That means instead of reducing expr into a funccall or whatever we like, we continue to shift expr.something. We keep shifting until we reduce, and that'll be when we see something stupid like (b).c, and that reduces nicely into an expr of its own, and then expr expr will reduce into funccall! Mayhem!
The important thing to notice here is that it's also detected that we could reduce '.'. By default, bison handles shift/reduce conflicts by shifting, thus capturing the greatest "area", and associating elements as closely as possible. It shows that the reduce is not being used by surrounding it in brackets. Let's have a quick survey of the other rules:
Here's state 40. We can see that, depending on what happens next, it shifts. Remember kids, that expr on the left is only the most recent expr, since we didn't reduce earlier! That is to say, a(b) was never reduced into one expr, so it still exists as two; a, (b), and thus (b) is the expr before the '.' in these rules.
To back up a little, I don't think state 29 is the cause of all my problems, but similar states elsewhere which don't reduce first are a headache.
