changeset 17:5ff3f1efa76a

add CbC test code.
author Ryoma SHINYA <shinya@firefly.cr.ie.u-ryukyu.ac.jp>
date Mon, 05 Jul 2010 06:26:20 +0900
parents 100efeeb2ad9
children ec36e784df2e
files code/cbc/dfa.cbc
diffstat 1 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/code/cbc/dfa.cbc	Mon Jul 05 06:26:20 2010 +0900
@@ -0,0 +1,74 @@
+#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");
+}