Mercurial > hg > Members > shinya > pyrect
view code/c/reg.c @ 3:a193b4ff3909
prepare graph outputs (but not implement)
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 Jun 2010 11:44:40 +0900 |
parents | 02656ea776f3 |
children |
line wrap: on
line source
#include <stdio.h> void state_8(char* s); void state_1_3_5_6_7(char* s); void state_1_3_4_5_7(char* s); void state_1_2_3_5_7(char* s); void accept(char* s); void reject(char* s); int main(int argc, char* argv[]) { puts("regexp: (A|B)*C"); puts("number of state: 4"); printf("string: %s\n", argv[1]); state_1_3_5_6_7(argv[1]); return 0; } void state_8(char* s) { switch(*s++) { case '\0': accept(s); break; default: reject(s); } } void state_1_3_5_6_7(char* s) { switch(*s++) { case 'A': state_1_2_3_5_7(s); break; case 'C': state_8(s); break; case 'B': state_1_3_4_5_7(s); break; default: reject(s); } } void state_1_3_4_5_7(char* s) { switch(*s++) { case 'A': state_1_2_3_5_7(s); break; case 'C': state_8(s); break; case 'B': state_1_3_4_5_7(s); break; default: reject(s); } } void state_1_2_3_5_7(char* s) { switch(*s++) { case 'A': state_1_2_3_5_7(s); break; case 'C': state_8(s); break; case 'B': state_1_3_4_5_7(s); break; default: reject(s); } } void accept(char* s) { printf("\nstring matches regexp. \n\n"); } void reject(char* s) { printf("\nstring does not match regexp. \n\n"); }