[antlr-interest] Double Left Recursion Update: Test case with working "double left recursion"

Sam Harwell sam at tunnelvisionlabs.com
Wed Feb 29 10:20:33 PST 2012


Hi Jan,

Why not simply change the result rule to the following?

result : expr+ EOF;

I go into more detail in comments on the following issue on github:
https://github.com/antlr/antlr4/issues/26

--
Sam Harwell
Owner, Lead Developer
http://tunnelvisionlabs.com


-----Original Message-----
From: Jan Finis [mailto:finis at in.tum.de] 
Sent: Tuesday, February 28, 2012 8:12 AM
To: Terence Parr
Cc: antlr-interest at antlr.org
Subject: [antlr-interest] Double Left Recursion Update: Test case with
working "double left recursion"

Hi again,

as I mentioned in my last mail, I think that the problem with rules of the
form

expr : expr expr;

is solvable because old Honey Badger was able to match them. I tried again
and could confirm this. This grammar:


result : expr { System.out.println($expr.s); } EOF;

expr returns [String s]
	: 'x' { $s = "x"; }
	| e1=expr '?' { $s = $e1.s + "?"; }
	| e1=expr e2=expr { $s = "(" + $e1.s + " " + $e2.s + ")"; }
	;


parses correctly with an older 4.0ea version. I have uploaded this 
version here:
http://www-db.in.tum.de/~finis/antlr-4.0ea-complete-old.jar/

It does not only parse correctly, even the resulting parser is really 
able to match input without descending into a looping recursion.

I tested the resulting parser on the following input:

xxxxx?xx?xx


and the result was:

(x (x (x (x (x? (x (x? (x x))))))))

so the concatenation operation seems to be right associative, but it 
works perfectly fine :).

Best regards,
Jan


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list