Пример #1
0
/* FIRST(arithmetic expression)={-,+,AVID_T,FPL_T,INL_T,(}
<arithmetic expression> - >
	<unary arithmetic expression>
	| <additive arithmetic expression>
Author: Kwok Hong Kelvin Chan */
void arithmetic_expression(void){
	switch(lookahead_token.code){
	case AVID_T:
	case FPL_T:
	case INL_T:
	case LPR_T:
		additive_arithmetic_expression();
		gen_incode("Arithmetic expression parsed");
		break;
	case ART_OP_T:
		switch(lookahead_token.attribute.arr_op){
		case MINUS:
		case PLUS:	
			unary_arithmetic_expression();
			gen_incode("Arithmetic expression parsed");
			break;
		default:
			syn_printe();
			break;
		}
		break;
	default:
		syn_printe();
		break;
	}
}
Пример #2
0
/* FIRST(output list)={variable identifier,STR_T,e}
<output list> -> 
	<variable list> | STR_T | e
Author: Kyle Hinskens */
void output_list(void) {
	switch(lookahead_token.code) {
	case STR_T:
		match(STR_T, NO_ATTR);
		gen_incode("Output list (string literal) parsed");
		break;
	case AVID_T:
	case SVID_T:
		variable_list();
		break;
	default:
		gen_incode("Output list (empty) parsed");
		break;
	}
}
Пример #3
0
/* FIRST(primary string expression={SVID_T, STR_T}
<primary string expression> -> 
		SVID_T | STR_T
Author: Kyle Hinskens */
void primary_string_expression(void){
	switch(lookahead_token.code){
		case SVID_T:
			match(SVID_T, NO_ATTR);
			gen_incode("Primary string expression parsed");
			break;
		case STR_T:
			match(STR_T, NO_ATTR);
			gen_incode("Primary string expression parsed");
			break;
		default:
			syn_printe();
			break;
	}
}
Пример #4
0
/*
 * Production: Program
 * FIRST set: { KW_T (only PLATYPUS) }
 */
void program(void) {
    match(KW_T, PLATYPUS);
    match(LBR_T,NO_ATTR);
    opt_statements();
    match(RBR_T,NO_ATTR);
    gen_incode("PLATY: Program parsed");
}
Пример #5
0
/*
 * Production: Optional Variable List
 * FIRST set: { AVID_T, SVID_T, STR_T, e }
 */
void opt_variable_list(void) {
    switch (lookahead.code) {
        case AVID_T:
        case SVID_T:
            variable_list();
            return;
            
        case STR_T:
            match(STR_T, NO_ATTR);
            gen_incode("PLATY: Output list (string literal) parsed");
            return;
        
        default:
            gen_incode("PLATY: Output list (empty) parsed");
    }
}
Пример #6
0
/*
 * Production: Arithmetic Expression
 * FIRST set: { -, +, AVID_T, FPL_T, INL_T, ( }
 */
void arithmetic_expression(void) {
    switch (lookahead.code) {
        case ART_OP_T:
            /* The attribute must be MINUS or PLUS. */
            switch (lookahead.attribute.arr_op) {
                case MINUS:
                case PLUS:
                    unary_arithmetic_expression();
                    break;
                    
                default:
                    syn_printe();
                    return;
            }
            break;
        
        case AVID_T:
        case FPL_T:
        case INL_T:
        case LPR_T:
            additive_arithmetic_expression();
            break;
        
        /* If nothing matches, print an error. */
        default:
            syn_printe();
            return;
    }
    
    gen_incode("PLATY: Arithmetic expression parsed");
}
Пример #7
0
/* FIRST(relational expression)={AVID_T, FPL_T,INL_T,SVID_T, STR_T}
<relational expression> ->
	<primary a_relational expression> <p_operator> <primary a_relational expression> 
	| <primary s_relational expression> <p_operator> <primary s_relational expression>
Author: Kyle Hinskens */
void relational_expression(void){
	switch(lookahead_token.code){
		case AVID_T:
		case FPL_T:
		case INL_T:
			primary_a_relational_expression();
			switch (lookahead_token.code){
				case REL_OP_T:
					p_operator();
					primary_a_relational_expression();
					break;
				default :
					syn_printe();
			}
			break;
		case SVID_T:
		case STR_T: 
			primary_s_relational_expression();
			switch (lookahead_token.code){
				case REL_OP_T:
					p_operator();
					primary_s_relational_expression();
					break;
				default :
					syn_printe();
			}
			break;
		default:
			syn_printe();
			break;
	}

	gen_incode("Relational expression parsed");
}
Пример #8
0
/*
 * Purpose: Start the parser.
 * Author: Jason Macfarlane
 * History/Versions: 1.0
 * Called functions: mlwpar_next_token(), program(), match(), gen_incode()
 * Parameters: Buffer* in_buf
 */
