示例#1
0
void
execute_command(command_t c, int profiling) {
  
  switch (c->type) {
      
    case IF_COMMAND:
      execute_if(c, profiling);
      break;
    case UNTIL_COMMAND:
      execute_until(c, profiling);
      break;
    case WHILE_COMMAND:
      execute_while(c, profiling);
      break;
    case SEQUENCE_COMMAND:
      execute_sequence(c, profiling);
      break;
    case PIPE_COMMAND:
      execute_pipe(c, profiling);
      break;
    case SIMPLE_COMMAND:
      execute_simple(c, profiling);
      break;
    case SUBSHELL_COMMAND:
      execute_subshell(c, profiling);
      break;
    default:
      error (1, 0, "command not found");
  }
  
}
示例#2
0
文件: interp.c 项目: mdoug/FIAL
int FIAL_interpret (struct FIAL_exec_env *env)
{
	block *b = NULL;
	node *stmt = NULL;

	if(!env || !env->block_stack)
		return -1;
	if(!env->block_stack->stmt)
		return 1;


	for(;;) {
		b = env->block_stack;
		stmt = b->stmt->left;

		assert(stmt);
		switch(stmt->type) {
		case AST_VAR_DECL:
			ER(declare_variable(stmt, env));
			break;
		case AST_ASSIGN:
			ER(assign_variable(stmt, env));
			break;
		case AST_IF:
			ER(execute_if(stmt, env));
			break;
		case AST_BLOCK:
			ER(push_block(env, stmt));
			env->skip_advance = 1;
			break;
		case AST_CALL_A:
			ER(execute_call_A(stmt, env));
			break;
		case AST_CALL_B:
			ER(execute_call_B(stmt, env));
			break;
		case AST_BREAK:
			ER(execute_break(stmt, env));
			break;
		case AST_CONTINUE:
			ER(execute_continue(stmt, env));
			break;
		default:
			assert(0);
			/*is this an error?  I could just skip unknown
			 * statements...*/
			break;
		}
		if(!env->block_stack)
			break;
		if(env->skip_advance)
			env->skip_advance = 0;
		else
			env->block_stack->stmt = env->block_stack->stmt->right;
		while(!env->block_stack->stmt) {
			pop_block(env);
			if(!env->block_stack) {
				return 0;
			}
			assert(env->block_stack->stmt);
			env->block_stack->stmt = env->block_stack->stmt->right;
		}
	}
	return 0;
}