int main(void) { char * str = "Don't ask what your country can do for you, but ask what you can do for your country."; char c; int state = 0; // init state int input = 0; // 0: space 1: alpha int counter = 0; printf("hello, count how many words in string:\n"); printf("<%s>\n", str); while ((c = *str++) != '\0') { input = get_input_type(c); if (state == 0 && input == 1) state = 1; else if (state == 1 && input == 0) { counter++; state = 0; } } printf("find %d words.\n", counter); return 0; }
int main(void) { int new_state; // printf( "please input a string : " ); // scanf( "%s", buf ); printf( "your input string is: %s \n", buf ); DPRINT( "%s\n", buf ); i = 0; state = 0; while( state != -1 ) { input = get_input_type( buf[i] ); DPRINT( "(%d)%d \n", state, input ); /* get new state from state transition table */ new_state = state_table[state][input]; DPRINT( "new state: %d \n", input ); //getchar(); /* call action to do something */ action[state][input](); state = new_state; i++; } return 0; }
int main(void) { char result[10][50]; int row, col; int i = 0; int input; int oldtype; int state = 0; printf("demo state machine \n"); printf("please input a string: \n"); //scanf("%s", str); scanf("%s", filename); read_file( filename, str ); printf("string number is %s \n", str); printf("result string is \n"); printf("-----------------------------------------\n"); /* init start state = 0 */ state = 0; while( state != -1 ) { c = str[i]; //printf("%c", c); input = get_input_type( c ); //printf("%d", input); action[state][input](); state = s_table[state][input]; i++; } //printf("\n"); // printf("there is %d number in string. \n", row+1); return 0; }
int main(int argc, char *argv[]) { int new_state; // printf( "please input a string : " ); // scanf( "%s", buf ); if(argc < 2){ fprintf(stderr, "Usage: %s <filename>\n", argv[0]); exit(1); } int n = read_file(argv[1], buf); printf("%s\n", buf); printf("%d bytes read from %s \n", n, argv[1]); DPRINT( "your input string is: %s \n", buf ); printf("-------------------------------------------\n"); i = 0; state = 0; while( state != -1 ) { input = get_input_type( buf[i] ); DPRINT( "(%d)%d:0x%x \n", state, input, buf[i] ); /* get new state from state transition table */ new_state = state_table[state][input]; DPRINT( "new state: %d \n", input ); //getchar(); /* call act to do something */ action[state][input](); state = new_state; i++; } return 0; }
int main(void) { char buf[] = " This is a book. That is a bag\n"; // input 1100001001110100000111000011001010000 // state 01200001001220100000122000012001010000 // print p pppppppp pppppppp ppppp ppppppppp int state = 0; int i = 0; int words = 0; char * p = NULL; int counter = 0; // printf("buf = %s\n", buf); i = 0; while (1) { int input = 0; void (*pf)(void); c = getchar(); input = get_input_type(c); //printf("c = %c, input = %d\n", c, input); if (c == EOF) break; pf = act_table[state][input]; pf(); state = state_transition[state][input]; i++; } return 0; }
void Parser::process_input(string _input) { try { // Tokenize the input, divide the string input into minimal units tokenizer.tokenize_input(_input); string token; // Check if there is any token if(tokenizer.remaining_tokens() > 0) { token = tokenizer.peek(); } else { // Most likely blank line, return return; } InputType type = get_input_type(token); switch(type) { case QUERY: process_query(); break; default: process_command(type); break; } } catch(exception& e) { cout << "Exception: " << e.what() << endl; } }
size_t unsupervised_data_reader::get_input_neuron_elem_size() const { return neuron_data_type::get_input_size(get_input_type()); }
int main( int argc, char * argv[] ) { /* the index of source string */ int i = 0; /* input char 's condition type */ int cond = 0; /* define the input char */ char input; /* get the input char type */ int input_type; /* define the state machine status */ int state = 0; printf( "state machine demo begin ! \n" ); /* check input argument */ if( argc > 1 ) printf( "input string is \n%s \n", argv[1] ); /* state machine begin ! */ state = 0; #define END -100 /* check the input char by char */ /// while( state != -100 ) while( state != END ) { /* get current input char */ input = argv[1][i]; // printf( "input char is %c \n", input ); // printf( "%c", input ); /* get input char type */ input_type = get_input_type( input ); //printf( "input char type is %d \n", input_type ); //printf( "%d", input_type ); printf( "state = %d \n", state ); printf( "input char type is %d \n", input_type ); switch( state ) { case 0: switch ( input_type ) { case 0: state = 1; break; case 1: //state = -1; #define E1 -1 state = E1; printf( "\ne1: you input like <a> \n" ); goto error; break; case -1: #define END -100 // state = -100; state = END; printf( "end: no number string ! \n" ); } break; case 1: switch ( input_type ) { case 0: state = 1; break; case 1: state = -2; printf( "\ne2: you input like <9a> \n" ); goto error; break; case -1: state = -100; printf( "end: number string is ok! \n" ); } break; } i++; } printf( "\n" ); return 0; error: printf( "error happen !\n" ); return -1; }
// int main(void) int parse_dict(char * filename, void(*callback)(char *, char *)) { int i = 0; int j = 0; int counter = 0; int state = 0; // init state int input = 0; // 0: space 1: alpha 2: digit char word[64]; char meaning[256]; FILE * fp; printf("begin to parse dict file!\n"); fp = fopen(filename, "r"); if (fp == NULL) { printf("file %s doesn't exist!\n", filename); exit(0); } while (1) { char c; //c = getchar(); c = fgetc(fp); if (c == EOF) break; input = get_input_type(c); //printf("state = %d ", state); switch (state) { case 0: //" " switch (input) { case 0: break; case 1: state = 1; i = 0; //printf("word begin with <%c>\n", c); break; case 2: state = 0; //printf("word begin with <%c>\n", c); break; default: break; } break; case 1: // "#" switch (input) { case 0: word[i++] = c; state = 1; break; case 1: state = 0; break; case 2: word[i] = '\0'; counter++; //printf("%d ", counter); //printf("word found! value = <%s>\n", word); j = 0; state = 2; break; default: break; } break; case 2: // "9" switch (input) { case 0: meaning[j++] = c; state = 2; break; case 1: state = 0; break; case 2: meaning[j] = '\0'; //printf("meaning found! value = <%s>\n", meaning); callback(word, meaning); state = 0; break; default: break; } break; default: break; } } fclose(fp); printf("parse dict file finished!\n"); return 0; }
int main(void) { int state = 0; while (1) { char c; int input; c = getchar(); input = get_input_type(c); if (c == EOF) break; debug("%c", c); if (state == 0 && input == 1) { state = 1; } else if (state == 0 && input == 4) { state = 5; putchar(c); } else if (state == 1 && input == 1) { state = 4; } else if (state == 1 && input == 2) { state = 2; } else if (state == 2 && input == 0) { state = 2; } else if (state == 2 && input == 2) { state = 3; } else if (state == 3 && input == 1) { state = 0; } else if (state == 3 && input == 0) { state = 2; } else if (state == 4 && input == 3) { state = 0; putchar(c); } else if (state == 5 && input == 4) { state = 0; putchar(c); } else if (state == 5 && input == 5) { state = 6; putchar(c); } else if (state == 6 && input == 4) { state = 5; putchar(c); } else if (state == 6 && input == 5) { state = 5; putchar(c); } else if (state == 6 && input == 0) { state = 5; putchar(c); } else if (state == 0 || state == 5) putchar(c); debug(" input=%d, state=%d\n", input, state); } return 0; }
int main(void) { char pre[] = "4213657"; char in[] = "1234567"; // char str[] = "helloworld"; char str[] = "Don't ask what your country can do for you, but ask what you can do for your country.\n"; int i = 0; int pos = 0; int state = 0; // init state int input = 0; // 0: space 1: alpha link root = NULL; printf("hello, btree!\n"); printf("%s", str); while (1) { char c; char wordbuf[32]; c = str[pos++]; if (c == '\0') break; input = get_input_type(c); //printf("state = %d ", state); #if 1 if (state == 0 && input == 1) { state = 1; //printf("word begin with <%c>\n", c); i = 0; wordbuf[i++] = c; } else if (state == 1 && input == 0) { wordbuf[i] = '\0'; printf("word end value = <%s>\n", wordbuf); printf("insert %s(%d)\n", wordbuf, input); root = insert(root, wordbuf); state = 0; } else if (state == 1 && input == 1) wordbuf[i++] = c; #endif } #if 0 for (i = 0; i < strlen(str); i++) { printf("insert %c \n", str[i]); root = insert(root, str[i]); } #endif //pre_order(root); //printf("\npre travel finished\n"); in_order(root, 0, '^'); printf("\nin travel finished\n"); //post_order(root); //printf("\npost travel finished\n"); return 0; }
int main(void) { int state = 0; while (1) { char c; int input; c = getchar(); input = get_input_type(c); if (c == EOF) break; debug("%c", c); /* ABCD */ if (state == 0 && input == 1) // "/ { state = 1; } else if (state == 0 && input == 4) // "abc' { state = 5; putchar(c); } else if (state == 1 && input == 1) // "// { state = 4; } else if (state == 1 && input == 2) // "/* { state = 2; } else if (state == 2 && input == 0) // "/*abc { state = 2; } else if (state == 2 && input == 2) // "/*abc* { state = 3; } else if (state == 3 && input == 1) // "/*abc*/ { state = 0; } else if (state == 3 && input == 0) // "/*abc*abc { state = 2; } else if (state == 4 && input == 3) // "// abcd \n { state = 0; putchar(c); } else if (state == 5 && input == 4) // "abc'/' { state = 0; putchar(c); } else if (state == 5 && input == 5) // "abc'\/ { state = 6; putchar(c); } else if (state == 6 && input == 4) // "abc'\' { state = 5; putchar(c); } else if (state == 6 && input == 5) // "abc'vv { state = 5; putchar(c); } else if (state == 6 && input == 0) // "abc'\' { state = 5; putchar(c); } else if (state == 0 || state == 5) putchar(c); debug(" input=%d, /* abcd */ state=%d\n", input, state); } return 0; }