view CbC-examples/regexp/dfareg.c @ 62:70947ddafad7

added test code, CbC-example/regexp
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Sun, 25 Apr 2010 17:46:01 +0900
parents
children
line wrap: on
line source

#include <stdio.h>

#include <stdlib.h>

__code state_20_21(char* s);
__code state_1(char* s);
__code state_3_8_9_13_23_24(char* s);
__code state_6_7(char* s);
__code state_2_3_9_13_23_24_25(char* s);
__code state_10_11(char* s);
__code state_18_19(char* s);
__code state_4_5(char* s);
__code state_14_15(char* s);
__code state_3_9_13_22_23_24(char* s);
__code state_3_9_12_13_23_24(char* s);
__code state_16_17(char* s);
__code accept();
__code reject();

int main(int argc, char* argv[]) {
	if (argc == 1) {
		printf("usage: %s text\n", argv[0]);
		exit(0);
}

	puts("regexp: P(erl|HP|ython)*");
	puts("number of state: 12");
	printf("string: %s\n", argv[1]);
	goto state_1(argv[1]);
	return 0;
}

__code state_20_21(char* s) {
	switch(*s++) {
		case 'n': 
			goto state_3_9_13_22_23_24(s);
			break;
		default: goto reject();
	}
}

__code state_1(char* s) {
	switch(*s++) {
		case 'P': 
			goto state_2_3_9_13_23_24_25(s);
			break;
		default: goto reject();
	}
}

__code state_3_8_9_13_23_24(char* s) {
	switch(*s++) {
		case 'y': 
			goto state_14_15(s);
			break;
		case 'H': 
			goto state_10_11(s);
			break;
		case 'e': 
			goto state_4_5(s);
			break;
		case '\0': goto accept();
			break;
		default: goto reject();
	}
}

__code state_6_7(char* s) {
	switch(*s++) {
		case 'l': 
			goto state_3_8_9_13_23_24(s);
			break;
		default: goto reject();
	}
}

__code state_2_3_9_13_23_24_25(char* s) {
	switch(*s++) {
		case 'y': 
			goto state_14_15(s);
			break;
		case 'H': 
			goto state_10_11(s);
			break;
		case 'e': 
			goto state_4_5(s);
			break;
		case '\0': goto accept();
			break;
		default: goto reject();
	}
}

__code state_10_11(char* s) {
	switch(*s++) {
		case 'P': 
			goto state_3_9_12_13_23_24(s);
			break;
		default: goto reject();
	}
}

__code state_18_19(char* s) {
	switch(*s++) {
		case 'o': 
			goto state_20_21(s);
			break;
		default: goto reject();
	}
}

__code state_4_5(char* s) {
	switch(*s++) {
		case 'r': 
			goto state_6_7(s);
			break;
		default: goto reject();
	}
}

__code state_14_15(char* s) {
	switch(*s++) {
		case 't': 
			goto state_16_17(s);
			break;
		default: goto reject();
	}
}

__code state_3_9_13_22_23_24(char* s) {
	switch(*s++) {
		case 'y': 
			goto state_14_15(s);
			break;
		case 'H': 
			goto state_10_11(s);
			break;
		case 'e': 
			goto state_4_5(s);
			break;
		case '\0': goto accept();
			break;
		default: goto reject();
	}
}

__code state_3_9_12_13_23_24(char* s) {
	switch(*s++) {
		case 'y': 
			goto state_14_15(s);
			break;
		case 'H': 
			goto state_10_11(s);
			break;
		case 'e': 
			goto state_4_5(s);
			break;
		case '\0': goto accept();
			break;
		default: goto reject();
	}
}

__code state_16_17(char* s) {
	switch(*s++) {
		case 'h': 
			goto state_18_19(s);
			break;
		default: goto reject();
	}
}


__code accept() {
	printf("\nstring matches regexp. \n\n");
}


__code reject() {
	printf("\nstring does not match regexp. \n\n");
}