parsing - Dealing with overloaded symbols in ambiguous grammars in ANTLR4 -
i trying write parser dialect of answer set programming (asp) which, in terms of grammar, looks prolog extensions. 1 extension, instance expansion, meaning fact(1..3).
instance expanded in fact(1). fact(2). fact(3).
. notice language understands int
, float
numbers , uses .
terminator.
in cases parser fails distinguish between integers, floats, extensions , separators because reckon language ambiguous. in cases, have explicitly separate tokens white spaces. prolog or asp parser, however, correctly deals such productions. read antlr4 can disambiguate problematic productions autonomously, needs don't know how do! ;-) read here , here, apparently did not me.
could please tell me overcome ambiguity? please notice cannot change language because quite standard. in order simplify experts' work, created minimal working example follows.
grammar test; program: statement* ; statement: // dot statement terminator range dot | intnum dot | floatnum dot ; intnum: // not needed, helps in testrig int; floatnum: // not needed, helps in testrig float; range: // defines expansion int dots int ; dots: '..'; dot: '.'; float: digit+ '.' digit* | '.' digit+ ; int: digit+ ; ws: [ \t\r\n]+ -> skip ; fragment nonzero : [1-9] ; fragment digit : [0] | nonzero ;
i use following input:
1 . 1. . 1.5 . .5 . 1 .. 5 . 1. 1.. 1.5. .5. 1..5.
and following errors instead parsed corrected other tools:
line 8:0 extraneous input '1.' expecting '.' line 11:2 extraneous input '.5' expecting '.'
many in advance!
prolog not accept 1.
float. feature makes grammar more ambiguous, maybe try removing feature.
Comments
Post a Comment