[antlr-interest] White space needed in the parsing.
jack zhang
jackgzhang2 at yahoo.com
Thu Sep 18 13:22:01 PDT 2008
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:
tree grammar QueryTree;
options {
// We're going to process an AST whose nodes are of type CommonTree.
ASTLabelType = CommonTree;
// We're going to use the tokens defined in
// both our MathLexer and MathParser grammars.
// The MathParser grammar already includes
// the tokens defined in the MathLexer grammar.
//tokenVocab =QueryParser; // because it contains a token spec.
}
// We want to add some fields and methods to the generated class.
@members {
private CommandParser commandParser;
public void
setCommandParser(CommandParser dateParser)
{
this.commandParser = commandParser;
}
}//members
orexpression returns [String s] :
^(OR a=expr b=expr) {
s = "(" + a + " or " + b + ")";
};
andexpression returns [String s] :
^(AND a=expr b=expr) {
s = "(" + a + " and " + b + ")";
};
notexpression returns [String s] :
^(NOT a=expr) {
s = "(not " + a + ")";
};
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 !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080918/15307986/attachment.html
More information about the antlr-interest
mailing list