views:

98

answers:

2

Hi

Here is the grammar rules:

ProcessExpression :  EventExpression "->" ProcessExpression

                    | ProcessName ;

Please can you tell me how can I tell to bison that the first rule has the highest precedence than the second one?

I have tried:

%nonassoc PROC

%right "->"

ProcessExpression :  EventExpression "->" ProcessExpression

                    | ProcessName % prec PROC;

But without any result. Thank you.

A: 

I think, you can apply what you have written, only when there is a left recursion. So try something like this.

%nonassoc PROC
%left EVENT

ProcessExpression :  EventExpression "->" ProcessExpression %prec EVENT

                    | ProcessName % prec PROC;

Thanks, Gokul.

Gokul
A: 

For resolving reduce/reduce conflicts, bison gives rules precedence in the order they are in the source file, so by being first, the first rule has higher precedence. But that is apparently not what you want, or you wouldn't be asking this question.

Using %nonassoc/%right gives precedences to tokens for resolving shift/reduce conflicts. In this case what matters is the precedence of a token to shift to the precedence of a rule to be reduced. There's only one rule involved (though other rules may exist partially parsed in the current state), so it makes no sense to talk about one rule having higher or lower precedence than another in this situation.

So what is it you're trying to do? What exactly is going wrong? Are EventExpression and ProcessName somewhat similar so they have conflicts? You give no information about what those rules are...

Chris Dodd