Esempio n. 1
0
IntegerNode * ParserClass::Integer() {
    TokenClass tc = Match(INTEGER_TOKEN);
    string s = tc.GetLexeme();
    const char *c = s.c_str();
    IntegerNode *i = new IntegerNode(atoi(c));
    return i;
}
Esempio n. 2
0
// Verify that the next token in the input file is of the same type
// that the parser expects.
TokenClass ParserClass::Match(TokenType expectedType)
{
	TokenClass currentToken = this->mScanner->GetNextToken();
	if (currentToken.GetTokenType() != expectedType)
	{
		std::cerr << "Error in ParserClass::Match. " << std::endl;
		std::cerr << "Expected token type " <<
			TokenClass::GetTokenTypeName(expectedType) <<
			", but got type " << currentToken.GetTokenTypeName() <<
			std::endl;
		exit(1);
	}
	MSG("\tSuccessfully matched Token Type: " << currentToken.GetTokenTypeName() << ". Lexeme: \"" <<
		currentToken.GetLexeme() << "\"");
	return currentToken; // the one we just processed
}
Esempio n. 3
0
IdentifierNode * ParserClass::Identifier() {
    TokenClass token = Match(IDENTIFIER_TOKEN);
    IdentifierNode *in = new IdentifierNode(token.GetLexeme(), mSymbolTable);
    return in;
}
Esempio n. 4
0
IntegerNode * ParserClass::Integer()
{
	TokenClass token = this->Match(INTEGER_TOKEN);
	IntegerNode * in = new IntegerNode(std::atoi(token.GetLexeme().c_str()));
	return in;
}