void parser(Buffer* in_buf) {
    sc_buf = in_buf; /* Copy the passed buffer pointer location to the scanner buffer. */
    lookahead = mlwpar_next_token(sc_buf); /* Advance lookahead to the first token. */
    program(); /* Start the parser. */
    match(SEOF_T,NO_ATTR); /* Match the end of the PLATYPUS file. */
    gen_incode("PLATY: Source file parsed");
}
Пример #9
0
/*
 * Production: Optional Statements
 * FIRST set: { AVID_T, SVID_T, KWT (only IF, USING, INPUT, OUTPUT), e }
 */
void opt_statements(void) {
    switch(lookahead.code){
        case AVID_T:
        case SVID_T:
            statements();
            return;
            
        case KW_T:
            /* The token attribute must be IF, INPUT, OUTPUT or USING. */
            switch (lookahead.attribute.get_int) {
                case IF:
                case INPUT:
                case OUTPUT:
                case USING:
                    statements();
                    return;
                    
                default:
                    break;
            }
            
        default:
            gen_incode("PLATY: Opt_statements parsed");
            return;
    }
}
Пример #10
0
/* Provided by S.Ranev */
void parser(Buffer *in_buf) {
	sc_buf = in_buf;
	lookahead_token = mlwpar_next_token(sc_buf);
	program();
	match(SEOF_T, NO_ATTR);
	gen_incode("Source file parsed");
}
Пример #11
0
/*
 * Production: Input Statement
 * FIRST set: { KW_T (only INPUT) }
 */
void input_statement(void) {
    match(KW_T, INPUT);
    match(LPR_T, NO_ATTR);
    variable_list();
    match(RPR_T,NO_ATTR);
    match(EOS_T,NO_ATTR);
    gen_incode("PLATY: INPUT statement parsed");
}
Пример #12
0
/*
 * Production: Output Statement
 * FIRST set: { KW_T (only OUTPUT) }
 */
