Hi,

I'm currently writing a small grammar to parse a searchbar language and 
I'm failing at making whitespaces behave like the AND keyword.

Here is my grammar :

grammar SearchBar;

options {
    output=AST;
}

WS  : ( ' ' | '\t' ) { skip(); } ;
AND : 'AND' ;
OR  : 'OR' ;
NOT : 'NOT' ;
LEFT_PAREN  : '(' ;
RIGHT_PAREN : ')' ;
TERM        : ~(' '|'\t'|'"'|RIGHT_PAREN|LEFT_PAREN|NOT|OR|AND)* ;
QUOTEDTERM  : '"' ~('"')* '"' ;

orexpression
    : andexpression ( OR^ andexpression )*
    ;

andexpression
    : notexpression ( (AND^)? notexpression )*
    ;

notexpression
    : (NOT^)? searchterm
    ;

searchterm
    : TERM
    | QUOTEDTERM
    | LEFT_PAREN! orexpression RIGHT_PAREN!
    ;

And here is my tree grammar :

tree grammar SearchBarEval;

options {
    ASTLabelType=CommonTree;
    tokenVocab=SearchBar;
}

prog
    : expr+ ;

expr returns [XMSExpression expression]
    : ^(OR a=expr b=expr) {
        $expression = new Or($a.expression, $b.expression);
    }
    | ^(AND a=expr b=expr) {
        $expression = new And($a.expression, $b.expression);
    }
    | ^(NOT a=expr) {
        $expression = new Not($a.expression);
    }
    | TERM {
        $expression = new Term($TERM.text);
    }
    | QUOTEDTERM {
        $expression = new QuotedTerm($QUOTEDTERM.text);
    }
    ;

When I try to evaluate, for example, the input 'apples bananas tomatos', 
I only get the Term 'apples'. I understand why I'm having this problem 
but I was unable to find a good solution.

Thanks in advance,

--
Aurélien

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/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.


Reply via email to