ANTLR v4签名整数规则

时间:2017-12-09 18:13:48

标签: antlr grammar antlr4

在minijava示例的ANTLR4语法中我想按照以下规则解析有符号整数:

IntegerLiteral:IntegerSign? DecimalIntegerLiteral;
fragment
DecimalIntegerLiteral:DecimalNumeral IntegertypeSuffix?;
fragment
IntegerSign:'+'|'-';
fragment
IntegertypeSuffix:[lL];
fragment
DecimalNumeral:'0'| NonZeroDigit(Digits?| Underscores Digits);
fragment
Digits:Digit(DigitsAndUnderscores? Digit)?;
fragment
Digit:'0'| NonZeroDigit;
fragment
NonZeroDigit:[1-9];
fragment
DigitsAndUnderscores:DigitOrUnderscore+;
fragment
DigitOrUnderscore:Digit| '_';
fragment
Underscores:'_'+;

但在解析时会因表达式规则而导致错误:

expression:expression PLUS expression # addExpression

enter image description here

我应该如何避免这种冲突?

0 个答案:

没有答案