void output_statement(void) {
    match(KW_T, OUTPUT);
    match(LPR_T, NO_ATTR);
    opt_variable_list();
    match(RPR_T, NO_ATTR);
    match(EOS_T, NO_ATTR);
    gen_incode("PLATY: OUTPUT statement parsed");
}
Пример #13
0
/* FIRST(unary arithmetic expression)={-,+}
<unary arithmetic expression> ->
 - <primary arithmetic expression>
	| + <primary arithmetic expression>
Author: Kyle Hinskens */
void unary_arithmetic_expression(void){
	switch(lookahead_token.attribute.arr_op){
		case MINUS:
			match(ART_OP_T,MINUS);
			primary_arithmetic_expression();
			gen_incode("Unary arithmetic expression parsed");
			break;
		case PLUS:
			match(ART_OP_T,PLUS);
			primary_arithmetic_expression();
			gen_incode("Unary arithmetic expression parsed");
			break;
		default:
			syn_printe();
			break;
	}
}
Пример #14
0
/* FIRST(assignment statement)={AVID ,SVID}
<assignment statement> -> 
	<assignment expression>; 
Author: Kyle Hinskens */
void assignment_statement(void){
	switch(lookahead_token.code){
		case AVID_T:
		case SVID_T:
			assignment_expression(); 
			match(EOS_T, NO_ATTR);
			gen_incode("Assignment statement parsed");
			break;
	}
}
Пример #15
0
/* FIRST(assignment expression)={AVID ,SVID}
<assignment expression> ->	
	AVID = <arithmetic expression>
	| SVID = <string expression>
Author: Kwok Hong Kelvin Chan */
void assignment_expression(void){
	switch(lookahead_token.code){
	case AVID_T:
		match(AVID_T, NO_ATTR);
		match(ASS_OP_T, NO_ATTR);
		arithmetic_expression();
		gen_incode("Assignment expression (arithmetic) parsed");
		break;
	case SVID_T:
		match(SVID_T, NO_ATTR);
		match(ASS_OP_T, NO_ATTR);
		string_expression();
		gen_incode("Assignment expression (string) parsed");
		break;
	default:
		syn_printe();
		break;
	}
}
Пример #16
0
/* FIRST(string expression)={SVID_T, STR_T}
<string expression> -> 
	<primary string expression> <string expression’>
Author: Kyle Hinskens */
void string_expression(void){
	switch (lookahead_token.code){
	case SVID_T:
	case STR_T:
		primary_string_expression();
		string_expression_p();
		gen_incode("String expression parsed");
		break;
	}
}
Пример #17
0
/* FIRST(multiplicative arithmetic expression’)={*,/,e}
<multiplicative arithmetic expression’> ->
	* <primary arithmetic expression> <multiplicative arithmetic expression’> 
	| / <primary arithmetic expression> <multiplicative arithmetic expression’> 
	| e
Author: Kyle Hinskens */
void multiplicative_arithmetic_expression_p(void){
	switch(lookahead_token.code){
	case ART_OP_T:
		switch(lookahead_token.attribute.arr_op){
			case MULT:
				match(ART_OP_T,MULT);
				primary_arithmetic_expression();
				multiplicative_arithmetic_expression_p();
				gen_incode("Multiplicative arithmetic expression parsed");
				break;
			case DIV:
				match(ART_OP_T,DIV);
				primary_arithmetic_expression();
				multiplicative_arithmetic_expression_p();
				gen_incode("Multiplicative arithmetic expression parsed");
				break;
		}
	}
}
Пример #18
0
/* FIRST(output statement)={OUTPUT}
<output statement> ->
	OUTPUT(<output list>);
Author: Kyle Hinskens */
void output_statement(void) {
	if (lookahead_token.code == KW_T && lookahead_token.attribute.get_int == OUTPUT) {
		match(KW_T,OUTPUT);
		match(LPR_T,NO_ATTR);
		output_list();
		match(RPR_T,NO_ATTR);
		match(EOS_T,NO_ATTR);
		gen_incode("OUTPUT statement parsed"); 
	}
}
Пример #19
0
/* FIRST(additive arithmetic expression’)={+,-, e}
<additive arithmetic expression’> ->
	+ <multiplicative arithmetic expression> <additive arithmetic expression’> 
	| - <multiplicative arithmetic expression> <additive arithmetic expression’> 
	| e
Author: Kyle Hinskens */
void additive_arithmetic_expression_p(void){
	switch(lookahead_token.code){
	case ART_OP_T:
		switch (lookahead_token.attribute.arr_op){
		case PLUS:
			match(ART_OP_T,PLUS);
			multiplicative_arithmetic_expression();
			additive_arithmetic_expression_p();
			gen_incode("Additive arithmetic expression parsed");
			break;
		case MINUS:
			match(ART_OP_T,MINUS);
			multiplicative_arithmetic_expression();
			additive_arithmetic_expression_p();
			gen_incode("Additive arithmetic expression parsed");
			break;
		}
		break;
	}
}
Пример #20
0
/* FIRST(logical AND expression’)={.AMD., e}
<logical AND expression’> -> 
	.AND. <relational expression> <logical AND expression’> | e
Author: Kwok Hong Kelvin Chan */
void logical_AND_expression_p(void){
	switch(lookahead_token.code){
		case LOG_OP_T:
			switch (lookahead_token.attribute.log_op){
				case AND: 
					match(LOG_OP_T, AND);
					relational_expression(); 
					logical_AND_expression_p();
					gen_incode("Logical AND expression parsed"); 
					break;
			}
	}
}
Пример #21
0
/* FIRST(logical OR expression’)={.OR.,e}
<logical OR expression’> -> 
	.OR. <logical AND expression> <logical OR expression’> | e
Author: Kwok Hong Kelvin Chan */
void logical_OR_expression_p(void){
	switch(lookahead_token.code){
		case LOG_OP_T:
			switch (lookahead_token.attribute.log_op){
				case OR: 
					match(LOG_OP_T, OR);
					logical_AND_expression();
					logical_OR_expression_p(); 
					gen_incode("Logical OR expression parsed"); 
					break;
			}
	}
}
Пример #22
0
/*
 * Production: Assignment Expression
 * FIRST set: { AVID, SVID }
 */
void assignment_expression(void) {
    switch (lookahead.code) {
        case AVID_T:
            match(AVID_T, NO_ATTR);
            match(ASS_OP_T, NO_ATTR);
            arithmetic_expression();
            gen_incode("PLATY: Assignment expression (arithmetic) parsed");
            return;
        
        case SVID_T:
            match(SVID_T, NO_ATTR);
            match(ASS_OP_T, NO_ATTR);
            string_expression();
            gen_incode("PLATY: Assignment expression (string) parsed");
            return;
        
        /* If the current token code is not AVID or SVID, print an error. */
        default:
            syn_printe();
            return;
    }
    
}
Пример #23
0
/*
 * Production: Selection Statement
 * FIRST set: { KW_T (only IF) }
 */
