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));
}
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)

@ -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<Interpreter::Type_Code> Codes;
typedef std::vector<std::pair<Codes, Codes> > 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<Interpreter::Type_Code>& 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

@ -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);
}

Loading…
Cancel
Save