Exemplo n.º 1
0
IdentifierNode * Parser::Identifier(){
	Token tt = Match(IDENTIFIER_TOKEN);
	for(int i=0; i<g_varname.size(); i++){
		if(tt.GetLexeme() == g_varname.at(i).mScope){
			g_scope = g_varname.at(i).mVal;
		}
	}
	if(g_upscope){
		g_scope++;
		scopevar s;
		s.mScope = tt.GetLexeme();
		s.mVal =  g_scope;
		g_varname.push_back(s);
	}
	IdentifierNode * idn = new IdentifierNode(tt.GetLexeme(), sym, g_scope);
	g_scope = 0;
	return idn;
}
Exemplo n.º 2
0
Token Parser::Match(TokenType expectedType){
	Token curtoken = scan->GetNextToken();
	//cout << curtoken << endl;
	if(curtoken.GetTokenType() != expectedType)
	{
		cerr << "Error in the Parse::Match.\n";
		cerr << "Expected token type "<< gTokenTypeNames[expectedType] << ", but got type " << curtoken.GetTokenTypeName() << endl;
		exit(1);
	}
	MSG("\tSuccessfully matched token type: " << curtoken.GetTokenTypeName() << ". Lexeme: \"" << curtoken.GetLexeme() << "\"");
	return curtoken;
}
Exemplo n.º 3
0
IntegerNode * Parser::Integer(){
	Token tt = Match(INTEGER_TOKEN);
	IntegerNode * itn = new IntegerNode(atoi(tt.GetLexeme().c_str()));
	return itn;
}