For a class I have to write a compiler for Go. But I'm having some problems with handling identifiers. More specifically when they are used in arithmetic or logical operations. When working with just literals I can have rules like:
LOGICAL_OPERATION: BOOLLITERAL
| NOT LOGICAL_OPERATION
| LPAREN LOGICAL_OPERATION RPAREN
| LOGICAL_OPERATION AND LOGICAL_OPERATION
| LOGICAL_OPERATION OR LOGICAL_OPERATION
;
ARITHMETIC: ARITHMETIC PLUS ARITHMETIC
| ARITHMETIC MIN ARITHMETIC
| ARITHMETIC MUL ARITHMETIC
| ARITHMETIC DIV ARITHMETIC
| DIGIT
| LPAREN ARITHMETIC RPAREN
;
This works, but when I try to add Identifiers to these operations I get reduce/reduce errors
When the next symbol is a semicolon, which is defined to end each statement, he doesn't know to which he needs to go.