Mercurial > hg > Members > shinya > pyrect
view code/cbc/dfa.cbc @ 112:fcac8224a2e9 default tip
modify memchr parameter.
author | Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 12 Feb 2011 17:00:23 +0900 |
parents | 5ff3f1efa76a |
children |
line wrap: on
line source
#include <stdio.h> __code state_0(char* s); __code state_1(char* s); __code state_2(char* s); __code state_3(char* s); __code accept(char* s); __code 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]); goto state_1(argv[1]); return 0; } __code state_0(char* s) { switch(s++) { case '\0': goto accept(s); default: goto reject(NULL); } } __code state_1(char* s) { switch(s++) { case 'A': goto state_3(s); case 'C': goto state_0(s); case 'B': goto state_2(s); default: goto reject(NULL); } } __code state_2(char* s) { switch(s++) { case 'A': goto state_3(s); case 'C': goto state_0(s); case 'B': goto state_2(s); default: goto reject(NULL); } } __code state_3(char* s) { switch(s++) { case 'A': goto state_3(s); case 'C': goto state_0(s); case 'B': goto state_2(s); default: goto reject(NULL); } } __code accept(char* s) { printf("\nstring matches regexp. \n\n"); } __code reject(char* s) { printf("\nstring does not match regexp. \n\n"); }