|
|
|
@ -10,43 +10,7 @@
|
|
|
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
|
{
|
|
|
|
|
ControlParser::ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
|
|
|
|
|
Literals& literals)
|
|
|
|
|
: Parser (errorHandler, context), mLocals (locals), mLiterals (literals),
|
|
|
|
|
mLineParser (errorHandler, context, locals, literals, mCodeBlock),
|
|
|
|
|
mExprParser (errorHandler, context, locals, literals),
|
|
|
|
|
mState (StartState)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlParser::appendCode (std::vector<Interpreter::Type_Code>& code) const
|
|
|
|
|
{
|
|
|
|
|
std::copy (mCode.begin(), mCode.end(), std::back_inserter (code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
|
{
|
|
|
|
|
if (mState==StartState)
|
|
|
|
|
{
|
|
|
|
|
if (keyword==Scanner::K_if)
|
|
|
|
|
{
|
|
|
|
|
mExprParser.reset();
|
|
|
|
|
scanner.scan (mExprParser);
|
|
|
|
|
|
|
|
|
|
mState = IfEndState;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (keyword==Scanner::K_while)
|
|
|
|
|
{
|
|
|
|
|
mExprParser.reset();
|
|
|
|
|
scanner.scan (mExprParser);
|
|
|
|
|
|
|
|
|
|
mState = WhileEndState;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState)
|
|
|
|
|
bool ControlParser::parseIfBody (int keyword, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
|
{
|
|
|
|
|
if (keyword==Scanner::K_endif || keyword==Scanner::K_elseif ||
|
|
|
|
|
keyword==Scanner::K_else)
|
|
|
|
@ -131,8 +95,11 @@ namespace Compiler
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (mState==WhileBodyState)
|
|
|
|
|
|
|
|
|
|
bool ControlParser::parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
|
{
|
|
|
|
|
if (keyword==Scanner::K_endwhile)
|
|
|
|
|
{
|
|
|
|
@ -186,6 +153,55 @@ namespace Compiler
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ControlParser::ControlParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
|
|
|
|
|
Literals& literals)
|
|
|
|
|
: Parser (errorHandler, context), mLocals (locals), mLiterals (literals),
|
|
|
|
|
mLineParser (errorHandler, context, locals, literals, mCodeBlock),
|
|
|
|
|
mExprParser (errorHandler, context, locals, literals),
|
|
|
|
|
mState (StartState)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ControlParser::appendCode (std::vector<Interpreter::Type_Code>& code) const
|
|
|
|
|
{
|
|
|
|
|
std::copy (mCode.begin(), mCode.end(), std::back_inserter (code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
|
{
|
|
|
|
|
if (mState==StartState)
|
|
|
|
|
{
|
|
|
|
|
if (keyword==Scanner::K_if)
|
|
|
|
|
{
|
|
|
|
|
mExprParser.reset();
|
|
|
|
|
scanner.scan (mExprParser);
|
|
|
|
|
|
|
|
|
|
mState = IfEndState;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (keyword==Scanner::K_while)
|
|
|
|
|
{
|
|
|
|
|
mExprParser.reset();
|
|
|
|
|
scanner.scan (mExprParser);
|
|
|
|
|
|
|
|
|
|
mState = WhileEndState;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState)
|
|
|
|
|
{
|
|
|
|
|
if (parseIfBody (keyword, loc, scanner))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (mState==WhileBodyState)
|
|
|
|
|
{
|
|
|
|
|
if ( parseWhileBody (keyword, loc, scanner))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Parser::parseKeyword (keyword, loc, scanner);
|
|
|
|
|