Exemple #1
0
struct Token *function_execute(struct Token *statement, struct List *scope){

	int header = statement->list->tokens[0]->type;

	if( token_is_operator(header) ) return function_operator(statement,scope);
	if(header == T_PRINT)           return function_print(statement,scope);
	if(header == T_IF)              return function_if(statement,scope);
	if(header == T_EXPRESSION)      return function_expression(statement,scope);
	if(header == T_STRING)          return statement->list->tokens[1];
	if(header == T_EQUALS)          return function_assignment(statement,scope);
	if(header == T_LOOKUP)          return function_lookup(statement,scope);
	if(header == T_NOT)             return function_not(statement,scope);

	printf("(ERROR:function_execute) Statement was not a valid function.\n");
	return token_create(T_NUMBER,0);
}
Exemple #2
0
// print some general information about the image: type name,
// dimensions.
vint8 general_image::print_header() const
{
  print_type_name(type_name);
  function_print(", %li channels, %li rows, %li cols\n", bands, rows, cols);
  return 1;
}
Exemple #3
0
extern void interp_runCommand(Env* env, TPA_Instruction* inst) {
	char* str;
	Function* f;
	Points* points;
	PointItem* pointItem;
	FILE* out = stdout;
	switch(inst->kind) {
        case PA_IK_Expr:
            f = function_createWithFunctionTree(TPAExpr_toFunctionTree(inst->u.expr.expr, env));
            addFunction(env, inst->u.expr.name, f);
            break;

				case PA_IK_Table:
					f = function_createWithTruthTable(TPAExpr_toTruthTable(inst->u.table.vals));
					addFunction(env, inst->u.table.name, f);
					break;

        case PA_IK_Print:
            f = interp_getFunctionByName(env, inst->u.print.name);
            if(f==0) {
              fprintf(stderr,"Fonction inconnue\n");
            }
            else {
							out = stdout;

							if(inst->u.print.filename) {
								str = calloc(strlen(inst->u.print.filename)+1, sizeof(*str));
								strcpy(str, inst->u.print.filename+1);
								str[strlen(str)-1] = 0;
								out = file_fopenOutput(str);
								if(!out) {
									printf("Fallback on stdout print.\n");
									out = stdout;
								}
							}

							switch(inst->u.print.fmt) {
								case PA_PF_expr:
									function_print(f, out);
									break;

								case PA_PF_bdd:
									function_printAsBDD(f, out);
									break;

								case PA_PF_table:
									function_printAsTruthTable(f, out);
									break;

								case PA_PF_disjonctive:
									function_printAsDNF(f, out);
									break;

								case PA_PF_dot:
									function_printAsTree(f, out);
									break;

								case PA_PF_karnaugh:
									function_printAsKarnaugh(f, out);
									break;
							}

							if(out!=stdout)
								fclose(out);
            }
            break;
        case PA_IK_Point:
                // u.print.name - point name
                // u->u.point:
                // char*      name; // nom de l'ensemble
                // char       ope;  // operateur: '=':= ; '+':+= ; '-':-=
                // TPA_Expr** vals; // les valeurs du point:
                points = interp_getPointsByName(env,inst->u.point.name);
                if (points == 0) {
                    points = points_init();
                    addPoints(env, inst->u.expr.name, points);
                }
                if (interp_pointsOperation(points,inst->u.point.name,inst->u.point.ope,inst->u.point.vals) == 0)
                	fprintf(stderr, "La taille de point est incompatible avec l'ensemble\n");
				else 
	                points_print(points, out);
                break;
        case PA_IK_EvalEns:
					
					points = interp_getPointsByName(env,inst->u.evalens.ens);
          if (points == 0) {
						fprintf(stderr, "Ensemble des points inconnue\n");
            break;
					}
					pointItem = points->point;
					if (pointItem == 0) {
						fprintf(stderr, "L'ensemble des points est vide\n");
						break;
					}
					
					f = interp_getFunctionByName(env, inst->u.evalens.name);
					if (f == 0) {
						fprintf(stderr,"Fonction inconnue\n");
							break;
					}
					
					if (points_getDim(points) != function_getVarsLength(f)) {
						fprintf(stderr,"Dimension des points et de la fonction incompatible.\n");
							break;					
					}
					
					do {
						function_printEvalPoint(f,pointItem->p,out);					
						pointItem = pointItem->next;
					} while (pointItem != 0);
					break;
				
				f = interp_getFunctionByName(env, inst->u.evalens.name);
				if (f == 0) {
					fprintf(stderr,"Fonction inconnue\n");
				  	break;
				}
				
				if (points_getDim(points) != function_getVarsLength(f)) {
					fprintf(stderr,"Point vector dim and function vars number mismatch.\n");
				  	break;					
				}
								
				do {
					function_printEvalPoint(f,pointItem->p,out);					
					pointItem = pointItem->next;
				} while (pointItem != 0);

                break;
	    case PA_IK_EvalPoint:
	  		function_printEvalPoint(
	  			interp_getFunctionByName(env, inst->u.evalpoint.name),
	  			TPAExpr_toPoint(inst->u.evalpoint.vals),out
	  		);
        	break;
				
        default:
            fprintf(stderr," Instruction inconnue\n");
            break;
    }
}