I try to implement a function call in a custom grammar (plus a similar array-access operator):
expression
: ....OTHER EXPRESSION RULES....
| expression PARENTHESIS_OPEN expressions PARENTHESIS_CLOSE { } %prec DOT
| expression SQUARE_OPEN expressions SQUARE_CLOSE { } %prec DOT
;
Here is my all my operator precedences:
%right ASSIGN ASSIGN_MOD ASSIGN_XOR ASSIGN_AND ASSIGN_STAR ASSIGN_MINUS ASSIGN_PLUS ASSIGN_OR ASSIGN_DIV ASSIGN_LSHIFT ASSIGN_RSHIFT
%right QUESTION COLON
%left OR
%left AND
%left BIN_OR
%left XOR
%left BIN_AND
%left NOT_EQUALS NOT_SAME EQUALS SAME
%left LESS LESS_EQUALS MORE MORE_EQUALS
%left LSHIFT RSHIFT
%left PLUS MINUS
%left PERCENT STAR SLASH
%right TILDE NOT DECREASE INCREASE
%left DOT
Please note that DOT is has the highest precedence. So, I try to give this to my function-call rules. Still, I get 74 shift/reduce warnings, that all follow this pattern:
State 25
15 expression: expression . PLUS expression
16 | expression . MINUS expression
17 | expression . NOT_EQUALS expression
18 | expression . NOT_SAME expression
19 | expression . PERCENT expression
20 | expression . ASSIGN_MOD expression
21 | expression . XOR expression
22 | expression . ASSIGN_XOR expression
23 | expression . BIN_AND expression
24 | expression . AND expression
25 | expression . ASSIGN_AND expression
26 | expression . STAR expression
27 | expression . ASSIGN_STAR expression
28 | expression . ASSIGN_MINUS expression
29 | expression . ASSIGN expression
30 | expression . EQUALS expression
31 | expression . SAME expression
32 | expression . ASSIGN_PLUS expression
33 | expression . BIN_OR expression
34 | expression . OR expression
35 | expression . ASSIGN_OR expression
36 | expression . SLASH expression
37 | expression . ASSIGN_DIV expression
38 | expression . DOT expression
39 | expression . LESS expression
40 | expression . LESS_EQUALS expression
41 | expression . LSHIFT expression
42 | expression . ASSIGN_LSHIFT expression
43 | expression . MORE expression
44 | expression . MORE_EQUALS expression
45 | expression . RSHIFT expression
46 | expression . ASSIGN_RSHIFT expression
48 | expression . PARENTHESIS_OPEN expressions PARENTHESIS_CLOSE
49 | expression . SQUARE_OPEN expressions SQUARE_CLOSE
53 | DECREASE expression .
55 | expression . DECREASE
56 | expression . INCREASE
PARENTHESIS_OPEN shift, and go to state 46
DECREASE shift, and go to state 47
INCREASE shift, and go to state 52
SQUARE_OPEN shift, and go to state 54
DOT shift, and go to state 61
PARENTHESIS_OPEN [reduce using rule 53 (expression)]
SQUARE_OPEN [reduce using rule 53 (expression)]
$default reduce using rule 53 (expression)
State 46, that the conflicted shift indicates, says the following:
State 46
48 expression: expression PARENTHESIS_OPEN . expressions PARENTHESIS_CLOSE
MINUS shift, and go to state 5
TILDE shift, and go to state 6
NOT shift, and go to state 7
PARENTHESIS_OPEN shift, and go to state 8
DECREASE shift, and go to state 9
INCREASE shift, and go to state 10
INT shift, and go to state 11
FLOAT shift, and go to state 12
STRING shift, and go to state 13
CHAR shift, and go to state 14
ID shift, and go to state 15
$default reduce using rule 59 (expressions)
expression go to state 87
expressions go to state 88
I really do not get why bison chooses to reduce. Since I gave the function-call rule the highest possible precedence, bison should try to shift until it matches that one. Still, the prefix DECREASE operator looks like been the choice of bison, even if it has lower precedence.
Why bison does that? How can I say clearly to bison that the function-call rule should have the higher precedence, and thus, avoid the conflicts?