我正在尝试在 ANTLR 中创建一个评估命题逻辑公式的语法。所以对于输入(1 & 0) | 1
,它应该返回true
。
我已经构建了以下内容:
code returns[boolean value]
: formula EOF {$value = $formula.value;}
;
formula returns [boolean value]
: equiv {$value = $equiv.value;}
;
equiv returns [boolean value]
: a=implies {$value = $a.value;}
( '#' b=implies {$value = $value == $b.value;}
)*
;
implies returns [boolean value]
: a=or {$value = $a.value;}
( '>' b=or {$value = !$value || $b.value;}
)*
;
or returns [boolean value]
: a=and {$value = $a.value;}
( '|' b=and {$value ||= $b.value;}
)*
;
and returns [boolean value]
: a=term {$value = $a.value;}
( '&' b=term {$value &&= $b.value;}
)*
;
term returns [boolean value]
: '(' formula ')' {$value = $formula.value;}
| '0' {$value = false;}
| '1' {$value = true;}
| '¬' term {$value = !$term.value;}
;
WHITESPACE: (' '|'\t'|'\r'|'\f'|'\n')+{$channel = HIDDEN;} ;
但是我不断收到错误java.lang.NoSuchFieldError: offendingToken。无论如何要找出错误在哪里或如何解决它?