/* 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; } }
/* * Production: Primary Arithmetic Expression * FIRST set: { AVID_T, FPL_T, INL_T, ( } */ void primary_arithmetic_expression(void) { switch (lookahead.code) { case AVID_T: case FPL_T: case INL_T: match(lookahead.code, lookahead.attribute.rel_op); break; case LPR_T: match(LPR_T, lookahead.attribute.arr_op); arithmetic_expression(); match(RPR_T, NO_ATTR); break; /* If nothing matches, print an error. */ default: syn_printe(); break; } gen_incode("PLATY: Primary arithmetic expression parsed"); }
/* * 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; } }
/* FIRST(primary arithmetic expression)={AVID_T, FPL_T ,INL_T ,(} <primary arithmetic expression> -> AVID_T | FPL_T | INL_T | (<arithmetic expression>) Author: Kwok Hong Kelvin Chan */ void primary_arithmetic_expression(void){ switch(lookahead_token.code){ case LPR_T: match(LPR_T, NO_ATTR); arithmetic_expression(); match(RPR_T, NO_ATTR); break; 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 arithmetic expression parsed"); }