[il-antlr-interest: 33305] Re: [antlr-interest] Deciphering the TreeWalker error message ...
Hi Folks, I take on board the unanimous input that the tree grammar rule should start with TOKEN. However what keeps me puzzled is that, inspite of having all my rules intact and just slightly rejigging my alternatives make the tree grammar parse the input tree perfectly fine. I am able to parse huge SQL of about 160 lines with many many expressions fine! Also wouldn't the following expression ^(^(SUB_EXPR A) B) simply mean that we have a simple list of subtree followed by a node B that is rooted at a nil node? I was under the impression that the above syntax is valid as 1. There is a mention of tree simulation like ^( nil ^(VARDEF int i) ^(VARDEF int j) ) in page 167/372 in the chapter Proper AST Structure in Definitive ANTLR Reference. 2. ANTLR doesn't report any error while compiling. 3. The grammar works for most test cases involving expression. Thanks, Vasan On 7/21/2011 10:06 PM, Kevin J. Cummings wrote: On 07/21/2011 02:48 AM, Gary Miller wrote: 3. rule : ^(subrule otherrule) ; Just looks wrong. I am under the impression that a treewalker rule should be rooted in a TOKEN, not a subtree. The few treewalker grammars I have written always have rules that look like ^(TOKEN some other rules or TOKENS) If a subrule reference is not allowed to be the root of the tree being parsed, I would have thought that ANTLR would have issued an error when the tree grammar was run through ANTLR I could be wrong with my assumption here, but I have never gotten into trouble by assuming it (so far). Often this involves me collapsing my treewalker rules together. For example, if I have 12 parse rules to accurately describe precidence in an expression, my treegrammar might have 12 alternations, one for each possibly different rooted TOKEN when walking them. This makes my treegrammars (much) smaller than my parser grammars. If you inline (expand) out what you have written you would get compoundExpression : ^((SUB_EXPR ^(PAREN_SCLAR_EXPRESSION sclarExpression+) conversion_clause ) ; The ^(( is impossible Make all you start tree look like ^(TOKEN ...) ^(sign sse=sclarSubExpression) therefore also look wrong. Yes, treegrammar rules can refer to other rules, but the rooted expressions: ^() should be rooted with TOKENs. 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
[il-antlr-interest: 33271] Re: [antlr-interest] Deciphering the TreeWalker error message ...
Hey Grey, Yes you are absolutely right, the first element is a rule reference. My sclarSubExpression snippet is as follows:- sclarSubExpression : ^(SUB_EXPR ^(sign sse=sclarSubExpression)) | ^(SUB_EXPR expressionWithParen) | ^(SUB_EXPR function) | ^(SUB_EXPR object_name) | ^(SUB_EXPR constant) | ^(SUB_EXPR coalesce_exp) | ^(SUB_EXPR nullif_exp) | ^(SUB_EXPR case_expression) ; expressionWithParen : ^(PAREN_SCLAR_EXPRESSION sclarExpression+) ; The toStringTree AST is also provided below: Works:- -- DML_STATEMENT DOWN select DOWN SELECT_LIST DOWN SELECT_ITEM DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN PAREN_SCLAR_EXPRESSION DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN 1 UP UP UP UP UP UP UP from DOWN TABLE_LIST_ITEM DOWN TABLE_OR_VIEW_NAME DOWN table1 UP UP UP where DOWN CONDITION_LIST DOWN between DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN 2 UP UP and DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN 3 UP UP COMPOUND_EXPR DOWN SUB_EXPR DOWN 4 UP UP UP UP UP UP UP UP Parser AST Tree : (DML_STATEMENT (select (SELECT_LIST (SELECT_ITEM (COMPOUND_EXPR (SUB_EXPR (PAREN_SCLAR_EXPRESSION (COMPOUND_EXPR (SUB_EXPR 1))) (from (TABLE_LIST_ITEM (TABLE_OR_VIEW_NAME table1))) (where (CONDITION_LIST (between (COMPOUND_EXPR (SUB_EXPR 2)) (and (COMPOUND_EXPR (SUB_EXPR 3)) (COMPOUND_EXPR (SUB_EXPR 4 Fails: --- DML_STATEMENT DOWN select DOWN SELECT_LIST DOWN SELECT_ITEM DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN PAREN_SCLAR_EXPRESSION DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN 1 UP UP UP UP UP UP UP from DOWN TABLE_LIST_ITEM DOWN TABLE_OR_VIEW_NAME DOWN table1 UP UP UP where DOWN CONDITION_LIST DOWN between DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN 2 UP UP and DOWN COMPOUND_EXPR DOWN SUB_EXPR DOWN 3 UP UP COMPOUND_EXPR DOWN SUB_EXPR DOWN 4 UP UP UP UP UP UP UP UP Parser AST Tree : (DML_STATEMENT (select (SELECT_LIST (SELECT_ITEM (COMPOUND_EXPR (SUB_EXPR (PAREN_SCLAR_EXPRESSION (COMPOUND_EXPR (SUB_EXPR 1))) (from (TABLE_LIST_ITEM (TABLE_OR_VIEW_NAME table1))) (where (CONDITION_LIST (between (COMPOUND_EXPR (SUB_EXPR 2)) (and (COMPOUND_EXPR (SUB_EXPR 3)) (COMPOUND_EXPR (SUB_EXPR 4 Thanks for spending your valuable time looking into this issue. Regards, Vasan On 7/21/2011 11:23 AM, Gary Miller wrote: Hey Vasan, Without seeing the reset of the tree walker grammar and the toStringTree of the AST I'm really just guessing. The rule looks a bit odd to me. All my tree walker rules look more like compoundExpression : ^(SOMETOKEN conversion_clause) | sclarSubExpression ; I guess you can have rules as the first element of a tree, its just not something that turns up in my tree grammars. Regards Gary On Thu, Jul 21, 2011 at 3:29 PM, srinivasan karthikeyan pitchai srinivasan.karthikeyan.pitc...@oracle.com wrote: Hi Folks, I forgot to mention. The compoundExpression rule has options{backtrack = true;} set that is it reads like compoundExpression options {backtrack = true;} : ^(sclarSubExpression conversion_clause) | sclarSubExpression ; Thanks, Vasan On 7/21/2011 10:56 AM, srinivasan karthikeyan pitchai wrote: Jim, Gray, Loring, Thanks for pitching in to give me some direction to focus on. ANTLR Gurus, I've solved the issue. Still I am unable to reason out my fix. I am providing the offending grammar snippet below and would appreciate your rationale to get an insight into the problem and how the fix works!! The below rule fails with the no viable alt; token=[@-1,0:0='DOWN' error message compoundExpression: ^(sclarSubExpression conversion_clause) | sclarSubExpression ; However when I change the rule like the following, i.e make the conversion_clause optional and then remove the second alternative every thing works fine!! In my mind both the rules are semantically identical. compoundExpression: ^(sclarSubExpression conversion_clause?) ; Thanks a ton. -Vasan On 7/21/2011 4:16 AM, Jim Idle wrote: Or use the dot description producing methods and create a nice graphic with graphviz. Much easier to see that way. Jim -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of Gary Miller Sent: Wednesday, July 20, 2011 3:44 PM To: antlr-interest@antlr.org Subject: Re: [antlr-interest] Deciphering the TreeWalker error message ... I often find it usefully to print out the AST (toStringTree in Java) and walk through the tree grammar manually. Regards Gary On Thu, Jul 21, 2011 at 3:15 AM, Loring Craymerlgcray...@yahoo.com wrote: UP and DOWN tokens (start/end of child list for tree) do not have location information attached so no line/column error reporting. Mostly the error says that you started a subtree that your grammar does not match, probably an LPAREN or RPAREN rooted subtree from your report of cases where you do or do not get the error. --Loring
[il-antlr-interest: 33243] [antlr-interest] Deciphering the TreeWalker error message ...
Hi Folks, What does the ANTLR walker error message like the following mean? no viable alt; token=[@-1,0:0='DOWN' Would appreciate any general guidance/suggestions to zero in on the errors of this nature. Thanks, Vasan Input sql: --- select (1) from table1 where 2 between 3 and 4; Error Message: TDWalker1.g: node from after line 2:8 [start1, startStatement, dml, query_term, query_expression, query, query_unit, where_clause, condition_list, condition_subexpression, condition] Walker1: no viable alt; token=[@-1,0:0='DOWN',2,0:-1] (decision=127 state 0) decision=590:1: condition options {backtrack=true; } : ( ^( comparison_operator ( condition_quantifier )? c1= condition c2= condition ) | ^( BETWEEN expression ^( and_or_operator c1= condition c2= condition ) ) | ^( condition_operator expression c1= condition ^( ESCAPE escape_character ) ) | ^( condition_operator expression c1= condition ) | ^( condition_operator expression_list c1= condition ) | ^( NOT c1= condition ) | ^( EXISTS expression ) | ^( IS_NOT_NULL expression ) | ^( IS_NULL expression ) | ^( IS_NOT expression UNTIL_CHANGED ) | ^( IS expression UNTIL_CHANGED ) | ^( IS_NOT expression UNTIL_CLOSED ) | ^( IS expression UNTIL_CLOSED ) | expression | condition_list ); context=.. However the following SQL, that just doesn't have the parenthesis around 1, works fine!!! select (1) from table1 where 2 between 3 and 4; 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
[il-antlr-interest: 33267] Re: [antlr-interest] Deciphering the TreeWalker error message ...
Jim, Gray, Loring, Thanks for pitching in to give me some direction to focus on. ANTLR Gurus, I've solved the issue. Still I am unable to reason out my fix. I am providing the offending grammar snippet below and would appreciate your rationale to get an insight into the problem and how the fix works!! The below rule fails with the no viable alt; token=[@-1,0:0='DOWN' error message compoundExpression: ^(sclarSubExpression conversion_clause) | sclarSubExpression ; However when I change the rule like the following, i.e make the conversion_clause optional and then remove the second alternative every thing works fine!! In my mind both the rules are semantically identical. compoundExpression: ^(sclarSubExpression conversion_clause?) ; Thanks a ton. -Vasan On 7/21/2011 4:16 AM, Jim Idle wrote: Or use the dot description producing methods and create a nice graphic with graphviz. Much easier to see that way. Jim -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of Gary Miller Sent: Wednesday, July 20, 2011 3:44 PM To: antlr-interest@antlr.org Subject: Re: [antlr-interest] Deciphering the TreeWalker error message ... I often find it usefully to print out the AST (toStringTree in Java) and walk through the tree grammar manually. Regards Gary On Thu, Jul 21, 2011 at 3:15 AM, Loring Craymerlgcray...@yahoo.com wrote: UP and DOWN tokens (start/end of child list for tree) do not have location information attached so no line/column error reporting. Mostly the error says that you started a subtree that your grammar does not match, probably an LPAREN or RPAREN rooted subtree from your report of cases where you do or do not get the error. --Loring From: srinivasan karthikeyan pitchai srinivasan.karthikeyan.pitc...@oracle.com To: antlr-interest@antlr.org Cc: Terence Parrpa...@cs.usfca.edu Sent: Wednesday, July 20, 2011 9:46 AM Subject: [antlr-interest] Deciphering the TreeWalker error message ... Hi Folks, What does the ANTLR walker error message like the following mean? no viable alt; token=[@-1,0:0='DOWN' Would appreciate any general guidance/suggestions to zero in on the errors of this nature. Thanks, Vasan Input sql: --- select (1) from table1 where 2 between 3 and 4; Error Message: TDWalker1.g: node from after line 2:8 [start1, startStatement, dml, query_term, query_expression, query, query_unit, where_clause, condition_list, condition_subexpression, condition] Walker1: no viable alt; token=[@-1,0:0='DOWN',2,0:-1] (decision=127 state 0) decision=590:1: condition options {backtrack=true; } : ( ^( comparison_operator ( condition_quantifier )? c1= condition c2= condition ) | ^( BETWEEN expression ^( and_or_operator c1= condition c2= condition ) ) | ^( condition_operator expression c1= condition ^( ESCAPE escape_character ) ) | ^( condition_operator expression c1= condition ) | ^( condition_operator expression_list c1= condition ) | ^( NOT c1= condition ) | ^( EXISTS expression ) | ^( IS_NOT_NULL expression ) | ^( IS_NULL expression ) | ^( IS_NOT expression UNTIL_CHANGED ) | ^( IS expression UNTIL_CHANGED ) | ^( IS_NOT expression UNTIL_CLOSED ) | ^( IS expression UNTIL_CLOSED ) | expression | condition_list ); context=.. However the following SQL, that just doesn't have the parenthesis around 1, works fine!!! select (1) from table1 where 2 between 3 and 4; 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 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 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
[il-antlr-interest: 33268] Re: [antlr-interest] Deciphering the TreeWalker error message ...
Hi Folks, I forgot to mention. The compoundExpression rule has options{backtrack = true;} set that is it reads like compoundExpression options {backtrack = true;} : ^(sclarSubExpression conversion_clause) | sclarSubExpression ; Thanks, Vasan On 7/21/2011 10:56 AM, srinivasan karthikeyan pitchai wrote: Jim, Gray, Loring, Thanks for pitching in to give me some direction to focus on. ANTLR Gurus, I've solved the issue. Still I am unable to reason out my fix. I am providing the offending grammar snippet below and would appreciate your rationale to get an insight into the problem and how the fix works!! The below rule fails with the no viable alt; token=[@-1,0:0='DOWN' error message compoundExpression: ^(sclarSubExpression conversion_clause) | sclarSubExpression ; However when I change the rule like the following, i.e make the conversion_clause optional and then remove the second alternative every thing works fine!! In my mind both the rules are semantically identical. compoundExpression: ^(sclarSubExpression conversion_clause?) ; Thanks a ton. -Vasan On 7/21/2011 4:16 AM, Jim Idle wrote: Or use the dot description producing methods and create a nice graphic with graphviz. Much easier to see that way. Jim -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of Gary Miller Sent: Wednesday, July 20, 2011 3:44 PM To: antlr-interest@antlr.org Subject: Re: [antlr-interest] Deciphering the TreeWalker error message ... I often find it usefully to print out the AST (toStringTree in Java) and walk through the tree grammar manually. Regards Gary On Thu, Jul 21, 2011 at 3:15 AM, Loring Craymerlgcray...@yahoo.com wrote: UP and DOWN tokens (start/end of child list for tree) do not have location information attached so no line/column error reporting. Mostly the error says that you started a subtree that your grammar does not match, probably an LPAREN or RPAREN rooted subtree from your report of cases where you do or do not get the error. --Loring From: srinivasan karthikeyan pitchai srinivasan.karthikeyan.pitc...@oracle.com To: antlr-interest@antlr.org Cc: Terence Parrpa...@cs.usfca.edu Sent: Wednesday, July 20, 2011 9:46 AM Subject: [antlr-interest] Deciphering the TreeWalker error message ... Hi Folks, What does the ANTLR walker error message like the following mean? no viable alt; token=[@-1,0:0='DOWN' Would appreciate any general guidance/suggestions to zero in on the errors of this nature. Thanks, Vasan Input sql: --- select (1) from table1 where 2 between 3 and 4; Error Message: TDWalker1.g: node from after line 2:8 [start1, startStatement, dml, query_term, query_expression, query, query_unit, where_clause, condition_list, condition_subexpression, condition] Walker1: no viable alt; token=[@-1,0:0='DOWN',2,0:-1] (decision=127 state 0) decision=590:1: condition options {backtrack=true; } : ( ^( comparison_operator ( condition_quantifier )? c1= condition c2= condition ) | ^( BETWEEN expression ^( and_or_operator c1= condition c2= condition ) ) | ^( condition_operator expression c1= condition ^( ESCAPE escape_character ) ) | ^( condition_operator expression c1= condition ) | ^( condition_operator expression_list c1= condition ) | ^( NOT c1= condition ) | ^( EXISTS expression ) | ^( IS_NOT_NULL expression ) | ^( IS_NULL expression ) | ^( IS_NOT expression UNTIL_CHANGED ) | ^( IS expression UNTIL_CHANGED ) | ^( IS_NOT expression UNTIL_CLOSED ) | ^( IS expression UNTIL_CLOSED ) | expression | condition_list ); context=.. However the following SQL, that just doesn't have the parenthesis around 1, works fine!!! select (1) from table1 where 2 between 3 and 4; 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 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 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send
[il-antlr-interest: 33270] Re: [antlr-interest] Deciphering the TreeWalker error message ...
Hi Gurus, Input: select (1) from table1 where 2 between 3 and 4; For what ever it is worth, even the equivalent rewrite of the rule continues to fail!! compoundExpression options {backtrack = true;} : ^(sclarSubExpression conversion_clause | ^(sclarSubExpression blank) ; blank: ; The only acceptable rule seems to be: compoundExpression: ^(sclarSubExpression conversion_clause?) ; Any insight into the nature of the issue and why it works using the second rule definition, while it fails with the first rule definition would be great. Many Thanks, Vasan On 7/21/2011 10:59 AM, srinivasan karthikeyan pitchai wrote: Hi Folks, I forgot to mention. The compoundExpression rule has options{backtrack = true;} set that is it reads like compoundExpression options {backtrack = true;} : ^(sclarSubExpression conversion_clause) | sclarSubExpression ; Thanks, Vasan On 7/21/2011 10:56 AM, srinivasan karthikeyan pitchai wrote: Jim, Gray, Loring, Thanks for pitching in to give me some direction to focus on. ANTLR Gurus, I've solved the issue. Still I am unable to reason out my fix. I am providing the offending grammar snippet below and would appreciate your rationale to get an insight into the problem and how the fix works!! The below rule fails with the no viable alt; token=[@-1,0:0='DOWN' error message compoundExpression: ^(sclarSubExpression conversion_clause) | sclarSubExpression ; However when I change the rule like the following, i.e make the conversion_clause optional and then remove the second alternative every thing works fine!! In my mind both the rules are semantically identical. compoundExpression: ^(sclarSubExpression conversion_clause?) ; Thanks a ton. -Vasan On 7/21/2011 4:16 AM, Jim Idle wrote: Or use the dot description producing methods and create a nice graphic with graphviz. Much easier to see that way. Jim -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of Gary Miller Sent: Wednesday, July 20, 2011 3:44 PM To: antlr-interest@antlr.org Subject: Re: [antlr-interest] Deciphering the TreeWalker error message ... I often find it usefully to print out the AST (toStringTree in Java) and walk through the tree grammar manually. Regards Gary On Thu, Jul 21, 2011 at 3:15 AM, Loring Craymerlgcray...@yahoo.com wrote: UP and DOWN tokens (start/end of child list for tree) do not have location information attached so no line/column error reporting. Mostly the error says that you started a subtree that your grammar does not match, probably an LPAREN or RPAREN rooted subtree from your report of cases where you do or do not get the error. --Loring From: srinivasan karthikeyan pitchai srinivasan.karthikeyan.pitc...@oracle.com To: antlr-interest@antlr.org Cc: Terence Parrpa...@cs.usfca.edu Sent: Wednesday, July 20, 2011 9:46 AM Subject: [antlr-interest] Deciphering the TreeWalker error message ... Hi Folks, What does the ANTLR walker error message like the following mean? no viable alt; token=[@-1,0:0='DOWN' Would appreciate any general guidance/suggestions to zero in on the errors of this nature. Thanks, Vasan Input sql: --- select (1) from table1 where 2 between 3 and 4; Error Message: TDWalker1.g: node from after line 2:8 [start1, startStatement, dml, query_term, query_expression, query, query_unit, where_clause, condition_list, condition_subexpression, condition] Walker1: no viable alt; token=[@-1,0:0='DOWN',2,0:-1] (decision=127 state 0) decision=590:1: condition options {backtrack=true; } : ( ^( comparison_operator ( condition_quantifier )? c1= condition c2= condition ) | ^( BETWEEN expression ^( and_or_operator c1= condition c2= condition ) ) | ^( condition_operator expression c1= condition ^( ESCAPE escape_character ) ) | ^( condition_operator expression c1= condition ) | ^( condition_operator expression_list c1= condition ) | ^( NOT c1= condition ) | ^( EXISTS expression ) | ^( IS_NOT_NULL expression ) | ^( IS_NULL expression ) | ^( IS_NOT expression UNTIL_CHANGED ) | ^( IS expression UNTIL_CHANGED ) | ^( IS_NOT expression UNTIL_CLOSED ) | ^( IS expression UNTIL_CLOSED ) | expression | condition_list ); context=.. However the following SQL, that just doesn't have the parenthesis around 1, works fine!!! select (1) from table1 where 2 between 3 and 4; 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 List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your
[il-antlr-interest: 32743] [antlr-interest] AST rewrite
Hi Gurus, I'm a novice using ANTLR for a development project. I am at a stage where I need to rewrite AST so that the transformed AST renders itself more easy for me to walk and emit the translation that I need. In this context I've a concept question. In general, can I use the *same* tree adapter, used by the InputNodeStream used by the walker, in a java method that I code to restructure the tree without using the rewrite rule? That is can I add, delete, replace nodes at will in the source tree? I am looking at this option as I need to move up a subtree from deep down to a much higher level. In particular would manipulating the source tree mess up the iterator used by the ANTLR AST walker to parse the tree? (eg) Just want to know if I can effect this in JAVA. I am sure we can make it happen using rewrite rule. However I want to conceptually know if what I desire above is a feasibility or it it a totally wrong approach. ^(ROOT a b ^(ROOT c d ^(ROOT e f g))) I need to restructure the tree like, say, ^(ROOT a b ^(ROOT c d ) ^(ROOT e f g)) Based on your input I need to chalk the future course of my coding. Thanks in advance. Regards, Vasan 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
[il-antlr-interest: 32748] Re: [antlr-interest] AST rewrite
Thanks for sharing your input. I am able to do some pretty complex AST manipulation as stated initially. First results are very encouraging, I am getting an end to end translation successfully. Regards, Vasan On 6/11/2011 7:31 PM, Trevor John Thompson wrote: The short answer is yes, you can manipulate the tree (before walking, not during). I am using tree adapter manipulations to reorganize the AST, and then handing the tree to the standard tree walker. The only caution is that TreeIterator depends on parent pointers. I am contemplating a version that does not have this dependency, so i can base my trees on BaseTree, rather than CommonTree. On 2011 Jun 11, at 00:53, srinivasan karthikeyan pitchai wrote: Hi Gurus, I'm a novice using ANTLR for a development project. I am at a stage where I need to rewrite AST so that the transformed AST renders itself more easy for me to walk and emit the translation that I need. In this context I've a concept question. In general, can I use the *same* tree adapter, used by the InputNodeStream used by the walker, in a java method that I code to restructure the tree without using the rewrite rule? That is can I add, delete, replace nodes at will in the source tree? I am looking at this option as I need to move up a subtree from deep down to a much higher level. In particular would manipulating the source tree mess up the iterator used by the ANTLR AST walker to parse the tree? (eg) Just want to know if I can effect this in JAVA. I am sure we can make it happen using rewrite rule. However I want to conceptually know if what I desire above is a feasibility or it it a totally wrong approach. ^(ROOT a b ^(ROOT c d ^(ROOT e f g))) I need to restructure the tree like, say, ^(ROOT a b ^(ROOT c d ) ^(ROOT e f g)) Based on your input I need to chalk the future course of my coding. Thanks in advance. Regards, Vasan List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- Trevor John Thompson(425) 246-4023 net: ti...@me.com Quidquid Latine dictum sit, altum videtur. 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.