ChrisDodd/btyacc

How to make sure btyacc takes a specific path first

satya-das opened this issue · 2 comments

I am using btyacc to parse c++ (https://github.com/satya-das/cppparser) and I am having trouble to parse function declaration that has single pointer parameter. For example:
Type FuncName(Id* VarName);
gets parsed as if Id* VarName is an expression involving multiplication and FuncName is a variable of type Type initialized with value of the expression in ().
This can certainly be the case when initializing an object using it's constructor that takes single argument. But I want my parser to parse it as function declaration and when it fails in that then only it should take this path. I have tried using %prec but it is always taking the expression route first.
Is there a way I can ensure btyacc takes recommended parsing route first? Ordering of grammar rules doesn't help either.

The order of trials is always the same as the default yacc conflict resolution -- shift first, then reductions in the order of the rules in the file. It would not be easy to change that, but you can usually get the order you need by having the conflicts surface as reduce/reduce conflicts and use order to get the right priority.

In you case, making sure that the typename: IDENTIFIER rule is before the expression: IDENTIFIER rule should suffice -- that input will hit the reduce/reduce conflict between those two rules, and you want to try the typename path first.

Thanks for this suggestion. It helped me apply a workaround that worked.