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 !
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address