/* Main Implementation -------------------------------------------------------*/ int main( int argc, char *argv[] ) { if (argc == 2 && strcmp(argv[1], "--help") == 0) { std::cout << "Input Format:\n\n" << "Initial State: {3}\n" << "Final States: {12,...}\n" << "Total States: 15\n" << "State a b E\n" << "1 {...} {...} {...}\n" << "... ...\n"; exit(0); } int initState=0, totalStates=0; std::vector<int> finalStates; std::string alphabet; scanf("Initial State: {%d}\n", &initState); // read initial state read_final_states(&finalStates); // read final states scanf("Total States: %d\n", &totalStates); // read total no. of states read_alphabet(&alphabet); // read alphabet // Create NFA in memory and read transition table from stdin Automata fa(alphabet, initState-1, totalStates, finalStates); read_automata(&fa); // Convert to dfa convert_nfa_dfa(&fa); fa.Print(); return 0; }
void return_simulation_data(mxArray **plhs){ /* Return values */ mxArray *output_struct; mxArray *final_states; mxArray *final_times; if(!collection_status.initialized) ERROR("Attempted to read simulation data without initializing.\n"); collection_status.initialized = 0; /* Read outputs */ if(collection_status.shared_memory){ check_for_error(); output_struct = read_outputs_from_shared_memory(); } else{ output_struct = read_outputs_from_files(); } /* Read final states */ final_states = read_final_states(); /* Read final times */ final_times = read_final_times(); /* Assign return values */ plhs[0] = output_struct; plhs[1] = final_states; plhs[2] = final_times; }
// Ex. 14 automaton* read_automaton(FILE* fptr) { int state_c; int symbol_c; int initial_state; int final_state_c; int* final_states; s_table_element* symbol_table; state* state_table; char line[MAX_LEN+1]; if(fseek(fptr, 0, SEEK_SET)) { puts("Couldn't seek the start of the file!"); return NULL; } // Reading the number of states, number of symbols, and initial state fgets(line, (int)MAX_LEN, fptr); sscanf(line, "%d %d %d", &state_c, &symbol_c, &initial_state); // Constructing the table of final states final_states = read_final_states(fptr, &final_state_c); // Constructing the symbol table symbol_table = read_symbols(symbol_c, fptr); // Constructing the state table state_table = malloc(sizeof(state)*state_c); if(state_table == NULL) { puts("Couldn't allocate the state table"); return NULL; } int type; for(int i = 0; i < state_c; ++i) { if((i+1) == initial_state) type = 1; else if(is_final_state(final_states, final_state_c, i+1)) type = -1; else type = 0; state_table[i] = new_state(i+1, type, NULL); } while(read_transition(state_table, fptr)); automaton* ret = malloc(sizeof(automaton)); if(ret == NULL) return NULL; ret->initial_state = initial_state; ret->states = state_c; ret->symbol_c = symbol_c; ret->state_table = state_table; ret->symbol_table = symbol_table; ret->final_states = final_states; ret->final_state_c = final_state_c; return ret; }
int main(int argc, char *argv[]) { struct state_machine *sm; char *filename; int nstates; int i; int use_goto; use_goto = is_goto(argc, argv); sm = sm_make(); sm->tokens = read_tokens(); if (sm->tokens == NULL) panic("Invalid token input"); read_nstates(sm); read_initial_state(sm); read_final_states(sm); setup_transitions(sm); printf("Output filename: "); fflush(stdout); filename = read_line(); if (use_goto) write_output_goto(sm, filename); else write_output_func(sm, filename); sm_free(sm); return 0; }