int main(){ Num n1, n2; scanf("%lld/%lld %lld/%lld", &n1.up, &n1.down, &n2.up, &n2.down); stdPrint(n1); printf(" + "); stdPrint(n2); printf(" = "); stdPrint( plus(n1, n2) ); printf("\n"); stdPrint(n1); printf(" - "); stdPrint(n2); printf(" = "); stdPrint( minus(n1, n2) ); printf("\n"); stdPrint(n1); printf(" * "); stdPrint(n2); printf(" = "); stdPrint( multi(n1, n2) ); printf("\n"); stdPrint(n1); printf(" / "); stdPrint(n2); printf(" = "); if( n2.up==0 ) printf("Inf"); else stdPrint( divide(n1, n2) ); return 0; }
TypePtr standardRoutineCall (SymTableNodePtr routineIdPtr) { long key = routineIdPtr->defn.info.routine.key; long numParams = FunctionInfoTable[key].numParams; switch (key) { case RTN_RETURN: stdReturn(); return(NULL); case RTN_PRINT: stdPrint(); return(NULL); case RTN_CONCAT: return(stdConcat()); case RTN_GET_STATE_HANDLE: return(stdGetStateHandle()); default: if (key >= NumStandardFunctions) syntaxError(ABL_ERR_SYNTAX_UNEXPECTED_TOKEN); if (numParams == 0) { if (curToken == TKN_LPAREN) syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS); } else { if (curToken == TKN_LPAREN) getToken(); else syntaxError(ABL_ERR_SYNTAX_WRONG_NUMBER_OF_PARAMS); for (long i = 0; i < numParams; i++) { TypePtr paramType = expression(); switch (FunctionInfoTable[key].params[i]) { case PARAM_TYPE_ANYTHING: break; case PARAM_TYPE_CHAR: if (paramType != CharTypePtr) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_INTEGER: if (paramType != IntegerTypePtr) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_REAL: if (paramType != RealTypePtr) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_BOOLEAN: if (paramType != BooleanTypePtr) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_INTEGER_REAL: if ((paramType != IntegerTypePtr) && (paramType != RealTypePtr)) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_CHAR_ARRAY: if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != CharTypePtr)) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_INTEGER_ARRAY: if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != IntegerTypePtr)) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_REAL_ARRAY: if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != RealTypePtr)) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; case PARAM_TYPE_BOOLEAN_ARRAY: if ((paramType->form != FRM_ARRAY) || (paramType->info.array.elementTypePtr != BooleanTypePtr)) syntaxError(ABL_ERR_SYNTAX_INCOMPATIBLE_TYPES); break; } if (i == (numParams - 1)) ifTokenGetElseError(TKN_RPAREN, ABL_ERR_SYNTAX_MISSING_RPAREN); else ifTokenGetElseError(TKN_COMMA, ABL_ERR_SYNTAX_MISSING_COMMA); } } switch (FunctionInfoTable[key].returnType) { case RETURN_TYPE_NONE: return(NULL); case RETURN_TYPE_INTEGER: return(IntegerTypePtr); case RETURN_TYPE_REAL: return(RealTypePtr); case RETURN_TYPE_BOOLEAN: return(BooleanTypePtr); } } return(NULL); }