antlr4 - Why minus sign cannot be read correctly in my Antlr grammar -
i have written following antlr grammar:
grammar hello; file: row+ ; row: karyotype newline ; karyotype: chrnum (',' sexchr const?)? (',' event)* ; event: prefixplus gainchr (const | inh)? # gainchrevent | prefixminus losschr (const | inh)? # losschrevent ; chrnum: numrangetypei ; numrangetypei: int (approx int)? ; gainchr: int | sex ; losschr: int | sex ; prefixplus: plus ques? | ques plus ; prefixminus: minus ques? | ques minus ; sexchr: (sex | ques)+ ; approx: '~' | '-' ; const: 'c' ; inh: 'dn' | 'inh' | 'mat' | 'pat' ; int: [0-9]+ ; minus: '-' ; newline: '\r'? '\n' ; plus: '+' ; ques: '?' ; sex: [xy]+ ; ws : [ \t]+ -> skip ;
but when use following parsing:
43-45,xx,-4
the antlr told me "line 1:9 mismatched input '-' expecting {'-', '+', '?'}"
do know what's wrong grammar?
the approx
, minus
rules mutually ambiguous. try these changes:
numrangetypei: int ((approx | minus) int)? ; approx: '~' ;
Comments
Post a Comment