|
|
@ -3,54 +3,90 @@
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
#include "tokenloc.hpp"
|
|
|
|
#include "tokenloc.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "scanner.hpp"
|
|
|
|
#include "scanner.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
namespace Compiler
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FileParser::FileParser (ErrorHandler& errorHandler, Context& context)
|
|
|
|
FileParser::FileParser (ErrorHandler& errorHandler, Context& context)
|
|
|
|
: Parser (errorHandler, context)
|
|
|
|
: Parser (errorHandler, context), mState (BeginState)
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
bool FileParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
std::string FileParser::getName() const
|
|
|
|
{
|
|
|
|
|
|
|
|
std::cout << "integer: " << value << std::endl;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool FileParser::parseFloat (float value, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "float: " << value << std::endl;
|
|
|
|
return mName;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FileParser::parseName (const std::string& name, const TokenLoc& loc,
|
|
|
|
bool FileParser::parseName (const std::string& name, const TokenLoc& loc,
|
|
|
|
Scanner& scanner)
|
|
|
|
Scanner& scanner)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "name: " << name << std::endl;
|
|
|
|
if (mState==NameState)
|
|
|
|
return true;
|
|
|
|
{
|
|
|
|
|
|
|
|
mName = name;
|
|
|
|
|
|
|
|
mState = BeginCompleteState;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mState==EndNameState)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// optional repeated name after end statement
|
|
|
|
|
|
|
|
if (mName!=name)
|
|
|
|
|
|
|
|
reportWarning ("Names for script " + mName + " do not match", loc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mState = EndCompleteState;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Parser::parseName (name, loc, scanner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FileParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
bool FileParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "keyword: " << loc.mLiteral << std::endl;
|
|
|
|
if (mState==BeginState && keyword==Scanner::K_begin)
|
|
|
|
return true;
|
|
|
|
{
|
|
|
|
|
|
|
|
mState = NameState;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mState==EndState && keyword==Scanner::K_end)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mState = EndNameState;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Parser::parseKeyword (keyword, loc, scanner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FileParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
bool FileParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (code==Scanner::S_newline)
|
|
|
|
if (code==Scanner::S_newline)
|
|
|
|
std::cout << "newline" << std::endl;
|
|
|
|
{
|
|
|
|
else
|
|
|
|
if (mState==BeginCompleteState)
|
|
|
|
std::cout << "special: " << loc.mLiteral << std::endl;
|
|
|
|
{
|
|
|
|
|
|
|
|
// TODO: add script parser here
|
|
|
|
|
|
|
|
mState = EndState;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
if (mState==EndCompleteState || mState==EndNameState)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// we are done here -> ignore the rest of the script
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Parser::parseSpecial (code, loc, scanner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FileParser::parseEOF (Scanner& scanner)
|
|
|
|
void FileParser::parseEOF (Scanner& scanner)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::cout << "end of file" << std::endl;
|
|
|
|
if (mState!=EndNameState && mState!=EndCompleteState)
|
|
|
|
|
|
|
|
Parser::parseEOF (scanner);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FileParser::reset()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mState = BeginState;
|
|
|
|
|
|
|
|
mName.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|