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 grun -gui parse-tree picture has been attached.

the approx , minus rules mutually ambiguous. try these changes:

numrangetypei: int ((approx | minus) int)? ;  approx:  '~' ; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -