I’m learning how to write parsers, and to do so, I’m writing parser for SQL.
Grammar I’m writing is processed by perl Parse::Eyapp module, which is very similar to standard yacc.
When I added support for single-operand operators (not sure what is the correct name – operators like 12!, or @@ ‘value’), when compiling the grammar to perl, I got:
14 shift/reduce conflicts
I had it also earlier, but I solved it by adding appropriate %left and %right, but this time I’m at loss, since the problem seems to be from conflict between 1-operand operators, and more traditional two-operand ones.
Full grammar is too long to put in here, so I’ll just link to it.
To compile it, I use command:
eyapp -m Pg::SQL::Parser::SQL -o SQL.pm SQL.eyp
When running eyapp ... with verbose enabled, I get this output.
So, the question is: how to solve the problem in here?
Aargh. Looks like I misdiagnosed the problem. The real cause of the problem were not unary operators, but cast (expr ‘::’ normal_type).
Adding %left ‘::’ at the end of priority configs solved the problem.
In case you’re curious – commit link.