[antlr-interest] White space needed in the parsing.
Jim Idle
jimi at temporal-wave.com
Thu Sep 18 14:18:54 PDT 2008
On Thu, 2008-09-18 at 22:42 +0200, Markus Fröb wrote:
> > -----Ursprüngliche Nachricht-----
> > Von: "jack zhang" <jackgzhang2 at yahoo.com>
> > Gesendet: 18.09.08 22:22:29
> > An: antlr-interest at antlr.org
> > Betreff: [antlr-interest] White space needed in the parsing.
>
> >
> >
> > Thanks! it works. Another question is that (Sorry that I am pretty
> > new to Antlr) in the tree walker, how to walk the WORD+ parser.
> >
> > Currently I have following tree walker:
> >
> ------------------ CUT ----------------------
> >
> > expr returns [String s]
> > : ^(NOT a=expr) {
> > s = "(not " + a + ")";
> > }
> > |
> > ^(AND a=expr b=expr) {
> > s = "(" + a + " and " + b + ")";
> > }
> > | ^(OR a=expr b=expr) {
> > s = "(" + a + " or " + b + ")";
> > }
> > | WORD {
> > s = dateParser.parse($WORD.text);
> > }
> > ;
> >
> >
> >
> >
> >
> > But it only matches the first word and totally ignored the rest. Is
> > there a way to do this:
> >
> > WORD+ { for (String WORD :WORD+ { // do something to each WORD} }
> >
> > Thx !
>
> Your expression matches only one word, as you only specified one. I think the following should work (but I cannot guarantee this, as I haven't worked much with tree parsers yet):
>
> expr returns [String s]:
> ... and, or, not
> | w=word_expr { s = w; }
> ;
>
> word_expr returns [String s]
> : w=WORD e=word_expr { s = w + e; }
> | { s = ""; }
> ;
Its simpler than that (though I don't know what the dateParser call is
for:
| ( WORD { $s = $s + " " + $WORD.text); })+
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080918/d69665b6/attachment.html
More information about the antlr-interest
mailing list