示例#1
0
文件: syntax.c 项目: ptigas/ciscal
void statement(LIST *S, int level) {
	LIST *list;
	ATTR *E = (ATTR*)malloc(sizeof(ATTR));
	debug(level,"STATEMENT");
	if(token == ID) {
		assignment_stat(S, level+1);
	} else if(token == TK_IF) {
		if_stat(S, level+1);
		backpatch(S, int2string(nextquad()));
	} else if(token == TK_DO) {
		while_stat(S, level+1);
		S->next = NULL;
	} else if(token == TK_EXIT) {
		exit_stat(level+1);
		list = makelist(int2string(nextquad()));
		list->exitflag = 1;
		genquad("jump", "_", "_", "_");
		S->next = merge(S->next, list);
	} else if(token == TK_RETURN) {
		return_stat(E, level+1);
		S->next = NULL;
	} else if(token == TK_PRINT) {
		print_stat(level+1);
		S->next = NULL;
	} else if(token == TK_CALL) {
		call_stat(level+1);
		S->next = NULL;
	} else {
		S->next = NULL;
	}
}
示例#2
0
int statement()
{
	int es = 0;
	if (es == 0 && strcmp(token, "if") == 0) es = if_stat();//<IF语句>
	if (es == 0 && strcmp(token, "while") == 0) es = while_stat();//<while语句>
	if (es == 0 && strcmp(token, "for") == 0) es = for_stat();//<for语句>
	//可在此处添加do语句调用
	if (es == 0 && strcmp(token, "read") == 0) es = read_stat();//<read语句>
	if (es == 0 && strcmp(token, "write") == 0) es = write_stat();//<write语句>
	if (es == 0 && strcmp(token, "{") == 0) es = compound_stat();//<复合语句>
	if (es == 0 && (strcmp(token, "ID") == 0 || strcmp(token, "NUM") == 0 || strcmp(token, "(") == 0)) es = expression_stat();//<表达式语句>
	return(es);
}
示例#3
0
void stat(){
	if (lookahead == INTEGER || lookahead == STRING || lookahead == BOOLEAN || lookahead == TABLE)
		def_stat();
	else if (lookahead == ID)
		assign_stat();
	else if (lookahead == IF)
		if_stat();
	else if (lookahead == WHILE)
		while_stat();
	else if (lookahead == READ)
		read_stat();
	else //(lookahead == WRITE)
		write_stat();
}
示例#4
0
文件: stat.c 项目: bonfa/compilatori
/*Genera il codice per il nodo stat_list e crea lo scope del programma*/
Code stat_list(Pnode stat_list_node){
	//Definisco la variabile che contiene il codice da ritornare
	Code stat_list_code;
	stat_list_code.head = NULL;
	stat_list_code.tail = NULL;
	stat_list_code.size = 0;

	//Creo l'ambiente del programma
	push_environment();
	
	//Punto al primo stat
	Pnode stat_node = stat_list_node->child;
	//Ciclo lungo tutti gli stat_node
	while (stat_node!=NULL){
		//Creo il codice dello stat_node
		Code stat_code;
		switch (stat_node->type){
			case(N_DEF_STAT): 	stat_code = def_stat(stat_node);break;
			case(N_ASSIGN_STAT): 	stat_code = assign_stat(stat_node);break;
			case(N_IF_STAT): 	stat_code = if_stat(stat_node);break;
			case(N_WHILE_STAT): 	stat_code = while_stat(stat_node);break;
			case(N_READ_STAT): 	stat_code = read_stat(stat_node);break;
			case(N_WRITE_STAT): 	stat_code = write_stat(stat_node);break;
		}
		
		//Appendo il codice a stat_list_code
		stat_list_code = appcode(stat_list_code,stat_code);

		//Punto al fratello successivo
		stat_node = stat_node->brother;
	}
	
	//Appendo il codice per fare il pop dell'environment a stat_list_code
	if(numobj_in_current_env()!=0)
		stat_list_code = appcode(stat_list_code,makecode1(T_POP,numobj_in_current_env()));

	//elimino l'ambiente creato (elimina già le variabili dall'ambiente)
	pop_environment();

	return stat_list_code;
}
示例#5
0
Code stat(Pnode p)
{
    switch (p->type)
    {
        case N_DEF_STAT:
            return def_stat(p);
        case N_ASSIGN_STAT:
            return assign_stat(p);
        case N_IF_STAT:
            return if_stat(p);
        case N_WHILE_STAT:
            return while_stat(p);
        case N_READ_STAT:
            return read_stat(p);
        case N_WRITE_STAT:
            return write_stat(p);
        default:
            noderror(p);
    }
    return endcode();
}