int main(void) { ast_t * a; int jval; jit_t * jit; GC_INIT(); GREG g; ast_init(); sym_tab_init(); types_init(); scope_init(); loc_tab_init(); intrinsics_init(); jit = llvm_init(); ZZ_init(jit); yyinit(&g); printf("Welcome to Bacon v0.1\n\n"); printf("> "); while (1) { if (!(jval = setjmp(exc))) { if (!yyparse(&g)) { printf("Error parsing\n"); abort(); } else if (root) { #if DEBUG1 printf("\n"); ast_print(root, 0); #endif inference(root); #if DEBUG2 printf("\n"); /*ast2_print(root, 0);*/ #endif exec_root(jit, root); root = NULL; } } else if (jval == 1) root = NULL; else /* jval == 2 */ break; printf("\n> "); } llvm_cleanup(jit); yydeinit(&g); printf("\n"); return 0; }
double var_bayes::doc_e_step(const document &doc, suff_stats &ss, std::vector<double>& var_gamma, std::vector<std::vector<double>>& phi) { // Estimate gamma and phi for this document and get the document log likelihood double likelihood = inference(doc, var_gamma, phi); // Update the sufficient statistics int topic=0; for(const double& val: dirichlet_expectation(var_gamma)){ ss.alpha_ss[topic] += val; topic++; } int n=0; for(auto const& word_count : doc.wordCounts){ for(int k=0; k<numTopics; k++){ ss.classWord[k][word_count.first] += word_count.second * phi[n][k]; ss.classTotal[k] += word_count.second * phi[n][k]; } n++; } ss.numDocs++; return likelihood; }
int main(int argc, char* argv[]) { if (argc > 1) { if (strcmp(argv[1], "est")==0) { read_params(argv[6]); print_params(); em(argv[2], atoi(argv[3]), argv[4], argv[5]); return(0); } if (strcmp(argv[1], "inf")==0) { read_params(argv[5]); print_params(); inference(argv[2], argv[3], argv[4]); return(0); } } printf("usage : ctm est <dataset> <# topics> <rand/seed/model> <dir> <settings>\n"); printf(" ctm inf <dataset> <model-prefix> <results-prefix> <settings>\n"); return(0); }
VectorXs DenseCRF::map ( int n_iterations ) const { // Run inference MatrixXf Q = inference( n_iterations ); // Find the map return currentMap( Q ); }
int main(int argc, char *argv[]){ fuzzyvar *inputs = new fuzzyvar[3]; // Membership functions for Hue inputs[0].nMF = 2; inputs[0].f = new char[2]; inputs[0].a = new double[2]; inputs[0].b = new double[2]; inputs[0].c = new double[2]; inputs[0].d = new double[2]; inputs[0].y = new double[2]; // Hue is red inputs[0].f[0] = 'n'; inputs[0].a[0] = 6.; inputs[0].b[0] = 16.; inputs[0].c[0] = 160.; inputs[0].d[0] = 174.; // Hue is not red inputs[0].f[1] = 'p'; inputs[0].a[1] = 12.; inputs[0].b[1] = 18.; inputs[0].c[1] = 156.; inputs[0].d[1] = 164.; // Membership functions for Sat inputs[1].nMF = 3; inputs[1].f = new char[3]; inputs[1].a = new double[3]; inputs[1].b = new double[3]; inputs[1].c = new double[3]; inputs[1].d = new double[3]; inputs[1].y = new double[3]; // Sat is achroma inputs[1].f[0] = 'z'; inputs[1].a[0] = 0.05*255; inputs[1].b[0] = 0.2*255; inputs[1].c[0] = inputs[0].d[0] = 0.; // Sat is unstable inputs[1].f[1] = 'p'; inputs[1].a[1] = 0.1*255; inputs[1].b[1] = 0.3*255; inputs[1].c[1] = 0.4*255; inputs[1].d[1] = 0.6*255; // Sat is chroma inputs[1].f[2] = 's'; inputs[1].a[2] = 0.4*255; inputs[1].b[2] = 0.6*255; inputs[1].c[2] = inputs[1].d[2] = 0.; // Membership functions for Val inputs[2].nMF = 2; inputs[2].f = new char[2]; inputs[2].a = new double[2]; inputs[2].b = new double[2]; inputs[2].c = new double[2]; inputs[2].d = new double[2]; inputs[2].y = new double[2]; // Val is achroma inputs[2].f[0] = 'z'; inputs[2].a[0] = 0.*255; inputs[2].b[0] = 0.2*255; inputs[2].c[0] = inputs[0].d[0] = 0.; // Val is chroma inputs[2].f[1] = 's'; inputs[2].a[1] = 0.1*255; inputs[2].b[1] = 0.25*255; inputs[2].c[1] = inputs[2].d[1] = 0.; fuzzyvar output; // Membership functions for Grayscale output output.nMF = 4; output.f = new char[4]; output.a = new double[4]; output.b = new double[4]; output.c = new double[4]; output.d = new double[4]; output.y = new double[4]; // Output is 0 output.f[0] = '0'; output.a[0] = output.b[0] = output.c[0] = output.d[0] = 0.; // Output is low output.f[1] = 'z'; output.a[1] = 0.15*255; output.b[1] = 0.4*255; output.c[1] = output.d[1] = 0.; // Output is md output.f[2] = 'p'; output.a[2] = 0.2*255; output.b[2] = 0.35*255; output.c[2] = 0.55*255; output.d[2] = 0.7*255; // Output is high output.f[3] = 's'; output.a[3] = 0.4*255; output.b[3] = 0.8*255; output.c[3] = output.d[3] = 0; double X[3] = {atoi(argv[1]), atoi(argv[2]), atoi(argv[3])}; double Y = inference(inputs, output, X, 3); printf("\n%.2f\n", Y); return 0; }
int main(int argc, char * argv[]) { if (argc < 4 || argc > 5) { printf("Usage: ./fastLDA docword.txt iterations num_topics [num_threads]\n"); exit(INVALID_CALL); } num_iterations = strtol(argv[2], NULL, 10); if (num_iterations == 0) { printf("Recheck number of iterations\n"); exit(INVALID_NUM_ITERATIONS); } K = strtol(argv[3], NULL, 10); if (K == 0) { printf("Recheck number of topics\n"); exit(INVALID_NUM_TOPICS); } if (argc == 5) { _num_threads_ = strtol(argv[4], NULL, 10); if (_num_threads_ == 0) { printf("Recheck number of threads\n"); exit(INVALID_NUM_THREADS); } } else { _num_threads_ = 0; } if (_num_threads_ == 0) { long num_processors = omp_get_num_procs(); _num_threads_ = floor(1.2 * num_processors); if (_num_threads_ < MIN_NUM_THREADS) { _num_threads_ = MIN_NUM_THREADS; } printf("found %ld processors; set number of threads to %ld;\n", num_processors, _num_threads_); } else { printf("set number of threads to %ld;\n", _num_threads_); } printf("\n"); start_timer(); read_sparse_dataset(argv[1]); stop_timer("reading file took %.3f seconds\n"); printf("\n"); #ifndef NDEBUG printf("first word (%ld unique in doc %ld): id %ld count %ld\n", num_unique_d[1], (long)1, word_d_i[1][0], count_d_i[1][0]); printf("last word (%ld unique in doc %ld): id %ld count %ld\n", num_unique_d[D], D, word_d_i[D][num_unique_d[D] - 1], count_d_i[D][num_unique_d[D] - 1]); printf("\n"); #endif // allocate calculation tables start_timer(); if ((N_theta_d_k = (double *) malloc((D + 1) * K * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } if ((N_phi_w_k = (double *) malloc((W + 1) * K * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } N_z_k = N_phi_w_k; if ((C_t = (long *) malloc(_num_threads_ * sizeof(long))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } if ((rho_phi_times_C_over_C_t = (double *) malloc(_num_threads_ * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } if ((one_over_N_z_k_plus_W_times_ETA = (double *) malloc(K * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } if ((factor = (double *) malloc((count_max + 1) * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } if ((one_minus_factor = (double *) malloc((count_max + 1) * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } if ((N_hat_phi_t_w_k = (double **) malloc(_num_threads_ * sizeof(double *))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } for (long t = 0; t < _num_threads_; ++t) { if ((N_hat_phi_t_w_k[t] = (double *) malloc((W + 1) * K * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } } N_hat_z_t_k = N_hat_phi_t_w_k; if ((theta_d_k = (double *) malloc((D + 1) * K * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } if ((phi_w_k = (double *) malloc((W + 1) * K * sizeof(double))) == NULL) { printf("Out of memory\n"); exit(OUT_OF_MEMORY); } stop_timer("memory allocation took %.3f seconds\n"); // randomly initialize N_theta_d_k, N_phi_w_k, N_z_k start_timer(); for (long t = 0; t < _num_threads_; ++t) memset(N_hat_phi_t_w_k[t], 0, (W + 1) * K * sizeof(double)); #pragma omp parallel for schedule(static) num_threads(_num_threads_) for (long d = 1; d <= D; ++d) { long thread_id = omp_get_thread_num(); unsigned long x, y, z, t; // TODO: random these in final version x=123456789, y=362436069, z=521288629, t = 0; for (long i = 0; i < num_unique_d[d]; ++i) { for (long c = 0; c < count_d_i[d][i]; ++c) { x ^= x << 16; x ^= x >> 5; x ^= x << 1; t = x; x = y; y = z; z = t ^ x ^ y; long k = z % K; N_theta_d_k(d, k) += 1; N_hat_phi_t_w_k(thread_id, word_d_i[d][i], k) += 1; N_hat_z_t_k(thread_id, k) += 1; } } } #pragma omp parallel for schedule(static) num_threads(_num_threads_) for (long k = 0; k < K; ++k) { for (long w = 1; w <= W; ++w) { double sum_N_phi = 0; for (long t = 0; t < _num_threads_; ++t) { sum_N_phi += N_hat_phi_t_w_k(t, w, k); } N_phi_w_k(w, k) = sum_N_phi; } double sum_N_z = 0; for (long t = 0; t < _num_threads_; ++t) { sum_N_z += N_hat_z_t_k(t, k); } N_z_k(k) = sum_N_z; } stop_timer("random initialization took %.3f seconds\n"); #ifndef NDEBUG double sum = 0; for (long k = 0; k < K; ++k) { sum += N_z_k(k); } printf("sum(N_z_k): %.0f (should be equal to C)\n", sum); #endif printf("\n"); #ifdef REPORT_PERPLEXITY printf("calculate initial perplexity:\n"); start_timer(); calculate_theta_phi(); stop_timer("theta and phi calculation took %.3f seconds\n"); start_timer(); calculate_perplexity(); stop_timer("perplexity calculation took %.3f seconds\n"); printf("\n"); #endif // for each iteration for (long iteration_idx = 1; iteration_idx <= num_iterations; ++iteration_idx) { printf("iteration %ld:\n", iteration_idx); start_timer(); inference(iteration_idx); stop_timer("inference took %.3f seconds\n"); #ifdef REPORT_PERPLEXITY start_timer(); calculate_theta_phi(); stop_timer("theta and phi calculation took %.3f seconds\n"); start_timer(); calculate_perplexity(); stop_timer("perplexity calculation took %.3f seconds\n"); #endif printf("\n"); } start_timer(); calculate_theta_phi(); stop_timer("theta and phi calculation took %.3f seconds\n"); start_timer(); calculate_topic(); stop_timer("topic calculation took %.3f seconds\n"); start_timer(); output(); stop_timer("writing files took %.3f seconds\n"); return 0; }
std::unique_ptr<Builder> ConfigParser::getBuilder( Json::Value json, std::shared_ptr<arbiter::Arbiter> arbiter) { if (!arbiter) arbiter = std::make_shared<arbiter::Arbiter>(); const bool verbose(json["verbose"].asBool()); const Json::Value d(defaults()); for (const auto& k : d.getMemberNames()) { if (!json.isMember(k)) json[k] = d[k]; } const std::string outPath(json["output"].asString()); const std::string tmpPath(json["tmp"].asString()); const std::size_t threads(json["threads"].asUInt64()); normalizeInput(json, *arbiter); auto fileInfo(extract<FileInfo>(json["input"])); if (!json["force"].asBool()) { auto builder = tryGetExisting( json, *arbiter, outPath, tmpPath, threads); if (builder) { if (verbose) builder->verbose(true); // If we have more paths to add, add them to the manifest. // Otherwise we might be continuing a partial build, in which case // the paths to be built are already outstanding in the manifest. // // It's plausible that the input field could be empty to continue // a previous build. if (json["input"].isArray()) builder->append(fileInfo); return builder; } } const bool compress(json["compress"].asUInt64()); const bool trustHeaders(json["trustHeaders"].asBool()); auto cesiumSettings(getCesiumSettings(json["formats"])); bool absolute(json["absolute"].asBool()); if (cesiumSettings) { absolute = true; json["reprojection"]["out"] = "EPSG:4978"; } auto reprojection(maybeCreate<Reprojection>(json["reprojection"])); std::unique_ptr<std::vector<double>> transformation; std::unique_ptr<Delta> delta; if (!absolute && Delta::existsIn(json)) delta = makeUnique<Delta>(json); // If we're building from an inference, then we already have these. A user // could have also pre-supplied them in the config. // // Either way, these three values are prerequisites for building, so if // we're missing any we'll need to infer them from the files. std::size_t numPointsHint(json["numPointsHint"].asUInt64()); auto boundsConforming(maybeCreate<Bounds>(json["bounds"])); auto schema(maybeCreate<Schema>(json["schema"])); const bool needsInference(!boundsConforming || !schema || !numPointsHint); if (needsInference) { if (verbose) { std::cout << "Performing dataset inference..." << std::endl; } Inference inference( fileInfo, reprojection.get(), trustHeaders, !absolute, tmpPath, threads, verbose, !!cesiumSettings, arbiter.get()); inference.go(); // Overwrite our initial fileInfo with the inferred version, which // contains details for each file instead of just paths. fileInfo = inference.fileInfo(); if (!absolute && inference.delta()) { if (!delta) delta = makeUnique<Delta>(); if (!json.isMember("scale")) { delta->scale() = inference.delta()->scale(); } if (!json.isMember("offset")) { delta->offset() = inference.delta()->offset(); } } if (!boundsConforming) { boundsConforming = makeUnique<Bounds>(inference.bounds()); if (verbose) { std::cout << "Inferred: " << inference.bounds() << std::endl; } } if (!schema) { auto dims(inference.schema().dims()); if (delta) { const Bounds cube( Metadata::makeScaledCube( *boundsConforming, delta.get())); dims = Schema::deltify(cube, *delta, inference.schema()).dims(); } const std::size_t pointIdSize([&fileInfo]() { std::size_t max(0); for (const auto& f : fileInfo) { max = std::max(max, f.numPoints()); } if (max <= std::numeric_limits<uint32_t>::max()) return 4; else return 8; }()); const std::size_t originSize([&fileInfo]() { if (fileInfo.size() <= std::numeric_limits<uint32_t>::max()) return 4; else return 8; }()); dims.emplace_back("OriginId", "unsigned", originSize); dims.emplace_back("PointId", "unsigned", pointIdSize); schema = makeUnique<Schema>(dims); } if (!numPointsHint) numPointsHint = inference.numPoints(); if (const std::vector<double>* t = inference.transformation()) { transformation = makeUnique<std::vector<double>>(*t); } } auto subset(maybeAccommodateSubset(json, *boundsConforming, delta.get())); json["numPointsHint"] = static_cast<Json::UInt64>(numPointsHint); Structure structure(json); Structure hierarchyStructure(Hierarchy::structure(structure, subset.get())); const HierarchyCompression hierarchyCompression( compress ? HierarchyCompression::Lzma : HierarchyCompression::None); const auto ep(arbiter->getEndpoint(json["output"].asString())); const Manifest manifest(fileInfo, ep); const Metadata metadata( *boundsConforming, *schema, structure, hierarchyStructure, manifest, trustHeaders, compress, hierarchyCompression, reprojection.get(), subset.get(), delta.get(), transformation.get(), cesiumSettings.get()); OuterScope outerScope; outerScope.setArbiter(arbiter); auto builder = makeUnique<Builder>(metadata, outPath, tmpPath, threads, outerScope); if (verbose) builder->verbose(true); return builder; }
void StackPopCommands(STACK* stack_pointer, List* global, List* global_vet, List* local, List* function_list, List* AllParams){ if(stack_pointer!=NULL){ List* InUseFunction = TILL_NULL(function_list); /*A ultima funcao da lista de funcoes sera a funcao em uso cujos comandos serao desempilhados*/ int NumVal; List *GlobalSearch, *LocalSearch, *VectorialSearch, *FunctionSearch, *aux; ASTREE* Variable,*RightSon,*LeftSon,*Left_RightGrandSon; switch(stack_pointer->disc->type){ case IKS_AST_ARIM_SUBTRACAO: case IKS_AST_ARIM_MULTIPLICACAO: case IKS_AST_LOGICO_E: case IKS_AST_LOGICO_OU: case IKS_AST_ARIM_DIVISAO: case IKS_AST_LOGICO_COMP_DIF: case IKS_AST_LOGICO_COMP_IGUAL: case IKS_AST_LOGICO_COMP_LE: case IKS_AST_LOGICO_COMP_GE: case IKS_AST_LOGICO_COMP_L: case IKS_AST_LOGICO_COMP_G: case IKS_AST_ARIM_SOMA: stack_pointer->disc->node_type = inference(stack_pointer->disc->scc[0]->node_type,stack_pointer->disc->scc[1]->node_type); break; case IKS_AST_CHAMADA_DE_FUNCAO: /*Primeiramente, teremos de verificar a existencia da função chamada*/ LeftSon = stack_pointer->disc->scc[0]; RightSon = stack_pointer->disc->scc[1]; FunctionSearch = list_lookup(function_list,LeftSon->symbol->text); /*retorna a função chamada*/ if(FunctionSearch != NULL){ AllParams = FunctionParamList(AllParams,FunctionSearch->tam); /*Retorna a lista de parametros da função chamada*/ Variable = ParamLookup(RightSon,AllParams); if(Variable == NULL && RightSon!= NULL) stack_pointer->disc->node_type = inference(RightSon->type,LeftSon->type); else if(Variable == NULL && RightSon == NULL) stack_pointer->disc->node_type = LeftSon->node_type; } else{ printf("->Funcao nao declarada (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_UNDECLARED); break; } break; case IKS_AST_IDENTIFICADOR: GlobalSearch = list_lookup(global,stack_pointer->disc->symbol->text); LocalSearch = list_lookup(local,stack_pointer->disc->symbol->text); VectorialSearch = list_lookup(global_vet,stack_pointer->disc->symbol->text); FunctionSearch = list_lookup(function_list,stack_pointer->disc->symbol->text); if(GlobalSearch !=NULL){ if(LocalSearch !=NULL){ printf("->Identificador de variavel global foi declarado como variavel local (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else if(FunctionSearch !=NULL){ printf("->Identificador de variavel global foi declarado como funcao (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else{ stack_pointer->disc->node_type = GlobalSearch->type; stack_pointer->disc->size = var_size(stack_pointer->disc->node_type); break; } } else if(LocalSearch != NULL){ if(GlobalSearch != NULL){ printf("->Identificador de variavel local foi declarado como variavel global (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else if(FunctionSearch != NULL){ printf("->Identificador de variavel local foi declarado como funcao (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else{ stack_pointer->disc->node_type = LocalSearch->type; stack_pointer->disc->size = var_size(stack_pointer->disc->node_type); break; } } else if(FunctionSearch != NULL){ if(GlobalSearch != NULL){ printf("->Identificador de funcao foi declarado como variavel global (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else if(LocalSearch !=NULL){ printf("->Identificador de funcao foi declarado como variavel local (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else{ stack_pointer->disc->node_type = FunctionSearch->type; stack_pointer->disc->size = var_size(stack_pointer->disc->node_type); break; } } else if (VectorialSearch ==NULL){ printf("->Identificador nao declarado (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_UNDECLARED); break; } break; case IKS_AST_LITERAL: stack_pointer->disc->node_type = stack_pointer->disc->symbol->type; stack_pointer->disc->size = var_size(stack_pointer->disc->symbol->type); break; case IKS_AST_VETOR_INDEXADO: /*O primeiro filho de um vetor indexado será o TK_IDENTIFICADOR referente ao nome da variavel*/ LeftSon = stack_pointer->disc->scc[0]; /*Variavel do vetor*/ RightSon = stack_pointer->disc->scc[1]; /*Quantidade de termos do vetor*/ GlobalSearch = list_lookup(global,stack_pointer->disc->scc[0]->symbol->text); LocalSearch = list_lookup(local,stack_pointer->disc->scc[0]->symbol->text); VectorialSearch = list_lookup(global_vet,stack_pointer->disc->scc[0]->symbol->text); FunctionSearch = list_lookup(function_list,stack_pointer->disc->scc[0]->symbol->text); if(VectorialSearch !=NULL){ LeftSon->node_type = VectorialSearch->type; stack_pointer->disc->node_type = VectorialSearch->type; LeftSon->size =VectorialSearch->tam*var_size(LeftSon->node_type); stack_pointer->disc->size = LeftSon->size; break; } else{ if(GlobalSearch !=NULL){ printf("->Identificador de vetor foi declarado como variavel global (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else if(LocalSearch !=NULL){ printf("->Identificador de vetor foi declarado como variavel local (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } else if(FunctionSearch !=NULL){ printf("->Identificador de vetor foi declarado como funcao (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); break; } } break; case IKS_AST_ATRIBUICAO: /*Quando chegarmos no nó atribuição já teremos os nós filhos definidos: leftson e rightson filho direito do filho da esquerda*/ LeftSon = stack_pointer->disc->scc[0]; RightSon = stack_pointer->disc->scc[1]; Left_RightGrandSon = LeftSon->scc[1]; if(stack_pointer->disc->scc[0]->type == IKS_AST_VETOR_INDEXADO){ Variable = stack_pointer->disc->scc[0]->scc[0]; GlobalSearch = list_lookup(global,Variable->symbol->text); LocalSearch = list_lookup(local,Variable->symbol->text); VectorialSearch = list_lookup(global_vet,Variable->symbol->text); FunctionSearch = list_lookup(function_list,Variable->symbol->text); if(GlobalSearch !=NULL){ printf("-> Identificador de vetor foi declarado como variavel global (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); } else if(FunctionSearch !=NULL){ printf("-> Identificador de vetor foi declarado como funcao (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_FUNCTION); } else if(LocalSearch !=NULL){ printf("-> Identificador de vetor foi declarado como variavel local (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VARIABLE); } else{ Left_RightGrandSon->node_type = coertion(IKS_INT,Left_RightGrandSon->node_type); stack_pointer->disc->node_type = inference(LeftSon->node_type,RightSon->node_type); /* atribuição de tipo ao nodo indexado*/ } } else if(stack_pointer->disc->scc[0]->type == IKS_AST_IDENTIFICADOR){ Variable = stack_pointer->disc->scc[0]; GlobalSearch = list_lookup(global,Variable->symbol->text); LocalSearch = list_lookup(local,Variable->symbol->text); VectorialSearch = list_lookup(global_vet,Variable->symbol->text); FunctionSearch = list_lookup(function_list,Variable->symbol->text); if(VectorialSearch !=NULL){ printf("-> Identificador de variavel foi declarado como vetor (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_VECTOR); } else if(FunctionSearch !=NULL){ printf("-> Identificador de variavel foi declarado como funcao (linha %d)\n", getLineNumber()-1); exit(IKS_ERROR_FUNCTION); } else stack_pointer->disc->node_type = coertion(LeftSon->node_type,RightSon->node_type); } break; case IKS_AST_INPUT: LeftSon = stack_pointer->disc->scc[0]; if(LeftSon->type != IKS_AST_IDENTIFICADOR){ printf("O parametro do comando input (linha %d) nao se trata de um identificador\n",getLineNumber()-1); exit(IKS_ERROR_WRONG_PAR_INPUT); } else stack_pointer->disc->node_type = LeftSon->node_type; break; case IKS_AST_OUTPUT: LeftSon = stack_pointer->disc->scc[0]; if(LeftSon->node_type == IKS_CHAR){ printf("O parametro do comando output (linha %d) deve ser literal string ou expressao\n",getLineNumber()-1); exit(IKS_ERROR_WRONG_PAR_OUTPUT); } else stack_pointer->disc->node_type = LeftSon->node_type; break; case IKS_AST_RETURN: LeftSon = stack_pointer->disc->scc[0]; if(InUseFunction->type != LeftSon->node_type){ if((LeftSon->node_type == IKS_CHAR) ||(LeftSon->node_type == IKS_STRING)){ printf("A variavel do comando return deve ter o mesmo tipo da funcao %s (linha %d)\n",InUseFunction->text,getLineNumber()-1); exit(IKS_ERROR_WRONG_PAR_RETURN); } else{ InUseFunction->type = coertion(InUseFunction->type,LeftSon->node_type); } stack_pointer->disc->node_type = LeftSon->node_type; } else{ stack_pointer->disc->node_type = LeftSon->node_type; } break; } stack_pointer= stack_pointer->next; return StackPopCommands(stack_pointer,global,global_vet,local,function_list, AllParams); } }