示例#1
0
int Parser::getBranchInstructionNameNumber(string token){
	unordered_map<string, int>::iterator iter = BranchInstructionNameMap.find(token);
	if(iter != BranchInstructionNameMap.end()){
		return (*iter).second;
	}else{
		throw InvalidTokenException("Branch instruction name", token);
	}
	return 0;
}
示例#2
0
int Parser::getFPRegisterIndex(string token){
	unordered_map<string, int>::iterator iter = FPRegisterNameMap.find(token);
	if(iter != FPRegisterNameMap.end()){
		return (*iter).second;
	}else{
		throw InvalidTokenException("Floating point register name", token);
	}
	return 0;
}
示例#3
0
int Parser::getRegisterIndex(string token){
	if(tokenIsGPRegister(token)){
		return getGPRegisterIndex(token);
	}else if(tokenIsFPRegister(token)){
		return getFPRegisterIndex(token);
	}
	throw InvalidTokenException("Register name", token);
	return 0;
}
示例#4
0
virtualAddr Assembler::getLabelAddress(string label){
	unordered_map<string, virtualAddr>::iterator iter = labelMap.find(label);
	if(iter != labelMap.end()){
		return (*iter).second;
	}else{
		//EXCEPTION
		throw InvalidTokenException("Label", label);
	}
	return 0;
}
示例#5
0
int Parser::getArgumentValue(string argument){
	argument = removeNestedParentheses(argument);
	if(tokenIsRegister(argument)){
		return getRegisterIndex(argument);
	}else if(literals.tokenIsFixedPointLiteral(argument)){
		return literals.getLiteralValue(argument);
	}
	throw InvalidTokenException("Instruction argument", argument);
	return 0;
}
示例#6
0
void Expression::allocateVariables(OperationCode *opcode, Parser* parser) {
	for (list<ExpressionTerm*>::iterator it=postfix.begin(); it!=postfix.end(); it++) {
			Token *token = (*it)->token;
			if (token && (token->aType & Token::OPERATOR) == 0) {
				expressionVars[*it] = setVariable(parser, "");
			}
	}

	for (map<ExpressionTerm*,uint>::iterator it=expressionVars.begin(); it != expressionVars.end(); it++) {
			if (!it->first->token) continue;

			Token *token = it->first->token;

			allocateVariable(opcode, it->second);

			if (token->aType == Token::VARIABLE_FUNCTION) {
				// Copy the original variable into our new one
				opcode->addInterop(new ByteOperation(OP_MOV));

				uint src = getVariableID(parser, token->token);

				opcode->addInterop(new DwordOperation(&it->second));
				opcode->addInterop(new DwordOperation(&src));
			} else {
				// The value to be copied is a numerical value.
				byte operation = 0;
				void *dword = malloc(4);

				if (it->first->token->aType == Token::VARIABLE_INT) {
					operation = OP_MOVI;
					*(int*)dword = atoi(token->token.c_str());
				} else if (token->aType == Token::VARIABLE_FLOAT) {
					operation = OP_MOVF;
					*(float*)dword = (float)atof(token->token.c_str());
				} else {
					throw InvalidTokenException("Invalid token expression of type");
				}

				opcode->addInterop(new ByteOperation(operation));
				opcode->addInterop(new DwordOperation(&it->second));
				opcode->addInterop(new DwordOperation(dword));

				free(dword);
			}
	}
}
示例#7
0
		Field CreateTable::parseField(Lexer& lex)
		{
			Field res;
			res.size = 0;
			Token t;

			// <columnName>
			t = lex.NextToken(TokenType::Identifier, false);
			
			if (t.strData.size() >= STORM_SQL_FIELD_NAME_SIZE)
				throw NameTooLong();

			strcpy(res.name, t.strData.c_str());

			// <columnType>
			t = lex.NextToken(TokenType::Keyword);

			if (t.strData == "byte")
				res.type = Field::FieldType::byte;
			else if (t.strData == "int")
				res.type = Field::FieldType::int32;
			else if (t.strData == "uint")
				res.type = Field::FieldType::uint32;
			else if (t.strData == "char")
			{
				res.type = Field::FieldType::fixedchar;

				// (<length>)
				lex.NextToken("(", TokenType::Parenthesis);
				t = lex.NextToken(TokenType::IntValue);
				lex.NextToken(")", TokenType::Parenthesis);

				res.size = t.longIntData;
			}
			else
				throw InvalidTokenException(t);

			return res;
		}
示例#8
0
void Expression::buildPostfix(Tokens *tokens, Parser *parser) {
	Stack<Token*> stack;

	int paranthCnt = 0;
	const Token *next = tokens->checkNext();
	while (tokens->isMore() && next->aType != Token::SEMICOLON && next->aType != Token::COMMA) {

			if (next->aType == Token::VARIABLE_INT || next->aType == Token::VARIABLE_FLOAT) {
				postfix.push_back(new ExpressionTerm(tokens->popNext()));
			} else if (next->aType == Token::VARIABLE_FUNCTION) {
				Token *token = tokens->popNext();

				// Function call
				if (tokens->checkNext()->aType == Token::PARANTH_BEG) {
					FunctionCall *func = new FunctionCall(token);
					func->parseFragment(tokens, parser);
					postfix.push_back(new ExpressionTerm(func));
				} else {
					postfix.push_back(new ExpressionTerm(token));
				}
			} else if (next->aType & Token::OPERATOR) {
				Token *token = tokens->popNext();

				while (stack.Size() && stack.peek()->aType != Token::PARANTH_BEG) {
					if (operatorPrecedence(stack.peek()) > operatorPrecedence(token)) {
						postfix.push_back(new ExpressionTerm(stack.pop()));
					} else {
						break;
					}
				}

				stack.push(token);
			} else if (next->aType == Token::PARANTH_BEG) {
				paranthCnt++;
				stack.push(tokens->popNext());
			} else if (next->aType == Token::PARANTH_END) {
				paranthCnt--;
				if (paranthCnt < 0) break;

				while (stack.Size() && stack.peek()->aType != Token::PARANTH_BEG) {
					postfix.push_back(new ExpressionTerm(stack.pop()));
				}

				// Pop the "("
				stack.pop();

				// Pop the ")"
				tokens->popNext();
			} else {
				throw InvalidTokenException("Unexpected token: " + next->token);
			}

			next = tokens->checkNext();
	}

	while (stack.Size()) {
		postfix.push_back(new ExpressionTerm(stack.pop()));
	}

	if (!isParam) {
		delete tokens->popExpected(Token::SEMICOLON);
	}
}