[il-antlr-interest: 35035] [antlr-interest] Changing the root of a tree in a tree parser

2011-11-28 Thread franck102
I am trying to do something that seems pretty simple, which is adjusting the root token of a tree in my tree parser. Basically my parser always sees a=b as a comparison and generates ^( EQUAL a b) as an AST, and in the tree parser I want to adjust that to ^( ASSIGN a b) if I am at the statement

[il-antlr-interest: 35036] [antlr-interest] Tree building limitation in tree grammars?

2011-11-28 Thread franck102
My parser grammar can generate a number of subtrees with similar structure, and just a different root type. In the tree grammar I am trying to just pass such a subtree along without any changes, but that is turning out to be much trickier than I expected, am I missing something? Given this AST:

[il-antlr-interest: 35037] Re: [antlr-interest] notation algorithm translation

2011-11-28 Thread Christian
Hello, is ST and/or Antlr can solve that problem? Sure, it can! But a pattern matching framework could be a better alternative because it is more straight forward in mapping input to output. However, if you at all costs want to use ANTLR in combination with StringTemplate, you need to do the

[il-antlr-interest: 35039] Re: [antlr-interest] Confused about backtracking

2011-11-28 Thread franck102
Christian wrote Hi, what is the error/exception message? Regards, Christian MissingTokenException at the second '=', after parsing a=b.c as an expression. The tail recursion on expr is causing it it seems, but that's a real issue for me... here is a slightly modified version with

[il-antlr-interest: 35040] Re: [antlr-interest] Confused about backtracking

2011-11-28 Thread Christian
Mh, I am with you. I also do not understand backtracking in this situation ;) Could anyone else explain it, please? Am 28.11.2011 15:18, schrieb franck102: Christian wrote Hi, what is the error/exception message? Regards, Christian MissingTokenException at the second '=', after parsing

[il-antlr-interest: 35042] Re: [antlr-interest] Confused about backtracking

2011-11-28 Thread Kirby Bohling
On Mon, Nov 28, 2011 at 9:02 AM, Christian chw...@gmx.de wrote: Mh, I am with you. I also do not understand backtracking in this situation ;) Could anyone else explain it, please? Pretty sure you are having problems because you have '.' as an inline/generated token in your rules. I've said

[il-antlr-interest: 35044] Re: [antlr-interest] Confused about backtracking

2011-11-28 Thread Terence Parr
expr : ID suffix; will try to match the sep '.'. backtrack takes first alt that wins and the decision for suffix needs to backtrack due to your program rule. therefore it attempts '.' expr and fails. allowing …… as a program is not a good idea ;) T On Nov 26, 2011, at 4:21

[il-antlr-interest: 35045] Re: [antlr-interest] Tree building limitation in tree grammars?

2011-11-28 Thread John B. Brodie
Greetings! On 11/28/2011 08:08 AM, franck102 wrote: My parser grammar can generate a number of subtrees with similar structure, and just a different root type. In the tree grammar I am trying to just pass such a subtree along without any changes, but that is turning out to be much trickier

[il-antlr-interest: 35046] Re: [antlr-interest] Confused about backtracking

2011-11-28 Thread Jim Idle
Try turning backtrack mode off and see what ANTLR says about your production. This will give you the clue that you need. You probably need to add an explicit predicate. Clearly, you rules below are ambiguous on the '.' as it is a separator. So it thinks you are parsing ID '.' as a statement. The

[il-antlr-interest: 35047] Re: [antlr-interest] Confused about backtracking

2011-11-28 Thread Jim Idle
This answer is incorrect - the '.' will be the same token. See my earlier answer. Jim -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest- boun...@antlr.org] On Behalf Of Kirby Bohling Sent: Monday, November 28, 2011 8:18 AM To: Christian Cc:

[il-antlr-interest: 35049] Re: [antlr-interest] Confused about backtracking

2011-11-28 Thread franck102
None of those suggestion will help with the actual grammar unfortunately. It is indeed ambiguous, that is the warning I get if I turn backtracking off, but I can't refactor the rules (or the actual, large grammar) w/o ending with a completely meaningless AST. I still don't understand why antlr

[il-antlr-interest: 35051] Re: [antlr-interest] Tree building limitation in tree grammars?

2011-11-28 Thread franck102
Thanks John, I had tried the first one (using a label assigned in each branch of the alternative), I just posted it wrong. Your 2nd 3rd suggestions should work I expect, thanks! Too bad the most natural one ^( ( AND | OR ) ... w/o rewrite doesn't work... -- View this message in context: