From d4982926803b98185473b7255e145302909bf27f Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Thu, 6 Feb 2014 20:46:32 -0600 Subject: [PATCH] Add regression test for issue #461 (interpreter starting with LR rule) --- .../antlr/v4/test/TestParserInterpreter.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tool/test/org/antlr/v4/test/TestParserInterpreter.java b/tool/test/org/antlr/v4/test/TestParserInterpreter.java index 88d3ce6c3..0542b5378 100644 --- a/tool/test/org/antlr/v4/test/TestParserInterpreter.java +++ b/tool/test/org/antlr/v4/test/TestParserInterpreter.java @@ -192,6 +192,35 @@ public class TestParserInterpreter extends BaseTest { testInterp(lg, g, "s", "a+a*a", "(s (e (e a) + (e (e a) * (e a))))"); } + /** + * This is a regression test for antlr/antlr4#461. + * https://github.com/antlr/antlr4/issues/461 + */ + @Test public void testLeftRecursiveStartRule() throws Exception { + LexerGrammar lg = new LexerGrammar( + "lexer grammar L;\n" + + "A : 'a' ;\n" + + "B : 'b' ;\n" + + "C : 'c' ;\n" + + "PLUS : '+' ;\n" + + "MULT : '*' ;\n"); + Grammar g = new Grammar( + "parser grammar T;\n" + + "s : e ;\n" + + "e : e MULT e\n" + + " | e PLUS e\n" + + " | A\n" + + " ;\n", + lg); + + testInterp(lg, g, "e", "a", "(e a)"); + testInterp(lg, g, "e", "a+a", "(e (e a) + (e a))"); + testInterp(lg, g, "e", "a*a", "(e (e a) * (e a))"); + testInterp(lg, g, "e", "a+a+a", "(e (e (e a) + (e a)) + (e a))"); + testInterp(lg, g, "e", "a*a+a", "(e (e (e a) * (e a)) + (e a))"); + testInterp(lg, g, "e", "a+a*a", "(e (e a) + (e (e a) * (e a)))"); + } + void testInterp(LexerGrammar lg, Grammar g, String startRule, String input, String parseTree)