[antlr-interest] ANTLR3 question
John B. Brodie
jbb at acm.org
Mon Nov 6 13:11:59 PST 2006
Greetings!
>I'm working with the latests ANTLR release and with this rules:
...snipped...
This version of your grammar works just fine for me (v3 3.0b4):
//----begin
grammar t;
options { output=AST; ASTLabelType=MyAST; }
startRule : attribute_arguments EOF;
attribute_arguments: '{' (positional_argument_list? |
(positional_argument_list ',' named_argument_list) |
named_argument_list) '}';
positional_argument_list: (positional_argument) (',' positional_argument)*;
positional_argument: attribute_argument_expression;
named_argument_list: (named_argument) (',' named_argument)*;
named_argument: identifier '=' attribute_argument_expression;
attribute_argument_expression: expression;
expression
: literal
;
literal
: 'true' | 'false'
| INTEGER_LITERAL
| REAL_LITERAL
| 'character'
| 'string'
| 'null'
;
identifier : IDENTIFIER ;
IDENTIFIER : ('a'..'z')+ ;
INTEGER_LITERAL : UINT ;
REAL_LITERAL : (UINT '.' UINT?) | ('.' UINT) ;
fragment UINT : ('0'..'9')+ ;
// Whitespace -- ignored
WS : ( ' ' | '\t' | '\f' | '\r' | '\n' )+ { channel=99; };
// single-line comments
SL_COMMENT :
'//'
( options { greedy=false; } : . )*
( '\r' | '\r\n' | '\n' )
{ channel=99; }
;
// multiple-line comments
ML_COMMENT :
'/*'
( options {greedy=false;} : . )*
'*/'
{ channel=99; }
;
//----end
I suspect that maybe you were alittle too agressive in trying to trim the
problem for posting... (or I got my grammar wrong ;-)
I suspect that your bigger grammar has expressions that involve an
identifier. If so, this probably would lead to an ambiguity on the COMMA the
separates the positional_argument_list from the named_argument_list, altho k=4
should probably be big enuf to take care of that.
Hope this helps... but probably not ;-( maybe post another example?
-jbb
More information about the antlr-interest
mailing list