int main(int argc, char ** argv){ if (argc < 4){ printf("USAGE: naive_multiply input_file_1.ext input_file_2.ext output_file.ext\n"); printf("where ext is either hdf5 or txt\n"); return 0; } std::string in1_str(argv[1]);//convert char* -> string std::string in2_str(argv[2]); std::string out_str(argv[3]); std::string in1_ext= GetFileExtension(in1_str);//extract file extention std::string in2_ext= GetFileExtension(in2_str); std::string out_ext= GetFileExtension(out_str); std::vector<int> in1(0,0);//doesn't matter what we initialize to, read will clear it std::vector<int> in2(0,0); std::vector<int> out(0,0); //read first input file if(in1_ext.compare("txt")==0){ text_read(in1_str,in1); }else{// if(in1_ext.compare("hdf5")==0){ hdf5_read(in1_str,in1);//hdf5 read }//else{ // std::cout << in1_ext << " files not supported!!" << std::endl; // return 1; //} //read second input file if(in2_ext.compare("txt")==0){ text_read(in2_str,in2); }else{// if(out_ext.compare("hdf5")==0){ hdf5_read(in2_str,in2);//hdf5 read }//else{ // std::cout << in2_ext << " files not supported!" << std::endl; // return 1; //} clock_t start=clock(); //do the matrix multiply multiply(in1,in2,out); std::cout << (in1[0]) << " " << (clock()-start) << std::endl; //write the output file if(out_ext.compare("txt")==0){ text_write(out_str,out); }else if(out_ext.compare("hdf5")==0){ hdf5_write(out_str,out);//hdf5 write }else{ std::cout << out_ext << " files not supported" << std::endl; return 1; } return 0; }
static char *full_weekday_name(char *buf, char *end, const struct tm *t) { if (t->tm_wday < 0 || t->tm_wday > 6) return NULL; static char *names[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; return out_str(buf, end, names[t->tm_wday]); }
static char *abbreviated_month_name(char *buf, char *end, const struct tm *t) { if (t->tm_mon < 0 || t->tm_mon > 11) return NULL; static char *names[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; return out_str(buf, end, names[t->tm_mon]); }
static char *full_month_name(char *buf, char *end, const struct tm *t) { if (t->tm_mon < 0 || t->tm_mon > 11) return NULL; static char *names[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return out_str(buf, end, names[t->tm_mon]); }
static char get_dynamic(struct args_t *args) { uint32_t i = 0; uint16_t size = 1000; if (size == 0) out_c('0'); while (i++ < size) out_str(array); return 1; }
// APM Set Power State static void handle_155307(struct bregs *regs) { if (regs->bx != 1) { set_success(regs); return; } switch (regs->cx) { case 1: out_str("Standby"); break; case 2: out_str("Suspend"); break; case 3: apm_shutdown(); break; } set_success(regs); }
/** Encodes the given data as base64 and returns the encoded string. */ std::string base64::encode(const void* data, size_t length) { int out_len = 0; char* out = NibbleAndAHalf_base64(data, length, &out_len); if (out == NULL) { throw std::runtime_error("base64() returned a NULL string. This is most likely due to malloc() not being able to allocate enough memory."); } std::string out_str(out, out_len); free(out); // since we're in C ;) return out_str; }
std::string DeflateFrame::Inflate(const std::string& in) { /* * inflate the incoming payload */ std::string tin(in); tin.append(2, '\0'); tin.append(2, '\xff'); //z_stream zs_in; zs_in.next_in = (uint8_t*)tin.c_str(); zs_in.avail_in = tin.length(); int32_t out_buf_len = 32; uint8_t* out_buf = (uint8_t*)malloc(out_buf_len); zs_in.avail_out = out_buf_len; zs_in.next_out = out_buf; while (1) { int n = inflate(&zs_in, Z_SYNC_FLUSH); switch (n) { case Z_NEED_DICT: case Z_STREAM_ERROR: case Z_DATA_ERROR: case Z_MEM_ERROR: /* * screwed.. close the connection... * we will get a destroy callback to take care * of closing nicely */ free(out_buf); throw std::runtime_error("zlib error inflate " + std::to_string(n) + ", " + zs_in.msg); } if (zs_in.avail_out) break; out_buf_len *= 2; out_buf = (unsigned char *)realloc(out_buf, out_buf_len); if (!out_buf) { throw std::runtime_error("Out of memory"); } zs_in.next_out = out_buf + (out_buf_len/2); zs_in.avail_out = out_buf_len/2; } /* rewrite the buffer pointers and length */ std::string out_str((const char*)out_buf, out_buf_len - zs_in.avail_out); free(out_buf); return out_str; }
std::string FormatString(const char* format, ...) { va_list arguments; char *va_str; va_start(arguments, format); vasprintf(&va_str, format, arguments); va_end(arguments); std::string out_str(va_str); free(va_str); return out_str; }
/* * GOTO statement */ void parse_goto(TOKEN *first_token) { TOKEN token; out_white_space(first_token); out_str("goto"); if (get_token(&token) != IDENTIFIER) parse_error("Illegal GOTO label"); else { out_token(&token); check_eol(); } }
/* * RETURN statement * Handles RETURN [ <expression> ] ; */ void parse_return(TOKEN *first_token) { TOKEN token; int token_class; out_white_space(first_token); out_str("return"); token_class = parse_expression(&token); if (token_class != END_OF_LINE) parse_error("';' expected"); else out_token(&token); }
/* * ENABLE or DISABLE statement */ void parse_int_ctl(TOKEN *first_token) { TOKEN token; int token_class; out_token(first_token); out_str("()"); token_class = get_token(&token); if (token_class != END_OF_LINE) { parse_error("';' expected"); return; } out_token(&token); }
/* * IF statement */ void parse_if(TOKEN *first_token) { TOKEN token; out_white_space(first_token); out_str("if ("); if ((parse_expression(&token) != RESERVED) || (token.token_type != THEN)) parse_error("Missing THEN in IF statement"); else { out_pre_line(&token); out_char(')'); out_white_space(&token); } }
std::string DeflateFrame::Deflate(const std::string& in) { /* * deflate the outgoing payload */ //z_stream zs_out; zs_out.next_in = (uint8_t*)in.c_str(); zs_out.avail_in = in.length(); int32_t out_buf_len = 32; uint8_t* out_buf = (uint8_t*)malloc(out_buf_len); zs_out.avail_out = out_buf_len; zs_out.next_out = out_buf; while (1) { int n = deflate(&zs_out, Z_SYNC_FLUSH); if (n == Z_STREAM_ERROR) { /* * screwed.. close the connection... we will * get a destroy callback to take care of * closing nicely */ free(out_buf); throw std::runtime_error("zlib error deflate" + std::to_string(n) + ", " + zs_in.msg); } if (zs_out.avail_out) break; out_buf_len *= 2; out_buf = (uint8_t *)realloc(out_buf, out_buf_len); if (!out_buf) { throw std::runtime_error("Out of memory"); } zs_out.next_out = out_buf + (out_buf_len/2); zs_out.avail_out = out_buf_len/2; } std::string out_str((const char*)out_buf, out_buf_len - zs_out.avail_out - 4); //std::string o1 = std::string((const char*)out_buf, out_buf_len - zs_out.avail_out); //printf("%d:%s\n%d:%s\n", out_str.length(), out_str.c_str(), o1.length(), o1.c_str()); free(out_buf); return out_str; }
/** Decodes the given base64 string and returns the decoded string. */ std::string base64::decode(const char* data, size_t length) { /* Don't attempt to decode strings that are shorter than 2 characters, * as this would fail anyway in unbase64(). Catching it here leaves * only memory issues to be returned by unbase64(). */ if (length < 2) { throw std::runtime_error("Base64-decoding a string with only one character makes no sense."); } int out_len = 0; char* out = (char*)NibbleAndAHalf_unbase64(data, length, &out_len); if (out == NULL) { throw std::runtime_error("unbase64() returned a NULL string. This is most likely due to malloc() not being able to allocate enough memory."); } std::string out_str(out, out_len); free(out); // since we're in C, again! return out_str; }
int Service::call_are_you_there (Test::Callback_ptr callback) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Service, calling are_you_there\n")); const int iterations = 10; int exception_count = 0; for (int i = 0; i != iterations; ++i) { CORBA::String_var outstr; CORBA::String_out out_str (outstr.out ()); try { (void) callback->are_you_there (out_str); } catch (const CORBA::Exception&) { exception_count++; } ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Service, answer = %C\n", outstr.in ())); } return exception_count; }
/* * Parse statement starting with an identifier. * Possibilities include: * Assignment * Procedure statement */ void parse_identifier(TOKEN *first_token) { TOKEN token, next_token; TOKEN param_token, attrib_token, type_token; int token_class, next_token_class; DECL *decl_list, *extra_decl_list; PARAM_LIST *param_list, *param_ptr; DECL_MEMBER *decl_ptr; DECL_ID *decl_id; BOOLEAN extern_proc, got_type, interrupt_proc; char *tmp_text_ptr; /* Check for label or procedure */ tmp_text_ptr = text_ptr; token_class = get_token(&token); if (token_class == LABEL) { /* Determine if label or procedure definition */ next_token_class = get_token(&next_token); if ((next_token_class == RESERVED) && (next_token.token_type == PROCEDURE)) { /* * Procedure - Check for parameter list */ param_list = NULL; token_class = get_token(¶m_token); if (token_class == LEFT_PAREN) { /* Yes - get parameter list */ get_param_list(¶m_list); /* Get token after parameter list */ token_class = get_token(&attrib_token); } else /* No param list - save as attribute */ token_copy(¶m_token, &attrib_token); out_white_space(first_token); extern_proc = FALSE; interrupt_proc = FALSE; got_type = (token_class == RESERVED) && (attrib_token.token_type >= BYTE) && (attrib_token.token_type <= SELECTOR); if (got_type) { /* * Process [ <type> ] */ token_copy(&attrib_token, &type_token); token_class = get_token(&attrib_token); } while (token_class == RESERVED) { if (attrib_token.token_type == INTERRUPT) { /* * Process [ <interrupt> ] */ interrupt_proc = TRUE; token_class = get_token(&attrib_token); if (token_class == NUMERIC) /* Interrupt number */ token_class = get_token(&attrib_token); } else /* * Process [ EXTERNAL | { [ PUBLIC ] [ REENTRANT ] } ] */ if (attrib_token.token_type == EXTERNAL) { out_str("extern"); out_must_white(&attrib_token); extern_proc = TRUE; token_class = get_token(&attrib_token); } else if ((attrib_token.token_type == PUBLIC) || (attrib_token.token_type == REENTRANT)) { do { if (attrib_token.token_type == PUBLIC) { /* Ignore for now */ token_class = get_token(&attrib_token); } else if (attrib_token.token_type == REENTRANT) { /* Ignore for now */ token_class = get_token(&attrib_token); } else break; } while (token_class == RESERVED); } else break; } if (token_class != END_OF_LINE) { parse_error("';' expected"); return; } if (interrupt_proc && !extern_proc) parse_warning("INTERRUPT procedure declared"); /* Create declaration for procedure */ get_element_ptr(&decl_ptr); get_var_ptr(&decl_ptr->name_list); /* Type = PROCEDURE */ get_token_ptr(&decl_ptr->type); token_copy(&next_token, decl_ptr->type); /* Name = procedure name */ get_token_ptr(&decl_ptr->name_list->name); token_copy(first_token, decl_ptr->name_list->name); /* Flag if parameter list */ if (param_list) decl_ptr->initialization = DATA; /* Add it to context */ add_to_context(decl_ptr); if (got_type) { /* Output procedure type */ out_token_name(&type_token); out_must_white(&type_token); } /* Output procedure name */ out_token_name(first_token); if (extern_proc) { out_str("()"); if (param_list) /* Parse parameter declarations */ parse_param_list(param_list, &decl_list, &extra_decl_list); out_char(';'); /* Eat closing 'END [<proc name>];' */ token_class = get_token(&token); if ((token_class != RESERVED) || (token.token_type != END)) { parse_error("END expected"); return; } out_white_space(&token); token_class = get_token(&token); if (token_class == IDENTIFIER) { token_class = get_token(&token); } if (token_class != END_OF_LINE) { parse_error("';' expected"); } return; } else if (param_list) { out_token(¶m_token); /* Output parameter list */ param_ptr = param_list; while (param_ptr) { out_token(¶m_ptr->param); param_ptr = param_ptr->next_param; if (param_ptr) out_char(','); } out_char(')'); /* Parse parameter declarations */ parse_param_list(param_list, &decl_list, &extra_decl_list); /* Output declarations */ if (decl_list) { out_decl(decl_list); /* Add declarations to context */ add_decl_to_context(decl_list); } out_str("\n{"); /* } for dumb vi */ if (extra_decl_list) { out_decl(extra_decl_list); /* Add declarations to context */ add_decl_to_context(extra_decl_list); } /* Discard declarations */ free_decl(decl_list); free_decl(extra_decl_list); } else /* No parameter list */ out_str("()\n{"); /* } for dumb vi */ /* Create new context */ new_context(PROCEDURE, first_token); /* Parse statements to END */ parse_to_end(); /* Pop procedure context */ pop_context(); } else { /* * Label - add label name */ out_token(first_token); /* Add colon */ out_token(&token); /* Is this a defined label or a module? */ if (find_symbol(first_token, &decl_ptr, &decl_id)) { if (decl_ptr->type->token_class == LABEL) { /* Label - new context */ new_context(MODULE, first_token); parse_statement(&next_token); pop_context(); } else { parse_error("Illegal label name"); return; } } else parse_statement(&next_token); } return; } /* Assignment statement */ text_ptr = tmp_text_ptr; token_copy(first_token, &token); token_class = parse_variable(&token, &decl_ptr, &decl_id); /* Check for multiple assignments */ while (token_class == COMMA) { /* Print ' =' instead of ',' */ out_str(" ="); out_white_space(&token); /* Get identifier part of next assignment variable */ token_class = get_token(&token); if (token_class != IDENTIFIER) { parse_error("Illegal assignment"); return; } /* Parse remainder of variable (if any) */ token_class = parse_variable(&token, &decl_ptr, &decl_id); } if (token_class == OPERATOR) { if (token.token_type != EQUAL) { parse_error("Illegal use of identifier"); return; } out_token(&token); /* Check for POINTER assignment */ if (decl_ptr->type->token_type == POINTER) { /* Yes - cast it */ out_str(" ("); out_str(TYPE_POINTER); out_str(" *) "); } if (parse_expression(&token) != END_OF_LINE) parse_error("';' expected"); else out_token(&token); return; } else if (token_class != LABEL) { parse_error("Illegal use of identifier"); return; } }
int main(int argc, char* argv[]) { // spit out error if less then two elements if (argc < 3) { usage(argv[0]); exit(1); } // Load ppm image of floor textures to use Image<Color> floor_texture; std::string image_file = std::string(argv[1]); std::cout << "Loading " << argv[1] << std::endl; floor_texture.Load(image_file); // Load in location of furniture std::ifstream in_str(argv[2]); // Is this file is good if (!in_str.good()) { std::cerr << "Can't open " << argv[2] << " to read.\n"; exit(1); } //Load into vector as furnature objects std::vector<Furniture> furnitureVec; int itemCount = 0; loadFurnitureState(in_str,furnitureVec, itemCount); // INITAL RANDOMIZATION if(std::string(argv[3])=="start"){ std::cout << "Initial Randomization" << std::endl; setupInitalRandomPos(furnitureVec,floor_texture); // is file good to write std::ofstream out_str(argv[2]); if (!out_str.good()) { std::cerr << "Can't open " << argv[4] << " to write.\n"; exit(1); } saveFurnitureState(out_str,furnitureVec, itemCount); return 0; } // Randomly moves my furniture until they are in good starting positions std::cout <<"OLD COST " <<calculateCost(furnitureVec, floor_texture) << std::endl; std::cout << furnitureVec.size() <<std::endl; double current_cost = calculateCost(furnitureVec, floor_texture); unsigned int HEAT = 100; unsigned int SAVES = 0; while(0 < HEAT){ for(int i = 0; i < furnitureVec.size(); i ++){ Furniture curItem = furnitureVec[i]; float orginal_x = curItem.getPos().x; float orginal_y = curItem.getPos().y; // try and jitter cur item, this will change the value deskMove(furnitureVec[i],HEAT,floor_texture); // check new cost double new_cost = calculateCost(furnitureVec, floor_texture); // I got a better cost if(new_cost < current_cost){ current_cost = new_cost; // I did worst }else{ // place item back furnitureVec[i].setPos(orginal_x,orginal_y); } }//for HEAT--; if(HEAT%5 == 0){ std::string save_str = convertInt(SAVES); save_str = "saved_state_" + save_str + ".st"; const char *cstr = save_str.c_str(); std::ofstream out_str(cstr); if (!out_str.good()) { std::cerr << "Can't open " << argv[2] << " to write.\n"; exit(1); } saveFurnitureState(out_str,furnitureVec, itemCount); out_str.close(); SAVES++; }//sav }//while }//main
static char doGet(struct args_t *args) { out_str("Hello World!"); return 1; }
/* skelout - write out one section of the skeleton file * * Description * Copies skelfile or skel array to stdout until a line beginning with * "%%" or EOF is found. */ void skelout (void) { char buf_storage[MAXLINE]; char *buf = buf_storage; bool do_copy = true; /* "reset" the state by clearing the buffer and pushing a '1' */ if(sko_len > 0) sko_peek(&do_copy); sko_len = 0; sko_push(do_copy=true); /* Loop pulling lines either from the skelfile, if we're using * one, or from the skel[] array. */ while (skelfile ? (fgets (buf, MAXLINE, skelfile) != NULL) : ((buf = (char *) skel[skel_ind++]) != 0)) { if (skelfile) chomp (buf); /* copy from skel array */ if (buf[0] == '%') { /* control line */ /* print the control line as a comment. */ if (ddebug && buf[1] != '#') { if (buf[strlen (buf) - 1] == '\\') out_str ("/* %s */\\\n", buf); else out_str ("/* %s */\n", buf); } /* We've been accused of using cryptic markers in the skel. * So we'll use emacs-style-hyphenated-commands. * We might consider a hash if this if-else-if-else * chain gets too large. */ #define cmd_match(s) (strncmp(buf,(s),strlen(s))==0) if (buf[1] == '#') { /* %# indicates comment line to be ignored */ } else if (buf[1] == '%') { /* %% is a break point for skelout() */ return; } else if (cmd_match (CMD_PUSH)){ sko_push(do_copy); if(ddebug){ out_str("/*(state = (%s) */",do_copy?"true":"false"); } out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : ""); } else if (cmd_match (CMD_POP)){ sko_pop(&do_copy); if(ddebug){ out_str("/*(state = (%s) */",do_copy?"true":"false"); } out_str("%s\n", buf[strlen (buf) - 1] =='\\' ? "\\" : ""); } else if (cmd_match (CMD_IF_REENTRANT)){ sko_push(do_copy); do_copy = reentrant && do_copy; } else if (cmd_match (CMD_IF_NOT_REENTRANT)){ sko_push(do_copy); do_copy = !reentrant && do_copy; } else if (cmd_match(CMD_IF_BISON_BRIDGE)){ sko_push(do_copy); do_copy = bison_bridge_lval && do_copy; } else if (cmd_match(CMD_IF_NOT_BISON_BRIDGE)){ sko_push(do_copy); do_copy = !bison_bridge_lval && do_copy; } else if (cmd_match (CMD_ENDIF)){ sko_pop(&do_copy); } else if (cmd_match (CMD_IF_TABLES_SER)) { do_copy = do_copy && tablesext; } else if (cmd_match (CMD_TABLES_YYDMAP)) { if (tablesext && yydmap_buf.elts) outn ((char *) (yydmap_buf.elts)); } else if (cmd_match (CMD_DEFINE_YYTABLES)) { if ( tablesext ) out_str( "#define YYTABLES_NAME \"%s\"\n", tablesname ? tablesname : "yytables" ); } else if (cmd_match (CMD_IF_CPP_ONLY)) { /* only for C++ */ sko_push(do_copy); do_copy = C_plus_plus; } else if (cmd_match (CMD_IF_C_ONLY)) { /* %- only for C */ sko_push(do_copy); do_copy = !C_plus_plus; } else if (cmd_match (CMD_IF_C_OR_CPP)) { /* %* for C and C++ */ sko_push(do_copy); do_copy = true; } else if (cmd_match (CMD_NOT_FOR_HEADER)) { /* %c begin linkage-only (non-header) code. */ OUT_BEGIN_CODE (); } else if (cmd_match (CMD_OK_FOR_HEADER)) { /* %e end linkage-only code. */ OUT_END_CODE (); } else { flexfatal (_("bad line in skeleton file")); } } else if (do_copy) outn (buf); } /* end while */ }
static char doGet(struct args_t *args) { int cpt = 0; FOR_EACH_CONN(conn, { out_str("Connection: "); out_uint(cpt++); out_str("\n"); out_str("\tport: "); out_uint(UI16(conn->port)); out_str("\n"); out_str("\ttcp_state: "); out_uint(conn->tcp_state); out_str("\n"); out_str("\toutput_handler: "); if(conn->output_handler) out_str("****\n"); else out_str("NULL\n"); out_str("\tsomething to send: "); out_uint(something_to_send(conn)); out_str("\n"); }) return 1;
/* * ELSE statement */ void parse_else(TOKEN *first_token) { out_white_space(first_token); out_str("else"); }
void ntod (void) { int *accset, ds, nacc, newds; int sym, hashval, numstates, dsize; int num_full_table_rows=0; /* used only for -f */ int *nset, *dset; int targptr, totaltrans, i, comstate, comfreq, targ; int symlist[CSIZE + 1]; int num_start_states; int todo_head, todo_next; struct yytbl_data *yynxt_tbl = 0; flex_int32_t *yynxt_data = 0, yynxt_curr = 0; /* Note that the following are indexed by *equivalence classes* * and not by characters. Since equivalence classes are indexed * beginning with 1, even if the scanner accepts NUL's, this * means that (since every character is potentially in its own * equivalence class) these arrays must have room for indices * from 1 to CSIZE, so their size must be CSIZE + 1. */ int duplist[CSIZE + 1], state[CSIZE + 1]; int targfreq[CSIZE + 1] = {0}, targstate[CSIZE + 1]; /* accset needs to be large enough to hold all of the rules present * in the input, *plus* their YY_TRAILING_HEAD_MASK variants. */ accset = allocate_integer_array ((num_rules + 1) * 2); nset = allocate_integer_array (current_max_dfa_size); /* The "todo" queue is represented by the head, which is the DFA * state currently being processed, and the "next", which is the * next DFA state number available (not in use). We depend on the * fact that snstods() returns DFA's \in increasing order/, and thus * need only know the bounds of the dfas to be processed. */ todo_head = todo_next = 0; for (i = 0; i <= csize; ++i) { duplist[i] = NIL; symlist[i] = false; } for (i = 0; i <= num_rules; ++i) accset[i] = NIL; if (trace) { dumpnfa (scset[1]); fputs (_("\n\nDFA Dump:\n\n"), stderr); } inittbl (); /* Check to see whether we should build a separate table for * transitions on NUL characters. We don't do this for full-speed * (-F) scanners, since for them we don't have a simple state * number lying around with which to index the table. We also * don't bother doing it for scanners unless (1) NUL is in its own * equivalence class (indicated by a positive value of * ecgroup[NUL]), (2) NUL's equivalence class is the last * equivalence class, and (3) the number of equivalence classes is * the same as the number of characters. This latter case comes * about when useecs is false or when it's true but every character * still manages to land in its own class (unlikely, but it's * cheap to check for). If all these things are true then the * character code needed to represent NUL's equivalence class for * indexing the tables is going to take one more bit than the * number of characters, and therefore we won't be assured of * being able to fit it into a YY_CHAR variable. This rules out * storing the transitions in a compressed table, since the code * for interpreting them uses a YY_CHAR variable (perhaps it * should just use an integer, though; this is worth pondering ... * ###). * * Finally, for full tables, we want the number of entries in the * table to be a power of two so the array references go fast (it * will just take a shift to compute the major index). If * encoding NUL's transitions in the table will spoil this, we * give it its own table (note that this will be the case if we're * not using equivalence classes). */ /* Note that the test for ecgroup[0] == numecs below accomplishes * both (1) and (2) above */ if (!fullspd && ecgroup[0] == numecs) { /* NUL is alone in its equivalence class, which is the * last one. */ int use_NUL_table = (numecs == csize); if (fulltbl && !use_NUL_table) { /* We still may want to use the table if numecs * is a power of 2. */ int power_of_two; for (power_of_two = 1; power_of_two <= csize; power_of_two *= 2) if (numecs == power_of_two) { use_NUL_table = true; break; } } if (use_NUL_table) nultrans = allocate_integer_array (current_max_dfas); /* From now on, nultrans != nil indicates that we're * saving null transitions for later, separate encoding. */ } if (fullspd) { for (i = 0; i <= numecs; ++i) state[i] = 0; place_state (state, 0, 0); dfaacc[0].dfaacc_state = 0; } else if (fulltbl) { if (nultrans) /* We won't be including NUL's transitions in the * table, so build it for entries from 0 .. numecs - 1. */ num_full_table_rows = numecs; else /* Take into account the fact that we'll be including * the NUL entries in the transition table. Build it * from 0 .. numecs. */ num_full_table_rows = numecs + 1; /* Begin generating yy_nxt[][] * This spans the entire LONG function. * This table is tricky because we don't know how big it will be. * So we'll have to realloc() on the way... * we'll wait until we can calculate yynxt_tbl->td_hilen. */ yynxt_tbl = calloc(1, sizeof (struct yytbl_data)); yytbl_data_init (yynxt_tbl, YYTD_ID_NXT); yynxt_tbl->td_hilen = 1; yynxt_tbl->td_lolen = (flex_uint32_t) num_full_table_rows; yynxt_tbl->td_data = yynxt_data = calloc(yynxt_tbl->td_lolen * yynxt_tbl->td_hilen, sizeof (flex_int32_t)); yynxt_curr = 0; buf_prints (&yydmap_buf, "\t{YYTD_ID_NXT, (void**)&yy_nxt, sizeof(%s)},\n", long_align ? "flex_int32_t" : "flex_int16_t"); /* Unless -Ca, declare it "short" because it's a real * long-shot that that won't be large enough. */ if (gentables) out_str_dec ("static const %s yy_nxt[][%d] =\n {\n", long_align ? "flex_int32_t" : "flex_int16_t", num_full_table_rows); else { out_dec ("#undef YY_NXT_LOLEN\n#define YY_NXT_LOLEN (%d)\n", num_full_table_rows); out_str ("static const %s *yy_nxt =0;\n", long_align ? "flex_int32_t" : "flex_int16_t"); } if (gentables) outn (" {"); /* Generate 0 entries for state #0. */ for (i = 0; i < num_full_table_rows; ++i) { mk2data (0); yynxt_data[yynxt_curr++] = 0; } dataflush (); if (gentables) outn (" },\n"); } /* Create the first states. */ num_start_states = lastsc * 2; for (i = 1; i <= num_start_states; ++i) { numstates = 1; /* For each start condition, make one state for the case when * we're at the beginning of the line (the '^' operator) and * one for the case when we're not. */ if (i % 2 == 1) nset[numstates] = scset[(i / 2) + 1]; else nset[numstates] = mkbranch (scbol[i / 2], scset[i / 2]); nset = epsclosure (nset, &numstates, accset, &nacc, &hashval); if (snstods (nset, numstates, accset, nacc, hashval, &ds)) { numas += nacc; totnst += numstates; ++todo_next; if (variable_trailing_context_rules && nacc > 0) check_trailing_context (nset, numstates, accset, nacc); } } if (!fullspd) { if (!snstods (nset, 0, accset, 0, 0, &end_of_buffer_state)) flexfatal (_ ("could not create unique end-of-buffer state")); ++numas; ++num_start_states; ++todo_next; } while (todo_head < todo_next) { targptr = 0; totaltrans = 0; for (i = 1; i <= numecs; ++i) state[i] = 0; ds = ++todo_head; dset = dss[ds]; dsize = dfasiz[ds]; if (trace) fprintf (stderr, _("state # %d:\n"), ds); sympartition (dset, dsize, symlist, duplist); for (sym = 1; sym <= numecs; ++sym) { if (symlist[sym]) { symlist[sym] = 0; if (duplist[sym] == NIL) { /* Symbol has unique out-transitions. */ numstates = symfollowset (dset, dsize, sym, nset); nset = epsclosure (nset, &numstates, accset, &nacc, &hashval); if (snstods (nset, numstates, accset, nacc, hashval, &newds)) { totnst = totnst + numstates; ++todo_next; numas += nacc; if (variable_trailing_context_rules && nacc > 0) check_trailing_context (nset, numstates, accset, nacc); } state[sym] = newds; if (trace) fprintf (stderr, "\t%d\t%d\n", sym, newds); targfreq[++targptr] = 1; targstate[targptr] = newds; ++numuniq; } else { /* sym's equivalence class has the same * transitions as duplist(sym)'s * equivalence class. */ targ = state[duplist[sym]]; state[sym] = targ; if (trace) fprintf (stderr, "\t%d\t%d\n", sym, targ); /* Update frequency count for * destination state. */ i = 0; while (targstate[++i] != targ) ; ++targfreq[i]; ++numdup; } ++totaltrans; duplist[sym] = NIL; } } numsnpairs += totaltrans; if (ds > num_start_states) check_for_backing_up (ds, state); if (nultrans) { nultrans[ds] = state[NUL_ec]; state[NUL_ec] = 0; /* remove transition */ } if (fulltbl) { /* Each time we hit here, it's another td_hilen, so we realloc. */ yynxt_tbl->td_hilen++; yynxt_tbl->td_data = yynxt_data = realloc (yynxt_data, yynxt_tbl->td_hilen * yynxt_tbl->td_lolen * sizeof (flex_int32_t)); if (gentables) outn (" {"); /* Supply array's 0-element. */ if (ds == end_of_buffer_state) { mk2data (-end_of_buffer_state); yynxt_data[yynxt_curr++] = -end_of_buffer_state; } else { mk2data (end_of_buffer_state); yynxt_data[yynxt_curr++] = end_of_buffer_state; } for (i = 1; i < num_full_table_rows; ++i) { /* Jams are marked by negative of state * number. */ mk2data (state[i] ? state[i] : -ds); yynxt_data[yynxt_curr++] = state[i] ? state[i] : -ds; } dataflush (); if (gentables) outn (" },\n"); } else if (fullspd) place_state (state, ds, totaltrans); else if (ds == end_of_buffer_state) /* Special case this state to make sure it does what * it's supposed to, i.e., jam on end-of-buffer. */ stack1 (ds, 0, 0, JAMSTATE); else { /* normal, compressed state */ /* Determine which destination state is the most * common, and how many transitions to it there are. */ comfreq = 0; comstate = 0; for (i = 1; i <= targptr; ++i) if (targfreq[i] > comfreq) { comfreq = targfreq[i]; comstate = targstate[i]; } bldtbl (state, ds, totaltrans, comstate, comfreq); } } if (fulltbl) { dataend (); if (tablesext) { yytbl_data_compress (yynxt_tbl); if (yytbl_data_fwrite (&tableswr, yynxt_tbl) < 0) flexerror (_ ("Could not write yynxt_tbl[][]")); } if (yynxt_tbl) { yytbl_data_destroy (yynxt_tbl); yynxt_tbl = 0; } } else if (!fullspd) { cmptmps (); /* create compressed template entries */ /* Create tables for all the states with only one * out-transition. */ while (onesp > 0) { mk1tbl (onestate[onesp], onesym[onesp], onenext[onesp], onedef[onesp]); --onesp; } mkdeftbl (); } free(accset); free(nset); }
/* * DO statement * Handles DO;, DO CASE, DO WHILE, and iterative DO */ void parse_do(TOKEN *first_token) { TOKEN token; int token_class; int case_line; char case_statement[MAX_TOKEN_LENGTH]; char case_output[MAX_CASE_STATEMENT_SIZE]; char var_string[MAX_TOKEN_LENGTH]; char *temp_out_string, *temp_out_string1; DECL_MEMBER *var_decl; DECL_ID *var_decl_id; /* Create new context */ new_context(DO, (TOKEN *) NULL); out_white_space(first_token); /* Determine what kind of DO statement */ token_class = get_token(&token); switch (token_class) { case END_OF_LINE : /* DO; */ out_white_space(&token); out_char('{'); /* } for dumb vi */ parse_to_end(); break; case IDENTIFIER : /* DO counter = start TO limit BY step */ out_str("for"); out_must_white(&token); out_char('('); /* Put full variable in var_string */ var_string[0] = '\0'; temp_out_string = out_string; out_string = var_string; token_class = parse_variable(&token, &var_decl, &var_decl_id); out_string = temp_out_string; /* Check for '=' */ if ((token_class != OPERATOR) || (token.token_type != EQUAL)) { parse_error("Missing '='"); pop_context(); return; } /* Send <ident> '=' <expr> */ out_str(var_string); out_token(&token); token_class = parse_expression(&token); if ((token_class != RESERVED) || (token.token_type != TO)) { parse_error("Missing TO"); pop_context(); return; } /* Send <ident> <= <limit> */ out_str("; "); out_str(var_string); out_str(" <="); token_class = parse_expression(&token); out_str("; "); /* Parse increment */ if ((token_class == RESERVED) && (token.token_type == BY)) { /* Send <ident> += <step> */ out_str(var_string); out_str(" +="); token_class = parse_expression(&token); } else { /* Send <ident>++ */ out_str(var_string); out_str("++"); } out_str(") {"); /* } for dumb vi */ out_white_space(&token); if (token_class != END_OF_LINE) { parse_error("BY or ';' expected"); pop_context(); return; } parse_to_end(); break; case RESERVED : switch (token.token_type) { case CASE : /* DO CASE <expr>; */ out_str("switch ("); if (parse_expression(&token) != END_OF_LINE) { parse_error("';' expected"); pop_context(); return; } out_white_space(&token); out_str(") {"); /* } for dumb vi */ case_line = 0; while (1) { /* Place case statement in out_string */ temp_out_string1 = out_string; case_output[0] = '\0'; out_string = case_output; (void) snprintf(case_statement, sizeof(case_statement), "case %d :", case_line++); token_class = parse_new_statement(); if (token_class == END_OF_FILE) { parse_error("Premature end-of-file"); exit(1); } if (token_class == END) { out_string = temp_out_string1; out_str(case_output); break; } out_string = temp_out_string1; out_white_space(first_token); out_str(case_statement); out_str(case_output); out_white_space(first_token); out_str("break;\n"); } break; case WHILE : /* DO WHILE <expr>; */ out_str("while ("); if (parse_expression(&token) != END_OF_LINE) { parse_error("';' expected"); pop_context(); return; } out_white_space(&token); out_str(") {"); /* } for dumb vi */ parse_to_end(); break; default: parse_error("Illegal DO clause"); pop_context(); return; } break; } /* End of context */ pop_context(); }
//main executable //assumes input file will be list of directed edges (u, v), where each line is of form: u v (no commas) int main(int argc, char* argv[]){ srand(clock()); ofstream adj_dif("adjacency_group_differences.txt"); //reads in arguments if(argc != 4 && argc != 5 && argc != 6 && argc != 7){cout << "Please include input file, k value, edge_add/label_swap, output type (overlap, edge_frequency, both, neither), [repeats, det_merge/nondet_merge] \n"; return 0;} ifstream in_str(argv[1]); int k = atoi(argv[2]); bool edge_add = false; string test_profs("edge_add"); if(argv[3] == test_profs){edge_add = true;} string output_type = "neither"; if(argc >= 5){output_type = argv[4];} int repeats = 1; if(argc >= 6){repeats = atoi(argv[5]);} string merge = "none"; if(argc >= 7){merge = argv[6];} //declares basic variables string s; vector<list<int> > Adjacency_graph; vector<list<int> > Final_graph; list<int> l; set<int> a_set; //reads in all the edges, and creates the adjacency graph while(!in_str.eof()){ in_str >> s; int source = atoi(s.c_str()); in_str >> s; int target = atoi(s.c_str()); while(Adjacency_graph.size() <= source){Adjacency_graph.push_back(l);} Adjacency_graph[source].push_back(target); } //declares more variables vector<set<int> > K_neighborhood; Create_K_Graph(Adjacency_graph, k, K_neighborhood); //Problem should be here! list<frequency_edge> edge_frequencies; vector<list<int> > K_neighborhood_lists; vector<int> clique_lookup; vector<int> group_size; vector<int> temp_vec; list<vector<int> >adj_groups; adj_groups.push_back(temp_vec); vector<vector<int> > same_cliques; vector<adj_itr> adj_map; //finds adjacency_groups for label-swapping algorithm if(!edge_add){ for(int i=0; i<K_neighborhood.size(); i++){ list<int> l; for(set<int>::iterator sitr = K_neighborhood[i].begin(); sitr != K_neighborhood[i].end(); sitr++){ l.push_back(*sitr); } K_neighborhood_lists.push_back(l); } kSort(K_neighborhood, adj_groups, adj_map); //super bad. fix later for(adj_itr itr1 = adj_groups.begin(); itr1 != adj_groups.end(); itr1++){ same_cliques.push_back(*itr1); } //assembles clique_lookup (allows constant time checking if two nodes are in all same cliques) //clique_lookup[i]=j if node i is in the jth element of adj_groups clique_lookup.insert(clique_lookup.begin(), K_neighborhood.size(), 0); group_size.insert(group_size.begin(), K_neighborhood.size(), 0); for(int i=0; i<same_cliques.size(); i++){ for(int j=0; j<same_cliques[i].size(); j++){ clique_lookup[same_cliques[i][j]] = i; group_size[same_cliques[i][j]] = same_cliques[i].size(); } } } for(int i=0; i<repeats; i++){ if(edge_add){ Final_graph.insert(Final_graph.begin(), K_neighborhood.size(), l); Edge_Adding(K_neighborhood, Final_graph, k); } else{ list<vector<int> > temp_adj_groups = adj_groups; if(merge == "nondet_merge"){ int maximum_difference = 5; //the maximum difference between any two adjacency groups that can be merged int total_difference = 1000000; //the sum of the differences between merged adjacency groups //non-deterministically merges similar adjacency groups //algorithm stops when all adjacency groups have difference greater than maximum_difference, or when sum of differences //of merged adjacency groups is greater than total_differences merge_similar_adj_groups(maximum_difference, total_difference, Adjacency_graph, K_neighborhood, temp_adj_groups, adj_map); } else if(merge == "det_merge"){ int maximum_difference = 5; //deterministically merges closest adjacency groups until all remaining groups have a difference greater than maximum difference deterministic_merge2(Adjacency_graph, K_neighborhood, temp_adj_groups, adj_map, maximum_difference); } ofstream merged_adj("merged_adj"); for(adj_itr i=temp_adj_groups.begin(); i!=temp_adj_groups.end(); i++){ for(int j=0; j<(*i).size(); j++){ merged_adj << (*i)[j] << " "; } merged_adj << endl; } Label_Swap(Adjacency_graph, Final_graph, temp_adj_groups); } //updates list of edge-frequencies based on Final_graph list<frequency_edge>::iterator freq_itr = edge_frequencies.begin(); for(int j=1; j<Final_graph.size(); j++){ Final_graph[j].sort(); list<int>::iterator itr = Final_graph[j].begin(); while(*itr < j && itr != Final_graph[j].end()){itr++;} while(itr != Final_graph[j].end()){ //cout << j << " " << *itr << endl; //cout << freq_itr -> edge_type; if(freq_itr != edge_frequencies.end() && freq_edge_less(*freq_itr, j, *itr)){freq_itr++;} else if(freq_itr != edge_frequencies.end() && freq_itr->node1==j && freq_itr->node2==*itr){(freq_itr->frequency)++;freq_itr++;itr++;} else{//adds new frequency edge to list //assigns type to frequency edge string edge_type = "original"; bool in_original = false; for(list<int>::iterator listitr = Adjacency_graph[j].begin(); listitr != Adjacency_graph[j].end(); listitr++){ if(*listitr == *itr){in_original = true; break;} } if(!in_original){ if(K_neighborhood[j].find(*itr) == K_neighborhood[j].end()){edge_type = "invalid";} else{edge_type = "valid";} } frequency_edge t(j, *itr, 1, edge_type); edge_frequencies.insert(freq_itr, t); itr++; } } } if(i+1 < repeats){Final_graph.clear();} } //outputs overlap from last Final_graph if(output_type == "both" || output_type == "overlap"){ ofstream overlap_out("overlap.txt"); vector<set<int> > New_K_neighborhood; Create_K_Graph(Final_graph, k, New_K_neighborhood); output_overlap(overlap_out, K_neighborhood, New_K_neighborhood); } //outputs frequencies from edge_frequencies //calculates relevant statistics if(output_type == "both" || output_type == "edge_frequency"){ ofstream freq_out("edge_frequencies.txt"); ofstream edge_out("all_edge_frequencies.txt"); vector<int> frequencies; while(frequencies.size() <= repeats){frequencies.push_back(0);} for(list<frequency_edge>::iterator itr=edge_frequencies.begin(); itr!=edge_frequencies.end(); itr++){ frequencies[itr->frequency]++; edge_out << itr->node1 << " " << itr->node2 << " " << itr->frequency << " " << itr -> edge_type << endl; } } //outputs last final_graph ofstream out_str("output.txt"); for(int i=0; i<Final_graph.size(); i++){ for(list<int>::iterator listitr = Final_graph[i].begin(); listitr != Final_graph[i].end(); listitr++){ out_str << i << " " << *listitr << endl; } } }
/* * Parse expression and output appropriate tokens. * Return token at end of expression. */ int parse_expression(TOKEN *token) { int token_class; int i, last_class, temp_class; DECL_MEMBER *id_type; DECL_ID *id_id; char *new_id; char string_const[MAX_TOKEN_LENGTH], octal_const[5]; last_class = OPERATOR; token_class = get_token(token); while (1) { switch (token_class) { case LEFT_PAREN : if (last_class != OPERATOR) { parse_error("Missing operator"); return ERROR; } /* Sub-expression */ out_token(token); /* Parse to closing right paren */ token_class = parse_expression(token); if (token_class != RIGHT_PAREN) { parse_error("Missing ')'"); return ERROR; } out_token(token); break; case RIGHT_PAREN : return token_class; case OPERATOR : out_white_space(token); if (token->token_type == EQUAL) /* Make it a '==' */ out_str("=="); else /* Check for address operator '@' or '.' */ if ((token->token_type == AT_OP) || (token->token_type == PERIOD)) { token_class = get_token(token); if (token_class == IDENTIFIER) { /* Make it a '&' */ out_char('&'); /* See if it's a function reference */ if (find_symbol(token, &id_type, &id_id) && (id_type->type->token_type != PROCEDURE)) { /* Variable - parse it */ temp_class = parse_member(token, id_type, id_id); } else { /* Function call - Check for */ /* a function conversion */ if (check_cvt_id(token, &cvt_functions[0], &new_id)) /* Convert to desired function */ out_str(new_id); else /* Function call - output name */ out_token_name(token); temp_class = get_token(token); } } else if (token_class == LEFT_PAREN) { /* Constant list - convert to string */ out_char('"'); string_const[0] = '\0'; do { token_class = get_token(token); if (token_class == STRING) (void) strcat(string_const, token->token_name); else if (token_class == NUMERIC) { cvt_octal(token, octal_const); (void) strcat(string_const, octal_const); } else { parse_error("Illegal constant"); return ERROR; } token_class = get_token(token); } while (token_class == COMMA); if (token_class != RIGHT_PAREN) { parse_error("')' expected"); return ERROR; } i = strlen(string_const); if ((i >= 4) && (!strcmp(string_const + i - 4, "\\000"))) /* Discard trailing null */ string_const[i - 4] = '\0'; out_str(string_const); out_char('"'); } else { parse_error("Illegal operator"); return ERROR; } } else out_token_name(token); break; case IDENTIFIER : /* Check for identifier conversion */ if (check_cvt_id(token, &cvt_identifiers[0], &new_id)) { out_white_space(token); out_str(new_id); temp_class = get_token(token); } else /* See if variable in context */ if (find_symbol(token, &id_type, &id_id) && (id_type->type->token_type != PROCEDURE)) { /* Variable - parse it */ temp_class = parse_member(token, id_type, id_id); } else /* Function call - parse it */ temp_class = parse_function(token); break; case NUMERIC : out_token(token); break; case STRING : out_white_space(token); /* Convert to a numeric constant */ if (token->token_length > 4) { parse_error("Illegal string constant"); return ERROR; } if (token->token_length > 1) out_char('('); out_str_const(token->token_name, token->token_length); if (token->token_length > 1) out_char(')'); break; default : /* Must not be part of an expression! */ return token_class; } last_class = token_class; token_class = (last_class == IDENTIFIER) ? temp_class : get_token(token); } }
/* * Parse function call */ int parse_function(TOKEN *token) { int token_class; BOOLEAN left_shift, right_shift; char *new_func; DECL_MEMBER *decl_ptr; DECL_ID *decl_id; /* Function call - check for SHL or SHR */ out_white_space(token); left_shift = !strcmp(token->token_name, "shl") || !strcmp(token->token_name, "SHL"); right_shift = !strcmp(token->token_name, "shr") || !strcmp(token->token_name, "SHR"); if (left_shift || right_shift) { /* SHL(expr, expr) or SHR(expr, expr) */ /* Check for '(' */ token_class = get_token(token); if (token_class != LEFT_PAREN) { parse_error("'(' expected"); return ERROR; } out_token(token); /* Output first expression */ out_char('('); token_class = parse_expression(token); if (token_class != COMMA) { parse_error("',' expected"); return ERROR; } out_str(left_shift ? ") << (" : ") >> ("); /* Output second expression */ token_class = parse_expression(token); if (token_class != RIGHT_PAREN) { parse_error("Missing ')'"); return ERROR; } out_char(')'); out_token(token); } else { /* Check for a type cast function */ if (check_cvt_id(token, &cast_functions[0], &new_func)) { /* Convert to a cast */ out_char('('); out_str(new_func); out_str(") "); } else /* Check for a function conversion */ if (check_cvt_id(token, &cvt_functions[0], &new_func)) { /* Convert to desired function */ out_str(new_func); } else { /* Output function name */ out_token_name(token); /* Check for parameter list */ if (find_symbol(token, &decl_ptr, &decl_id)) { if (decl_ptr->type->token_type != PROCEDURE) { parse_error("Illegal function call"); return ERROR; } if (decl_ptr->initialization != DATA) { /* No param list */ token_class = get_token(token); return token_class; } } } /* Check for parameter list */ token_class = get_token(token); if (token_class != LEFT_PAREN) { parse_warning("Parameter list expected"); return token_class; } out_token(token); /* Parse to closing right paren */ do { token_class = parse_expression(token); out_token(token); } while (token_class == COMMA); if (token_class != RIGHT_PAREN) { parse_error("Missing ')'"); return ERROR; } } /* Return token following function */ token_class = get_token(token); return token_class; }
/* * Parse variable name or structure element and output appropriate tokens. * Passed with identifier in token, and declaration for token in decl. * Returns with token terminating variable. * Handles <member> { [ ( <expression> ) ] [ .<identifier> ] } */ int parse_member(TOKEN *token, DECL_MEMBER *decl, DECL_ID *decl_id) { int token_class; TOKEN member; DECL_MEMBER *var_decl; DECL_ID *var_decl_id; /* Check for literal */ if (decl->literal) { /* Yes - output case converted literal */ out_white_space(token); out_cvt_name(token); /* Return next token */ token_class = get_token(token); return token_class; } token_copy(token, &member); token_class = get_token(token); /* Check for array subscript */ if (decl->array_bound) { out_ident(&member, decl, decl_id); if (token_class == LEFT_PAREN) { /* Convert to open square bracket */ token->token_name[0] = '['; out_token(token); /* Parse expression to right parenthesis */ token_class = parse_expression(token); if (token_class != RIGHT_PAREN) { parse_error("')' expected"); return ERROR; } /* Convert to close square bracket */ token->token_name[0] = ']'; out_token(token); token_class = get_token(token); } } /* Check for .<identifier> */ if ((decl->type->token_type == STRUCTURE) && (token_class == PERIOD)) { if (decl->array_bound) /* Already printed identifier */ out_token(token); else { if (decl->at_ptr || decl_id->based_name) { /* * --- Note: Does not handle BASED AT variables! */ /* Print 'member->' */ out_token(&member); out_str("->"); } else { /* Print 'member.' */ out_ident(&member, decl, decl_id); out_token(token); } } token_class = get_token(token); if (token_class != IDENTIFIER) { parse_error("Illegal structure member"); return ERROR; } /* Find variable in list */ if (!find_list_symbol(token, decl->struct_list, &var_decl, &var_decl_id)) { parse_error("Undefined structure member"); return ERROR; } /* Parse this member now */ token_class = parse_member(token, var_decl, var_decl_id); } else if (decl->array_bound == NULL) out_ident(&member, decl, decl_id); return token_class; }
void readin(void) { static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;"; static char yy_nostdinit[] = "FILE *yyin = NULL, *yyout = NULL;"; line_directive_out( NULL, 1 ); if ( yyparse() ) { pinpoint_message( _( "fatal parse error" ) ); flexend( 1 ); } if ( syntaxerror ) flexend( 1 ); if ( backing_up_report ) { backing_up_file = fopen( backing_name, "w" ); if ( backing_up_file == NULL ) lerrsf( _( "could not create backing-up info file %s" ), backing_name ); } else backing_up_file = NULL; if ( yymore_really_used == true ) yymore_used = true; else if ( yymore_really_used == false ) yymore_used = false; if ( reject_really_used == true ) reject = true; else if ( reject_really_used == false ) reject = false; if ( performance_report > 0 ) { if ( lex_compat ) { fprintf( stderr, _( "-l AT&T lex compatibility option entails a large performance penalty\n" ) ); fprintf( stderr, _( " and may be the actual source of other reported performance penalties\n" ) ); } else if ( do_yylineno ) { fprintf( stderr, _( "%%option yylineno entails a large performance penalty\n" ) ); } if ( performance_report > 1 ) { if ( interactive ) fprintf( stderr, _( "-I (interactive) entails a minor performance penalty\n" ) ); if ( yymore_used ) fprintf( stderr, _( "yymore() entails a minor performance penalty\n" ) ); } if ( reject ) fprintf( stderr, _( "REJECT entails a large performance penalty\n" ) ); if ( variable_trailing_context_rules ) fprintf( stderr, _( "Variable trailing context rules entail a large performance penalty\n" ) ); } if ( reject ) real_reject = true; if ( variable_trailing_context_rules ) reject = true; if ( (fulltbl || fullspd) && reject ) { if ( real_reject ) flexerror( _( "REJECT cannot be used with -f or -F" ) ); else if ( do_yylineno ) flexerror( _( "%option yylineno cannot be used with -f or -F" ) ); else flexerror( _( "variable trailing context rules cannot be used with -f or -F" ) ); } if ( reject ) outn( "\n#define YY_USES_REJECT" ); if ( ! do_yywrap ) { outn( "\n#define yywrap() 1" ); outn( "#define YY_SKIP_YYWRAP" ); } if ( ddebug ) outn( "\n#define FLEX_DEBUG" ); if ( csize == 256 ) outn( "typedef unsigned char YY_CHAR;" ); else outn( "typedef char YY_CHAR;" ); if ( C_plus_plus ) { outn( "#define yytext_ptr yytext" ); if ( interactive ) outn( "#define YY_INTERACTIVE" ); } else { if ( do_stdinit ) { outn( yy_stdinit ); } else outn( yy_nostdinit ); } if ( fullspd ) outn( "typedef yyconst struct yy_trans_info *yy_state_type;" ); else if ( ! C_plus_plus ) outn( "typedef int yy_state_type;" ); if ( ddebug ) outn( "\n#define FLEX_DEBUG" ); if ( lex_compat ) outn( "#define YY_FLEX_LEX_COMPAT" ); if ( do_yylineno && ! C_plus_plus ) { outn( "extern int yylineno;" ); outn( "int yylineno = 1;" ); } if ( C_plus_plus ) { outn( "\n#include <FlexLexer.h>" ); if ( yyclass ) { outn( "int yyFlexLexer::yylex()" ); outn( "\t{" ); outn( "\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );" ); outn( "\treturn 0;" ); outn( "\t}" ); out_str( "\n#define YY_DECL int %s::yylex()\n", yyclass ); } } else { if ( yytext_is_array ) outn( "extern char yytext[];\n" ); else { outn( "extern char *yytext;" ); outn( "#define yytext_ptr yytext" ); } if ( yyclass ) flexerror( _( "%option yyclass only meaningful for C++ scanners" ) ); } if ( useecs ) numecs = cre8ecs( nextecm, ecgroup, csize ); else numecs = csize; /* Now map the equivalence class for NUL to its expected place. */ ecgroup[0] = ecgroup[csize]; NUL_ec = ABS( ecgroup[0] ); if ( useecs ) ccl2ecl(); }
/* * CALL statement * Handles CALL <procedure name> [ ( <parameter list> ) ] ; */ void parse_call(TOKEN *first_token) { TOKEN token; int token_class; DECL_MEMBER *id_type; DECL_ID *id_id; char *new_func, *tmp_out_string; char func_name[MAX_TOKEN_LENGTH]; /* Get procedure name */ token_class = get_token(&token); if (token_class != IDENTIFIER) { parse_error("Illegal procedure name"); return; } out_white_space(first_token); /* Check for function conversion */ if (check_cvt_id(&token, &cvt_functions[0], &new_func)) { out_str(new_func); token_class = get_token(&token); } else if (find_symbol(&token, &id_type, &id_id) && (id_type->type->token_type != PROCEDURE)) { /* Skip white space */ token.white_space_start = token.white_space_end; /* Check for call to pointer */ func_name[0] = '\0'; tmp_out_string = out_string; out_string = func_name; token_class = parse_variable(&token, &id_type, &id_id); out_string = tmp_out_string; if ((id_type->type->token_type == POINTER) || #ifdef OFFSET (id_type->type->token_type == OFFSET) || #endif (id_type->type->token_type == WORD)) { /* Yes - use pointer reference */ out_str("(*"); out_str(func_name); out_char(')'); } else { parse_error("Illegal procedure reference"); return; } } else { out_token_name(&token); token_class = get_token(&token); } /* Get parameter list (if any) */ if (token_class == LEFT_PAREN) { out_token(&token); do { token_class = parse_expression(&token); out_token(&token); } while (token_class == COMMA); if (token_class == RIGHT_PAREN) /* Get end of line */ check_eol(); else parse_error("Illegal parameter list seperator"); } else if (token_class == END_OF_LINE) { /* No parameter list */ out_str("()"); out_token(&token); } else parse_error("';' expected"); }