From 9b599597f1c16c4e185fd11d1a81ed7aa11d4191 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 25 Dec 2015 22:49:37 -0500 Subject: [PATCH] Grammar: Corrected left-recursion check --- src/Grammar.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Grammar.cpp b/src/Grammar.cpp index 7f7144b9..70b05f97 100644 --- a/src/Grammar.cpp +++ b/src/Grammar.cpp @@ -221,7 +221,8 @@ void Grammar::validate () const allTokens.push_back (token._token); if (token._token == production[0]._token && - rule.first == production[0]._token) + rule.first == production[0]._token && + production.size () == 1) allLeftRecursive.push_back (token._token); } } @@ -238,7 +239,7 @@ void Grammar::validate () const throw format ("Definition '{1}' referenced, but not defined.", nd); // Circular definitions - these are names in _rules that also appear as - // token 0 in any of the alternates for that definition. + // the only token in any of the alternates for that definition. for (auto& lr : allLeftRecursive) throw format ("Definition '{1}' is left recursive.", lr);