fixed parsing explicit references in the body of control structures

actorid
Marc Zinnschlag 15 years ago
parent 147dd57162
commit 044bf0ab48

@ -172,6 +172,20 @@ namespace Compiler
std::copy (mCode.begin(), mCode.end(), std::back_inserter (code)); 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) bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{ {
if (mState==StartState) if (mState==StartState)

@ -13,9 +13,9 @@ namespace Compiler
{ {
class Locals; class Locals;
class Literals; class Literals;
// Control structure parser // Control structure parser
class ControlParser : public Parser class ControlParser : public Parser
{ {
enum State enum State
@ -28,31 +28,36 @@ namespace Compiler
WhileEndState, WhileBodyState, WhileEndState, WhileBodyState,
WhileEndwhileState WhileEndwhileState
}; };
typedef std::vector<Interpreter::Type_Code> Codes; typedef std::vector<Interpreter::Type_Code> Codes;
typedef std::vector<std::pair<Codes, Codes> > IfCodes; typedef std::vector<std::pair<Codes, Codes> > IfCodes;
Locals& mLocals; Locals& mLocals;
Literals& mLiterals; Literals& mLiterals;
Codes mCode; Codes mCode;
Codes mCodeBlock; Codes mCodeBlock;
IfCodes mIfCode; // condition, body IfCodes mIfCode; // condition, body
LineParser mLineParser; LineParser mLineParser;
ExprParser mExprParser; ExprParser mExprParser;
State mState; State mState;
bool parseIfBody (int keyword, const TokenLoc& loc, Scanner& scanner); bool parseIfBody (int keyword, const TokenLoc& loc, Scanner& scanner);
bool parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner); bool parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner);
public: public:
ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals, ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
Literals& literals); Literals& literals);
void appendCode (std::vector<Interpreter::Type_Code>& code) const; void appendCode (std::vector<Interpreter::Type_Code>& code) const;
///< store generated code in \æ code. ///< 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); virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
///< Handle a keyword token. ///< Handle a keyword token.
/// \return fetch another token? /// \return fetch another token?
@ -67,4 +72,3 @@ namespace Compiler
} }
#endif #endif

@ -183,6 +183,13 @@ namespace Compiler
return true; return true;
} }
if (mState==BeginState && getContext().isId (name))
{
mState = PotentialExplicitState;
mExplicit = toLower (name);
return true;
}
if (mState==BeginState && mAllowExpression) if (mState==BeginState && mAllowExpression)
{ {
std::string name2 = toLower (name); 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); return Parser::parseName (name, loc, scanner);
} }

Loading…
Cancel
Save