java - Antlr4 doesn't find any viable alternative for an input string on a simple grammar -
i'm newbie in antlr , have create grammar parse rules , formulas specified users in project. i've been written hardest 1 contain conditional statement already, second 1 easier first one, no viable alternative input. grammar simple grammar demonstrated below:
grammar pmntidntfrtmpexp; start : statement | statement start ; statement : assignment ; assignment : id '=' addstmt ; addstmt : addstmt '+' mulstmt | addstmt '-' mulstmt | mulstmt ; mulstmt : mulstmt '*' terminal | mulstmt '/' terminal | mulstmt '^' terminal | terminal ; terminal : '('addstmt')' | id | number ; id : '@fild'(digit)+ ; number : digit+ ('.' digit+)? ; digit : '0'..'9' ; ws : [ \t\r\n]+ -> skip ;
but when wanted parse simple string assignment below
@fild76 = @fild12 + @fild43
i came error
line 1:27 no viable alternative @ input '@fild76=@fild12+@fild43'
i'll wonder if body me error.
i not know why grammar fails, seems first rule breaks it:
replacing:
start : statement | statement start ;
with syntactically equivalent
start : statement+ ;
does not emit error
Comments
Post a Comment