[antlr-interest] Lists. Lexer or Parser?
Dave Pawson
dave.pawson at gmail.com
Sat Sep 13 03:06:30 PDT 2008
2008/9/13 Gavin Lambert <antlr at mirality.co.nz>:
> 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>"); } ;
That's the problem? There is no textual content for the lexer to
trigger on for 'list'?
I can define 'item', but not list?
The input is
blah
blah
*list item 1
* list content 2
etc.
>
>>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 :)
I will, though it is discouraging that its content is 3.0 based.
>
> 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.
As I said, this is just me learning by example as I go.
regards
--
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk
More information about the antlr-interest
mailing list