[antlr-interest] How to recognize 'grammar' in parser ?
Ilia Kantor
ilia at obnovlenie.ru
Sat Dec 23 10:14:57 PST 2006
I wrote simple grammar that should recognize 'grammar <name>;' in parser.
But somehow it fails on 'grammar <gr...>;' example.
Looks like I need to change to lookahead or another method ?
---------------- Test grammar ---------------
grammar Gram;
options {
output=AST;
ASTLabelType=CommonTree;
}
DIGIT
: '0'..'9'
;
LETTER_ENG
: 'a'..'z'
| 'A'..'Z'
;
WS :
(' '|'\r'|'\t'|'\u000C'|'\n' )+ {$channel=HIDDEN;}
;
id : namechar+;
alpha_num
: DIGIT | LETTER_ENG;
namechar
: alpha_num | '_'
;
document : grammar_definition;
s_grammar
: 'grammar';
grammar_definition: s_grammar id ';' -> ^(s_grammar id);
--------------------------- Test input
grammar gr;
------------------------- Output
[mTokens, mT8]: line 2:10 mismatched char: ';' on line 2; expecting char 'a'
[document, grammar_definition, id]: line 0:-1 required (...)+ loop
(decision=1) did not match anything; token=[@-1,0:0='<no text>',<-1>,0:-1]
More information about the antlr-interest
mailing list