Exemple #1
0
void FParser::RunStatement()
{
	if(TokenType[0] == function)
    {
		if(!strcmp(Tokens[0], "if"))
		{
			Script->lastiftrue = spec_if();
			return;
		}
		else if(!strcmp(Tokens[0], "elseif"))
		{
			if(!PrevSection || 
				(PrevSection->type != st_if && 
				PrevSection->type != st_elseif))
			{
				script_error("elseif statement without if\n");
				return;
			}
			Script->lastiftrue = spec_elseif(Script->lastiftrue);
			return;
		}
		else if(!strcmp(Tokens[0], "else"))
		{
			if(!PrevSection ||
				(PrevSection->type != st_if &&
				PrevSection->type != st_elseif))
			{
				script_error("else statement without if\n");
				return;
			}
			spec_else(Script->lastiftrue);
			Script->lastiftrue = true;
			return;
		}
		else if(!strcmp(Tokens[0], "while"))
		{
			spec_while();
			return;
		}
		else if(!strcmp(Tokens[0], "for"))
		{
			spec_for();
			return;
		}
    }
	else if(TokenType[0] == name_)
    {
		// NB: goto is a function so is not here

		// Allow else without '()'
        if (!strcmp(Tokens[0], "else"))
        {
			if(!PrevSection ||
				(PrevSection->type != st_if &&
				PrevSection->type != st_elseif))
			{
				script_error("else statement without if\n");
				return;
			}
			spec_else(Script->lastiftrue);
			Script->lastiftrue = true;
			return;
        }

		// if a variable declaration, return now
		if(spec_variable()) return;
    }
	
	// just a plain expression
	svalue_t scratch;
	EvaluateExpression(scratch,0, NumTokens-1);
}
void run_statement()
{
	// decide what to do with it
	
	// NB this stuff is a bit hardcoded:
	//    it could be nicer really but i'm
	//    aiming for speed
	
	// if() and while() will be mistaken for functions
	// during token processing
	if(tokentype[0] == function)
    {
		if(!strcmp(tokens[0], "if"))
		{
			current_script->lastiftrue = spec_if();
			return;
		}
		else if(!strcmp(tokens[0], "elseif"))
		{
			if(!prev_section || 
				(prev_section->type != st_if && 
				prev_section->type != st_elseif))
			{
				script_error("elseif statement without if\n");
				return;
			}
			current_script->lastiftrue = 
				spec_elseif(current_script->lastiftrue);
			return;
		}
		else if(!strcmp(tokens[0], "else"))
		{
			if(!prev_section ||
				(prev_section->type != st_if &&
				prev_section->type != st_elseif))
			{
				script_error("else statement without if\n");
				return;
			}
			spec_else(current_script->lastiftrue);
			current_script->lastiftrue = true;
			return;
		}
		else if(!strcmp(tokens[0], "while"))
		{
			spec_while();
			return;
		}
		else if(!strcmp(tokens[0], "for"))
		{
			spec_for();
			return;
		}
    }
	else if(tokentype[0] == name_)
    {
		// NB: goto is a function so is not here

		// Allow else without '()'
        if (!strcmp(tokens[0], "else"))
        {
			if(!prev_section ||
				(prev_section->type != st_if &&
				prev_section->type != st_elseif))
			{
				script_error("else statement without if\n");
				return;
			}
			spec_else(current_script->lastiftrue);
			current_script->lastiftrue = true;
			return;
        }

		// if a variable declaration, return now
		if(spec_variable()) return;
    }
	
	// just a plain expression
	evaluate_expression(0, num_tokens-1);
}