Posted By:
Darrell_Schiebel
Posted On:
Monday, September 25, 2006 03:57 PM
I'm having trouble generating ASTs for lists. I want these lists to be a flexible as possible... I've got something like: class psrString extends Parser; options { buildAST = true; } complex : COMPLEX | FLOAT ; variant : (OPENSQ!)? (complex ((COMMA^)? complex )*)) (CLOSESQ!)? ; class Scanner extends Lexer; options { filter=WS; } FLOAT : ('-'|'+')? FLT ((('-'|'+') FLT)? 'i' {$setType(COMPLEX);} )? ; COMMA : ',' ; OPENSQ : '[' ; CLOSESQ : ']' ; protected FLT : ( (D)+ ('.' (D)*)? | '.' (D)+ ) ( ('e'|'E') ('-'|'+')? (D)+ )? ; protected D : '0' .. '9' ; protected
More>>
I'm having trouble generating ASTs for lists. I want these lists to be a flexible as possible... I've got something like:
class psrString extends Parser;
options { buildAST = true; }
complex
: COMPLEX
| FLOAT
;
variant
: (OPENSQ!)? (complex ((COMMA^)? complex )*)) (CLOSESQ!)? ;
class Scanner extends Lexer;
options { filter=WS; }
FLOAT : ('-'|'+')? FLT
((('-'|'+') FLT)? 'i' {$setType(COMPLEX);} )? ;
COMMA : ',' ;
OPENSQ : '[' ;
CLOSESQ : ']' ;
protected FLT : ( (D)+ ('.' (D)*)? | '.' (D)+ ) ( ('e'|'E') ('-'|'+')? (D)+ )? ;
protected D : '0' .. '9' ;
protected WS : ' ' | ' ' | '
' {newline();} | '
' '
' {newline();} ;
Now, if there happens to be a COMMA, as in
[1,2,3,4]
, it is parsed and the AST is created fine... however, if the COMMAs are left out, as in
[1 2 3 4]
, then the AST only contains the first item (i.e.
1
).
Can anyone give me a hint about how to handle this?
thanks,
Darrell
<<Less