Xtext を使用して、一連の数値を操作するための単純な言語を設計しようとしています。
言語の文字列の例を次に示します。
- {2,1+6} (数字の 2 と 7 のセット)
- {1+3, 3+5} + {2..5} (集合 {4, 8} と {2, 3, 4, 5} の和集合)
私は次の文法を使用しています:
grammar org.example.Set with org.eclipse.xtext.common.Terminals
generate set "http://www.set.net/set"
SetAddition returns SetExpression:
SetMultiplication ({SetAddition.left=current} '+' right=SetMultiplication)*
;
SetMultiplication returns SetExpression:
SetPrimary ({SetMultiplication.left=current} ('*'|'\\') right=SetPrimary)*
;
SetPrimary returns SetExpression:
SetAtom | '(' SetAddition ')'
;
SetAtom returns SetExpression:
Set | Range
;
Set:
lhs = '{' (car=ArithmeticTerm (',' cdr+=ArithmeticTerm)*)? '}'
;
Range:
'{' lhs=ArithmeticTerm '.' '.' rhs=ArithmeticTerm '}'
;
ArithmeticTerm:
Addition //| Multiplication
;
Addition returns ArithmeticTerm:
Multiplication ({Addition.lhs=current} ('+'|'-') rhs=Multiplication)*
;
Multiplication returns ArithmeticTerm:
Primary ({Multiplication.lhs=current} ('*'|'/'|'%') rhs=Primary)*
;
Primary returns ArithmeticTerm:
ArithmeticAtom |
'(' Addition ')'
;
ArithmeticAtom:
value = INT
;
MWE2 ワークフローを実行すると、次のエラーが発生します。
error(211): ../net.certware.argument.language.ui/src-gen/net/certware/argument/language/ui/contentassist/antlr/internal/InternalL.g:420:1: [fatal] rule rule__SetAtom__Alternatives has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
mwe2 ファイルでバックトラッキングを有効にしています。
私はそれにこのコードの断片を持っています:
// The antlr parser generator fragment.
fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {
options = {
backtrack = true
}
}
また、mwe2 ファイルで ANTLR に言及している他のフラグメントはありません。
私が使用している Xtext のバージョンは、Xtext Web サイトから入手できる Full Eclipse に統合された Xtext 2.8.0 です。
バックトラッキングが既に有効になっている場合、ANTLR がバックトラッキングを有効にすることを提案するのはなぜですか? 私の文法に何か問題がありますか?