Exemplo n.º 1
0
/* FIRST(statement)={AVID,SVID,IF,USING,INPUT,OUTPUT}
<statement> ->
	<assignment statement>
	| <selection statement> 
	| <iteration statement> 
	| <input statement>
	| <output statement>
Author: Kwok Hong Kelvin Chan */
void statement(void){
	switch(lookahead_token.code){
		case AVID_T:
		case SVID_T:
			assignment_statement();
			break;
		case KW_T:
			switch(lookahead_token.attribute.get_int) {
			case IF:
				selection_statement();
				break;
			case USING:
				iteration_statement();
				break;
			case INPUT:
				input_statement();
				break;
			case OUTPUT:
				output_statement();
				break;
			default:
				syn_printe();
				break;
			}
			break;
		default:
			syn_printe();
			break;
	}
}
Exemplo n.º 2
0
/*
 * Production: Statement
 * FIRST set: { AVID_T, SVID_T, KW_T (only IF, USING, INPUT, OUTPUT) }
 */
void statement(void) {
    switch (lookahead.code) {
        case AVID_T:
        case SVID_T:
            assignment_statement();
            return;
        
        case KW_T:
            /* The token attribute must be IF, INPut, OUTPUT or USING */
            switch (lookahead.attribute.kwt_idx) {
                case IF:
                    selection_statement();
                    return;
                
                case INPUT:
                    input_statement();
                    return;
                
                case OUTPUT:
                    output_statement();
                    return;
                
                case USING:
                    iteration_statement();
                    return;
                
                /* If the keyword token does not match the above, print an error and return. */
                default:
                    syn_printe();
                    return;
            }
        
        /* If nothing matches, print an error. */
        default:
            syn_printe();
            return;
    }
}
Exemplo n.º 3
0
void SyntaxAnalyzer::S()
{
	if ((cur->type == keyword)&&
		(strcmp(cur->lex, "end")!=0)) {
		if (strcmp(cur->lex, "if")==0) {
			next();
			if_statement();
			S();
		}
		else
		if (strcmp(cur->lex, "while")==0) {
			next();
			while_statement();
			S();
		}
		else
		if (strcmp(cur->lex, "goto")==0) {
			next();
			goto_statement();
			PolizOpGo* tmp = new PolizOpGo;
			add_poliz_list(tmp);
			S();
		}
		else
		if (strcmp(cur->lex, "print")==0) {
			next();
			print_statement();
			PolizPrint* tmp = new PolizPrint;
			add_poliz_list(tmp);
			S();
		}
		else
		if (strcmp(cur->lex, "then")!=0) {
			game_statement();
			S();
		}
		else
			throw Exeption("unexpected then", cur->num_str, cur->lex);
	}
	else
	if (cur->type == variable) {
		make_poliz_var();
		next();
		assignment_statement();
		PolizFunAssign* tmp = new PolizFunAssign;
		add_poliz_list(tmp);
		S();
	}
	else
	if (cur->type == label) {
		make_poliz_label();
		next();
		if (strcmp(cur->lex, ">")!=0)
			throw Exeption("'>' expected", cur->num_str, cur->lex);
		next();
		S();
	}
	else {
	if (strcmp(cur->lex, "end")!=0)
		throw Exeption("end expected", cur->num_str, cur->lex);
	else
		next();
	}
}