No one can help me with this? :S Let me know if something is not clear. I need to fix this issue as soon as I can.
Thanks -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Jean-Sebastien Vachon Sent: April-28-11 4:07 PM To: [email protected] Subject: [antlr-interest] Inserting missing nodes Hi All, First, I'd like to make it clear that I'm new to ANTLR so please be kind with me ;) Second, my main problem right now is that I'm currently building a grammar that will let me validate and parse a Boolean query with some special features. I got 90% of my parser working but I'm stuck with the last feature that is required. Basically, I need to be able to insert missing operators (AND/OR) where required. Considering the following query: "software engineer java" I need to build a tree representing the query as if it was "software AND engineer AND java" but I also need to be able to change the inserted operator 'AND' to something else. My first thought was to push a new type of node (let's say DEFAULT_OP) into my tree using a rewrite rule that I could rewrite to the proper operator using a tree walker and/or translator. I made a few tries and got it working in some situations but I can't get it to parse everything I'm throwing at it. My best try so far is shown in the listing below... I did not include the lexer as it is pretty straight forward... All hints and comments are welcomed... Thanks for your help =============================== grammar MyGrammar; options { language = Java; output = AST; ASTLabelType = CommonTree; } query : and_expr+ EOF! ; and_expr : (expr expr+) => default_op | (u1=or_expr (AND^ u2=or_expr)*); or_expr : u1=expr (OR^ u2=expr)* ; default_op : (e1=or_expr e2=or_expr) -> ^(DEFAULT_OP $e1 $e2) ; expr : (NOT^)? (operand) ; operand : (FIELD^)(operand) | PREFIX | WORD | SENTENCE | WORDLIST | NEGATIVE(w=PREFIX|w=WORD|w=SENTENCE|w=WORDLIST) -> ^(NOT $w) | MUST | LPAREN! expr RPAREN! ; List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address 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.
