java - Exact String parsing on antlr4 -


i having issue while doing parsing of file. scenario follows :

in file got parse, have values follows

abc/123/test

the first 3 letters kind of identifiers, , way can differ various line

in grammar file:

file1: str1?;         str1 : newline identifier1 slant integer slant alpha;  integer : [0-9]+; alpha : [a-z]+; slant : '/'; newline : '/n';  identifier1 : 'abc'; 

while running parser, parser not getting line identifier abc, instead giving me strange error

mismatched input 'abc' expecting 'abc' 

how can parse against exact string in antlr4?

the problem lexer lexes abc alpha instead of identifier1. here why:

  1. your identifier1 rules should rather lexer instead of parser rule. rename identifier1
  2. the identifier1 rule must declared before alpha rule, otherwise, alpha have higher precedence , abc parsed alpha instead of identifier1. sure move identifier1 rule above alpha rule, should wok fine.

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -