I wanted to make a simple Java parser so I've started with this grammar :
Programme
: Class{ printf("Programme OK!\n");}
;
Class
: ClassPrototype O_ACCOL VariableDeclaration Main C_ACCOL
ClassPrototype
: ACCESS CLASS ID ClassInheritance
| CLASS ID ClassInheritance
;
ClassInheritance
: EXTENDS ID
|
;
VariableDeclaration
: TYPE ID VariableDeclarations
| ACCESS TYPE ID VariableDeclarations
|
;
VariableDeclarations
: COMA ID VariableDeclarations
| S_COLON VariableDeclaration
;
Main
: MainPrototype O_ACCOL C_ACCOL
;
MainPrototype
: ACCESS STATIC VOID MAIN O_PAREN "String" ID C_PAREN
| STATIC VOID MAIN O_PAREN "String" ID C_PAREN
| VOID MAIN O_PAREN "String" ID C_PAREN
;
After compiling I've got 2 shift/reduce conflicts. I think I know why (tell me if I'm wrong) : after reading ACCESS it can't really choose between VariableDeclaration and MainPrototype. So this is what I've found from my reasearches.
But I really don't know how to solve these conflicts. Any ideas ?