Reputation: 1
I just started working with Antlr 4. I tried to write a grammar rules for a simple program, but I'm having a difficult time getting it to work.
I am trying to parse a sequence of lines that look like
$int a;
$string b;
$int num;
However, I keep getting the following error. "line 1:5 mismatched input 'a' expecting IDENTIFIER"
I have tried
Unfortunately, I am having a difficult time figuring out why this is failing or what exactly to search for to find out more about this. My grammar rules are given below
SEPARATION : [ \t\r\n\u000C]+;
fragment
STARTING_CHARACTER : [a-zA-Z];
fragment
CHARACTER : [a-zA-Z0-9_];
TERMINATE_CHARACTER : ';';
fragment
TYPE_OR_VAR_IDENTIFIER : STARTING_CHARACTER CHARACTER*;
NAMESPACED_TYPENAME : TYPE_OR_VAR_IDENTIFIER;
IDENTIFIER : TYPE_OR_VAR_IDENTIFIER;
type : '$' NAMESPACED_TYPENAME;
declaration_statement : SEPARATION? type SEPARATION IDENTIFIER SEPARATION? TERMINATE_CHARACTER;
statement : declaration_statement;
Any help is appreciated!
Upvotes: 0
Views: 83
Reputation: 1
After some additional searching, finally stumbled on to a solution. Looks like this was a similar problem as seen here
Mismatched input error in simple antlr4 grammar
Upvotes: 0