以下の文法は( left part = right part # comment )
、# comment
オプションです。
2つの質問:
- 時々警告(ANTLRWorks 1.4.2):
決定は、複数の選択肢を使用して「{Int、Word}」などの入力と一致する可能性があります:1、2(参照
id2
)
しかし、たまにしかありません! - 次の拡張は、コメント(
id2
)にchars'('および')'を含めることができることです。
文法:
grammar NestedBrackets1a1;
//==========================================================
// Lexer Rules
//==========================================================
Int
: Digit+
;
fragment Digit
: '0'..'9'
;
Special
: ( TCUnderscore | TCQuote )
;
TCListStart : '(' ;
TCListEnd : ')' ;
fragment TCUnderscore : '_' ;
fragment TCQuote : '"' ;
// A word must start with a letter
Word
: ( 'a'..'z' | 'A'..'Z' | Special ) ('a'..'z' | 'A'..'Z' | Special | Digit )*
;
Space
: ( ' ' | '\t' | '\r' | '\n' ) { $channel = HIDDEN; }
;
//==========================================================
// Parser Rules
//==========================================================
assignment
: TCListStart id1 '=' id1 ( comment )? TCListEnd
;
id1
: Word+
;
comment
: '#' ( id2 )*
;
id2
: ( Word | Int )+
;