[antlr-interest] Lists. Lexer or Parser?
Gavin Lambert
antlr at mirality.co.nz
Sat Sep 13 02:24:48 PDT 2008
At 01:58 13/09/2008, Dave Pawson wrote:
>Obvious next question, how to do it in the Parser please?
Just output whatever you want. Like so:
list : { Console.writeLine("<list>"); } item* {
Console.writeLine("</list>"); } ;
item : TEXT { Console.writeLine("<item>", $TEXT.text, "</item>");
} ;
>I'm not that far in the Antlr book - seems like I do need a tree
>with a non-existant node to hang the list item children from.
Maybe you should read more of the book :)
And you can do it like that if you want to (eg. if you want to
generate an AST you can manipulate or generate multiple kinds of
output from), but if your needs are simple then you might as well
just do the output directly in the parser.
More information about the antlr-interest
mailing list