単純な関数型言語の文法を定義しようとしています。定義はほぼ完了していますが、次のあいまいさを乗り越えることができません。
[14:43:53] warning(200): mygrammar.g:14:11: Decision can match input such as "ATOM" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input
[14:43:53] warning(200): mygrammar.g:14:11: Decision can match input such as "ID" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input
これが、ATOMとIDの図面がほぼ同じである関連ルールだと私が思うものです。
program : (statement'.')* ;
statement : assignment
| expression;
assignment : func '->' statement ((','statement)=> ',' statement)*
| ID '->' expression
| ATOM '->' ( string | number );
func : (ID '(' args ')')=> ID '(' args ')';
term : func
| '(' expression ')'
| number
| string
| ID
| ATOM ;
ATOM : ('A'..'Z'|'_')+;
ID : ('a'..'z'|'_')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
これがANTLRWorksの構文木です
idの代替http://www.vertigrated.com/images/id_alternatives.png
これは、私が構文解析をサポートしようとしているものの大まかなストローマンです。
hypotenuse(a,b) ->
sqr(x) -> x * x,
sqr(sqr(a) + sqr(b)).
print(hypotnenuse(2,3)).
statements
だから私は内部の入れ子をサポートできる必要がありますfunctions
私の代入演算子はどこ->
ですか、これは単一の代入言語です
.
私のステートメント終了マーカーはどこにありますか
これはANTLR3で解析することさえ可能ですか?