I am a beginner in ANTLR, and i want to make a program that detects variables. For that I wrote the following ANTLR code, but when I test it using grun
, it gives me an error line 1:0 token recognition error at: 'p'
on entering input p=10
. I am unable to understand why does this not work.
grammar rules;
/*
* Parser Rules
*/
addition : NUMBER PLUS NUMBER;
assign : VARIABLE ASSIGNMENT NUMBER;
/*
* Lexer Rules
*/
VARIABLE : [a-zA-Z_]+;
NUMBER : [0-9]+ ;
WHITESPACE : [ \n\t\r]+ -> skip ;
NEWLINE: '\n';
PLUS : '+';
ASSIGNMENT : '=';
The rule for addition works fine, but the assign is not working.
The command I am running on terminal is antlr4 rules.g4;grun rules assign -tokens
and after that I input p=10
for testing, but still it does not work and shows me line 1:0 token recognition error at: 'p'
error.
expression := addition | assign
– jurez