/* * <sentencia> → * <identificador> := <expresión> #asignar ; | * leer ( <listaIdentificadores> ) ; | * escribir ( <listaExpresiones> ) ; */ void sentencia(void) { token tok = prox_token(); struct reg_expr id_reg, result_reg; switch(tok) { case ID: identificador(&id_reg); match(ASIGNACION); expresion(&result_reg); asignar(&id_reg, &result_reg); match(PUNTOYCOMA); break; case LEER: match(LEER); match(PARENIZQUIERDO); lista_identificadores(); match(PARENDERECHO); match(PUNTOYCOMA); break; case ESCRIBIR: match(ESCRIBIR); match(PARENIZQUIERDO); lista_expresiones(); match(PARENDERECHO); match(PUNTOYCOMA); break; default: error_sintactico(tok); return; } }
void llamada_funcion() { if (sbol->codigo == CIDENT) { scanner(); } else { error_handler(34); // se esperaba identificador de funcion } inInvocation = TRUE; if (sbol->codigo == CPAR_ABR) { scanner(); } else { error_handler(19); // falta ( } if (sbol->codigo == CMAS || sbol->codigo == CMENOS || sbol->codigo == CIDENT || sbol->codigo == CPAR_ABR || sbol->codigo == CNEG || sbol->codigo == CCONS_ENT || sbol->codigo == CCONS_FLO || sbol->codigo == CCONS_CAR || sbol->codigo == CCONS_STR) { lista_expresiones(); } if (sbol->codigo == CPAR_CIE) { scanner(); } else { error_handler(20); // falta ) } inInvocation = FALSE; }
void sentencia(void) { /* * <sentencia> -> <identificador> ASIGNACION <expresión> PUNTOYCOMA * | LEER PARENIZQUIERDO <listaIdentificadores> PARENDERECHO PUNTOYCOMA * | ESCRIBIR PARENIZQUIERDO <listaExpresiones> PARENDERECHO PUNTOYCOMA */ token tok = next_token(); reg_expr right_operand, left_operand; switch (tok) { case ID: identificador(&left_operand); match(ASIGNACION); expresion(&right_operand); asignar(&left_operand, &right_operand); // #asignar match(PUNTOYCOMA); break; case LEER: match(LEER); match(PARENIZQUIERDO); lista_identificadores(); match(PARENDERECHO); match(PUNTOYCOMA); break; case ESCRIBIR: match(ESCRIBIR); match(PARENIZQUIERDO); lista_expresiones(); match(PARENDERECHO); match(PUNTOYCOMA); break; default: syntax_error(tok, "SENTENCIA"); } }