[antlr-interest] My parser hangs in an infinite loop on certa in inputs

mzukowski at yci.com mzukowski at yci.com
Tue Sep 9 08:26:43 PDT 2003


Don't mix automatic tree building with manual tree building.  Your node
#occur has been automatically built with #val as the sibling already.
Remember, it is a tree, not just a node, unless you turn tree building off
for the whole rule.  So adding #val as the sibling of the tree #occur is
really adding #val to #val causing an infinite loop.  

Possible solutions, I recommend the first as the most common and clearest
code:

Common idiom using "##" shorthand for "current root":

quantified_multiset_expr
   :   expression D_COLON! expression
       { #quantified_multiset_expr = #([QUANT_MSET_EXPR,
"quant_mset_expr"],##); };


Identical but explicitly naming root for the rule:
quantified_multiset_expr
   :   expression D_COLON! expression
       { #quantified_multiset_expr = #([QUANT_MSET_EXPR,
"quant_mset_expr"],#quantified_multiset_expr); };

Turning off tree building for the rule:

quantified_multiset_expr!
   :   occur:expression D_COLON val:expression
       { #quantified_multiset_expr = #([QUANT_MSET_EXPR,
"quant_mset_expr"],#occur,#val); };

Monty

-----Original Message-----
From: Matt Lowry [mailto:mclowry at cs.adelaide.edu.au] 
Sent: Monday, September 08, 2003 10:51 PM
To: ANTLR
Subject: [antlr-interest] My parser hangs in an infinite loop on certain
inputs
...

quantified_multiset_expr
   :   occur:expression D_COLON! val:expression
       { #quantified_multiset_expr = #([QUANT_MSET_EXPR,
"quant_mset_expr"],#occur,#val); }; // ACK! BLECH!

....

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list