int main(int argc, char **argv) { int i; char *post; State *start; if(argc < 3){ fprintf(stderr, "usage: nfa regexp string...\n"); return 1; } post = re2post(argv[1]); if(post == NULL){ fprintf(stderr, "bad regexp %s\n", argv[1]); return 1; } start = post2nfa(post); if(start == NULL){ fprintf(stderr, "error in post2nfa %s\n", post); return 1; } l1.s = malloc(nstate*sizeof l1.s[0]); l2.s = malloc(nstate*sizeof l2.s[0]); for(i=2; i<argc; i++) if(match(start, argv[i])) printf("%s\n", argv[i]); return 0; }
int main(int argc, char *argv[]) { if (argc != 3) { fprintf(stderr, "Usage: ./nfa regexp string...\n"); return 1; } char *post = re2post(argv[1]); if (post == NULL) { fprintf(stderr, "Invalid regexp.\n"); return 1; } printf("postfix: %s\n", post); State *start = post2nfa(post); if (start == NULL) { fprintf(stderr, "Error in post2nfa.\n"); return 1; } int i; l1.s = (State **) malloc(nstate * sizeof(l1.s[0])); l2.s = (State **) malloc(nstate * sizeof(l2.s[0])); for (i = 2; i < argc; i++) { if (match(start, argv[i])) printf("%s\n", argv[i]); } return 0; }
void lex_ini(char *regex_file, char *code_file) { regex_num = regex_loader(token, regex_file); if ((code_file_p = fopen(code_file, "r")) == NULL) { printf("Open failed.\n"); return; } char **post = (char**)malloc(regex_num * sizeof(char*)); for (int i = 0; i < regex_num; i++) { *(post + i) = re2post(token[i].regex); } start = (state**)malloc(regex_num*sizeof(state*)); for (int i = 0; i < regex_num; i++) { *(start + i) = post2nfa(*(post + i), i); } current_list.s = (state**)malloc(g_state_num * sizeof(state*)); next_list.s = (state**)malloc(g_state_num * sizeof(state*)); list_ini(start, ¤t_list, regex_num); current_buff = (char*)calloc(1024, sizeof(char)); next_buff = (char*)calloc(1024, sizeof(char)); current_num = load(current_buff); current_state = 1; if (current_num >= 1024) { next_num = load(next_buff); next_state = 1; } else fclose(code_file_p); }