From 044bf0ab4871b9631eb3ecf0284eb50518fcf20a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 30 Aug 2010 14:44:23 +0200 Subject: [PATCH] fixed parsing explicit references in the body of control structures --- components/compiler/controlparser.cpp | 14 ++++++++++++++ components/compiler/controlparser.hpp | 24 ++++++++++++++---------- components/compiler/lineparser.cpp | 14 +++++++------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/components/compiler/controlparser.cpp b/components/compiler/controlparser.cpp index 2f5d5c4b6..c255154b5 100644 --- a/components/compiler/controlparser.cpp +++ b/components/compiler/controlparser.cpp @@ -172,6 +172,20 @@ namespace Compiler std::copy (mCode.begin(), mCode.end(), std::back_inserter (code)); } + bool ControlParser::parseName (const std::string& name, const TokenLoc& loc, Scanner& scanner) + { + if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState || + mState==WhileBodyState) + { + scanner.putbackName (name, loc); + mLineParser.reset(); + scanner.scan (mLineParser); + return true; + } + + return Parser::parseName (name, loc, scanner); + } + bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner) { if (mState==StartState) diff --git a/components/compiler/controlparser.hpp b/components/compiler/controlparser.hpp index 17b3137c7..50fd2d1f9 100644 --- a/components/compiler/controlparser.hpp +++ b/components/compiler/controlparser.hpp @@ -13,9 +13,9 @@ namespace Compiler { class Locals; class Literals; - + // Control structure parser - + class ControlParser : public Parser { enum State @@ -28,31 +28,36 @@ namespace Compiler WhileEndState, WhileBodyState, WhileEndwhileState }; - + typedef std::vector Codes; typedef std::vector > IfCodes; - - Locals& mLocals; - Literals& mLiterals; + + Locals& mLocals; + Literals& mLiterals; Codes mCode; Codes mCodeBlock; IfCodes mIfCode; // condition, body LineParser mLineParser; ExprParser mExprParser; State mState; - + bool parseIfBody (int keyword, const TokenLoc& loc, Scanner& scanner); bool parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner); - + public: - + ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals, Literals& literals); void appendCode (std::vector& code) const; ///< store generated code in \æ code. + virtual bool parseName (const std::string& name, const TokenLoc& loc, + Scanner& scanner); + ///< Handle a name token. + /// \return fetch another token? + virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner); ///< Handle a keyword token. /// \return fetch another token? @@ -67,4 +72,3 @@ namespace Compiler } #endif - diff --git a/components/compiler/lineparser.cpp b/components/compiler/lineparser.cpp index 3f80d671e..5462f7788 100644 --- a/components/compiler/lineparser.cpp +++ b/components/compiler/lineparser.cpp @@ -183,6 +183,13 @@ namespace Compiler return true; } + if (mState==BeginState && getContext().isId (name)) + { + mState = PotentialExplicitState; + mExplicit = toLower (name); + return true; + } + if (mState==BeginState && mAllowExpression) { std::string name2 = toLower (name); @@ -206,13 +213,6 @@ namespace Compiler } } - if (mState==BeginState && getContext().isId (name)) - { - mState = PotentialExplicitState; - mExplicit = toLower (name); - return true; - } - return Parser::parseName (name, loc, scanner); }