void selection_statement(void) {
    match(KW_T, IF);
    match(LPR_T, NO_ATTR);
    conditional_expression();
    match(RPR_T, NO_ATTR);
    match(KW_T, THEN);
    opt_statements();
    match(KW_T, ELSE);
    match(LBR_T, NO_ATTR);
    opt_statements();
    match(RBR_T, NO_ATTR);
    match(EOS_T, NO_ATTR);
    gen_incode("PLATY: IF statement parsed");
}
Пример #24
0
/*
 * Production: Primary String Expression
 * FIRST set: { SVID_T, STR_T }
 */
void primary_string_expression(void) {
    switch (lookahead.code) {
        case STR_T:
        case SVID_T:
            match(lookahead.code, NO_ATTR);
            break;
        
        /* If the current token code is not STR_T or SVID_T, print an error. */
        default:
            syn_printe();
            break;
    }
    
    gen_incode("PLATY: Primary string expression parsed");
}
Пример #25
0
/* FIRST(selection statement)={IF}
<selection statement> ->
	IF (<conditional expression>) THEN <opt_statements> 
	ELSE { <opt_statements> } ; 
Author: Kyle Hinskens */
void selection_statement(void){
	if (lookahead_token.attribute.get_int == IF){
		match(KW_T,IF);
		match(LPR_T,NO_ATTR);
		conditional_expression();
		match(RPR_T,NO_ATTR);
		match(KW_T,THEN);
		opt_statements();
		match(KW_T,ELSE);
		match(LBR_T,NO_ATTR);
		opt_statements();
		match(RBR_T,NO_ATTR);
		match(EOS_T,NO_ATTR);
		gen_incode("IF statement parsed");
	}
}
Пример #26
0
/*
 * Production: Primary Arithmetic Relational Expression
 * FIRST set: { AVID_T, FPL_T, INL_T }
 */
void primary_a_relational_expression(void) {
    switch (lookahead.code) {
        case AVID_T:
        case FPL_T:
        case INL_T:
            match(lookahead.code, lookahead.attribute.rel_op);
            break;
        
        /* If the current token code is not AVID_T, FPL_T or INL_T, print an error. */
        default:
            syn_printe();
            break;
    }
    
    gen_incode("PLATY: Primary a_relational expression parsed");
}
Пример #27
0
/*
 * Production: Iteration Statement
 * FIRST set: { KW_T (only USING) }
 */
void iteration_statement(void) {
    match(KW_T, USING);
    match(LPR_T, NO_ATTR);
    assignment_expression();
    match(COM_T, NO_ATTR);
    conditional_expression();
    match(COM_T, NO_ATTR);
    assignment_expression();
    match(RPR_T, NO_ATTR);
    match(KW_T, REPEAT);
    match(LBR_T, NO_ATTR);
    opt_statements();
    match(RBR_T, NO_ATTR);
    match(EOS_T, NO_ATTR);
    gen_incode("PLATY: USING statement parsed");
}
Пример #28
0
/*
 * Production: Logical AND Expression (P)
 * FIRST set: { ., e }
 */
void logical_and_expression_p(void) {
    switch (lookahead.code) {
        case LOG_OP_T:
            /* The token attribute must be AND. */
            if (lookahead.attribute.log_op == AND) {
                match(LOG_OP_T, AND);
                relational_expression();
                logical_and_expression_p();
                gen_incode("PLATY: Logical AND expression parsed");
                return;
            }
            return;
            
        default:
            return;
    }
}
Пример #29
0
/*
 * Production: Logical OR Expression (P)
 * FIRST set: { ., e }
 */
void logical_or_expression_p(void) {
    switch (lookahead.code) {
        case LOG_OP_T:
            /* The token attribute must be OR. */
            if (lookahead.attribute.log_op == OR) {
                match(LOG_OP_T, OR);
                logical_and_expression();
                logical_or_expression_p();
                gen_incode("PLATY: Logical OR expression parsed");
                return;
            }
            return;
            
        default:
            return;
    }
}
Пример #30
0
/* FIRST(primary a_relational expression)={AVID_T, FPL_T,INL_T}
<primary a_relational expression> -> 
	AVID_T | FPL_T | INL_T
Author: Kyle Hinskens */
void primary_a_relational_expression(void){
	switch(lookahead_token.code){
		case AVID_T:
			match(AVID_T, NO_ATTR);
			break;
		case FPL_T:
			match(FPL_T, NO_ATTR);
			break;
		case INL_T:
			match(INL_T, NO_ATTR);
			break;
		default:
			syn_printe();
			break;
	}
	
	gen_incode("Primary a_relational expression parsed");
}