If I defined tokens like normal object access :
[$_a-zA-Z]+[.] { return ACCESS; }
[$_a-zA-Z]+ { return ID; }
[+] { return PLUIS; }
And the Bison grammar rules:
Accesses
: Accesses ACCESS { /*do something...*/ }
| ACCESS { /*do something...*/ }
Expression
: Accesses ID PLUS Accesses ID { /*do something...*/ }
I want to allow such contents in source codes:
moduleA.valueB.valueC + valueD
In the example, if I don't put empty rule in Accesses
, the single ID
variable like valueD
is illegal. But if I put the empty rule in, Accesses
will cause seriously S/R conflicts, and texts it matched will become strange.
And, I don't think duplicate the rules in Expression
is a good idea, ex:
Expression
: Accesses ID PLUS Accesses ID { /*do something...*/ }
| ID PLUS Accesses ID { /*do something...*/ }
| Accesses ID PLUS ID { /*do something...*/ }
| ID PLUS ID { /*do something...*/ }
Can I find other ways to solve this problem ?
EDIT: Ok thanks to your answer noticed me this simple grammar got no conflicts. At least you let me know that the real problem may hide in somewhere else ( what a mess for a compiler newbie ! ).