> -----Ursprüngliche Nachricht-----
> Von: "jack zhang" <[EMAIL PROTECTED]>
> Gesendet: 18.09.08 22:22:29
> An: [EMAIL PROTECTED]
> 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 = ""; }
;
This is right recursion as word_expr can match either a word and something
following, or nothing at all, which then returns the empty string. Since ANTLR
is greedy be default, and I think the tree parsers, too, this should catch all
words.
________________________________________________________________________
"50 erste Dates" mit Adam Sandler u. Drew Barrymore kostenlos anschauen!
Exklusiv für alle WEB.DE Nutzer. http://www.blockbuster.web.de
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---