Predictive_Parser::Predictive_Parser(CFG *grammar) { //init vars this->grammar = grammar; first = new map<string, set<string>*> (); follow = new map<string, set<string>*> (); subset_first = new map<pair<string,int>,set<string>*>(); parse_table = new Parse_Table_Entry*[grammar->get_nonterminals()->size()]; //size = size of terminals + 1 (input end marker) for (unsigned int i = 0; i < grammar->get_nonterminals()->size(); ++i) parse_table[i] = new Parse_Table_Entry[grammar->get_terminals()->size() + 1]; //calculate first set<string>* nonterminals = grammar->get_nonterminals(); for (set<string>::iterator it = nonterminals->begin(); it != nonterminals->end(); ++it) { calc_first(*it); } //calculate follow calc_follow(); //generate parsing table generate_table(); }
void generate_tables(int key_length, char *domain_tag, unsigned int t_length, unsigned int ch_length, int tables, int threads) { generate_start(key_length, domain_tag, t_length, ch_length, tables, threads); int i ; for(i = 0 ; i < tables ; i++){ generate_table(i); } }
void kuz_init() { #if(!USE_ASM) #if(USE_GALOIS) galois_init(); #endif #if(USE_MUL_TABLE) generate_mul_table(); #endif #if(USE_TABLES) generate_table(kuz_pil_enc128, generate_pil_enc128); generate_table(kuz_l_dec128, generate_l_dec128); generate_table(kuz_pil_dec128, generate_pil_dec128); #endif #endif calc_used_memory_count(); }
int main(int argc, char **argv){ int N = atoi(argv[1]); printf("Generating an %d x %d table\n", N, N); int *table = (int *)calloc(N,N*sizeof(int)); generate_table(table, N); save_table(table, N); free(table); }
bool table_stub(serverPage* pPage, muRequest* pRequest) { wxString sHTML = generate_table(); pPage->Clear(); pPage->SetTitle( wxT("Test Table Class") ); pPage->AddToBody(HTML::CENTER(HTML::HEADING1(wxT("Test Table Class")))); *pPage += sHTML; *pPage += HTML::HR() ; *pPage += HTML::LINK(wxT("Go Back To Home"), wxT("/index.html")); pPage->SetStyleSheet( sheet ); return true; }
int main(int argc, char **argv) { char mode = 'i'; if (argc == 2) mode = *argv[1]; switch (mode) { case 'i': generate_include(); break; case 'f': generate_func(); break; case 't': generate_table(); break; case 'h': generate_header(); break; default: abort(); } return 0; }
/* Event handler for tool 'parsetablegen' */ ATerm parsetablegen_handler(int conn, ATerm term) { ATerm in, out; /* We need some temporary variables during matching */ char *s0; ATerm t0; if(ATmatch(term, "rec-terminate(<term>)", &t0)) { rec_terminate(conn, t0); return NULL; } if(ATmatch(term, "rec-eval(generate-table(<term>,<str>))", &t0, &s0)) { return generate_table(conn, t0, s0); } if(ATmatch(term, "rec-do(signature(<term>,<term>))", &in, &out)) { ATerm result = parsetablegen_checker(conn, in); if(!ATmatch(result, "[]")) ATfprintf(stderr, "warning: not in input signature:\n\t%\n\tl\n", result); return NULL; } ATerror("tool parsetablegen cannot handle term %t", term); return NULL; /* Silence the compiler */ }
int main() { //generate_table(); //count = get_tokens(); //int j=0,i; int i=0,j; memset(Stack,'0',sizeof(Stack)); // for(i=0;i<300;i++) // memset(Rules[i],0,sizeof(Rules[i])); //char temp[200][30]; //char temp[200][30]; //for(i=0;i<200;i++) // memset(temp[i],'\0',sizeof(temp[i])); //for(i=100;i<127;i++) // j=fill_line(temp,127); //printf("%d",hash_nonterm("variables")); //j=fill_line(temp,108); // j=fill_line(temp,109); // for(i=100;i<128;i++) //j=fill_line(temp,i); int x,y; int count=get_tokens(); for(i=0;i<count;i++) { hashedTokens[i]=hash_tokens(Tokens[i]); // printf("%s %d\n",Tokens[i],hashedTokens[i]); } fout=fopen("Checkfile.txt","w+"); generate_table(); fclose(fout); /*for(i=0;i<59;i++) { for(j=0;j<68;j++) fprintf(fout,"%d ",Table[i][j]); fprintf(fout,"\n"); }*/ readRules(); fout=fopen("Output.txt","w+"); int tokNo=0,grammarNo,p; push(100); int loopcount=0,currentHash; while(top<1001) { loopcount++; if(top==1001 && tokNo==count) return 0; else if(top==1001 && tokNo!=count) return -1; else if(top!=1001 && tokNo==count) return -1; printStack(); fprintf(fout,"table value is %d where non terminal is %d and token is %d and token no is %d\n",Table[head()-100][hashedTokens[tokNo]+1],head(),hashedTokens[tokNo]+1,tokNo); grammarNo=Table[head()-100][hashedTokens[tokNo]+1]-1; //PUSHING //pop() p=0; while(Rules[grammarNo][p++]!=-1); p--; pop(); for(i=p-1;i>0;i--) { fprintf(fout,"pushing %d\n",Rules[grammarNo][i]); push(Rules[grammarNo][i]); } if(head()==67) { fprintf(fout,"Popping Ebsilon\n"); pop(); } while(1 && tokNo<count && top<1001) { if(head()<100 && head()>=0) { fprintf(fout,"head inside small loop is %d and token is %d\n",head(),hashedTokens[tokNo]); if(head()==hashedTokens[tokNo]) { fprintf(fout,"Poppping %d\n",head()); pop(); tokNo++; } else { fprintf(fout,"Wrong Terminal \n"); pop(); tokNo++; } } else break; } } return 0; }
/*Cargar desde un archivo*/ void cargarFile(GtkWidget *widget, gpointer user_data){ int cantidad; cantidad = tamanio; int** matriz; filename=gtk_file_chooser_get_filename (fileChooser); printf("leer floyd \n"); printf("nombre archivo %s\n", filename); FILE *fp; fp = fopen(filename, "r"); char ch; char* palabra; int largo = 0; palabra = (char*)calloc(1, sizeof(char)); int i,j; int numero; int max; int nodo1; int nodo2; while((ch=fgetc(fp)) != '\n'){ largo++; palabra = (char*) realloc(palabra,largo * sizeof(char)); palabra[largo-1] = ch; } largo = 0; numero = atoi(palabra); printf("tamanio %d\n",numero); int cuantas=0; gtk_spin_button_set_value(spinNodos,numero); show_nodes(); int f=0; while((ch=fgetc(fp)) != '\n'){ if (ch == ',') { printf("nom:%s\n", palabra); gtk_entry_set_text(nombres[f],palabra); largo =0; f++; } else{ largo++; palabra = (char*) realloc(palabra,largo * sizeof(char)); palabra[largo-1] = ch; } } printf("nom:%s\n", palabra); gtk_entry_set_text(nombres[f],palabra); largo = 0; generate_table(); for (i = 0; i < numero; ++i) { for (j = 0; j < numero; ++j) { gtk_entry_set_text(distancias[i][j],g_strdup_printf("%d",9999)); } } while(!feof(fp)) { ch = fgetc(fp); if(ch == '\n' ){ printf("%d",atoi(palabra)); printf("\n"); // matriz[nodo1-1][nodo2-1] =atoi(palabra); gtk_entry_set_text(distancias[nodo2-1][nodo1-1],g_strdup_printf("%d",atoi(palabra))); largo=0; palabra = (char*) realloc(palabra,1); } else if (ch == '-'){ fseek( fp, ftell(fp)-2, SEEK_SET ); nodo1 = fgetc(fp)- '0'; printf("nodo1:%d - ",nodo1); fgetc(fp); largo=0; palabra = (char*) realloc(palabra,0); } else if (ch == '='){ fseek( fp, ftell(fp)-2, SEEK_SET ); nodo2 = fgetc(fp)- '0'; printf("nodo2:%d - ",nodo2); fgetc(fp); largo=0; palabra = (char*) realloc(palabra,0); } else{ largo++; palabra = (char*) realloc(palabra,largo * sizeof(char)); palabra[largo-1] = ch; } } fclose(fp); printf("\n"); }