changeset 3:4e98faa1d831

add automaton
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Apr 2012 13:41:11 +0900
parents 396046c5b0b0
children afa536eef659
files DPP/Makefile automaton/a.out automaton/fautomaton1.cbc automaton/fautomaton1.cbc~ automaton/test.c automaton/test.c~
diffstat 6 files changed, 250 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/DPP/Makefile	Sun Feb 05 10:23:07 2012 +0900
+++ b/DPP/Makefile	Thu Apr 19 13:41:11 2012 +0900
@@ -2,7 +2,8 @@
 #MCC=mcc
 TARGET=dpp dpp2 tableau tableau2 tableau3
 #MCCFLAGS=-s
-CFLAGS=-I. -g -Wall
+#CFLAGS=-I. -g -O0 -Wall
+CFLAGS= -O2 -Wall
 
 .SUFFIXES:	.cbc .c .o
 
Binary file automaton/a.out has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/automaton/fautomaton1.cbc	Thu Apr 19 13:41:11 2012 +0900
@@ -0,0 +1,107 @@
+/*
+ * Implementation of the fininte automat by CbC
+ * This is test program
+ *
+ *  Finite automaton M.
+ *  M = ({q1,q2},{0,1}, delta, q1, {q2})
+ *  
+ *  delta = 
+ *    |0  1
+ *  -----------
+ *  q1|q1 q2
+ *  q1|q1 q2
+ */
+
+#include <stdio.h> 
+#include <stdlib.h> // exit()
+#include <string.h> // strlen()
+
+__code q1(char *c, int size, int count);
+__code q2(char *c, int size, int count);
+
+
+__code print_error()
+{
+	printf("error\n");
+	exit(0);
+}
+
+__code no_recognize()
+{
+	printf("no recognize\n");
+}
+
+__code recognize()
+{
+	printf("recognize\n");
+}
+
+int _isspace(char c)
+{
+	return c == ' ' || c == '\t';
+}
+
+char *skipchar(char *c)
+{
+	
+	while(_isspace(*c)) {
+		c++;
+	}
+
+	return c;
+}
+
+__code q1(char *c, int size, int count)
+{
+//	char *ch = skipchar(c);
+	char *ch = c;
+	ch++;
+	count++;
+	switch(*c) {
+	case '0':
+		goto q1(ch, size, count);
+		break;
+	case '1':
+		goto q2(ch, size, count);
+		break;
+	default:
+		if(count >= size) 
+			goto no_recognize();
+		else 
+			goto recognize();
+		
+	}
+
+}
+
+__code q2(char *c, int size, int count)
+{
+//	char *ch = skipchar(c);
+	char *ch = c;
+	ch++;
+	count++;
+	switch(*c) {
+	case '0':
+		goto q1(ch, size, count);
+		break;
+	case '1':
+		goto q2(ch, size, count);
+		break;
+	default:
+		if(count >= size)
+			goto recognize();
+		else 
+			goto no_recognize();
+	}
+	
+}
+
+
+int main(int argc, char *argv[])
+{
+	if(argc == 1 ) goto print_error();
+	int size = strlen(argv[1]);
+	char *c = argv[1];
+	goto q1(c, size, 0);
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/automaton/fautomaton1.cbc~	Thu Apr 19 13:41:11 2012 +0900
@@ -0,0 +1,107 @@
+/*
+ * Implementation of the fininte automat by CbC
+ * test program
+ *
+ *  Finite automaton M.
+ *  M = ({q1,q2},{0,1}, delta, q1, {q2})
+ *  
+ *  delta = 
+ *    |0  1
+ *  -----------
+ *  q1|q1 q2
+ *  q1|q1 q2
+ */
+
+#include <stdio.h> 
+#include <stdlib.h> // exit()
+#include <string.h> // strlen()
+
+__code q1(char *c, int size, int count);
+__code q2(char *c, int size, int count);
+
+
+__code print_error()
+{
+	printf("error\n");
+	exit(0);
+}
+
+__code no_recognize()
+{
+	printf("no recognize\n");
+}
+
+__code recognize()
+{
+	printf("recognize\n");
+}
+
+int _isspace(char c)
+{
+	return c == ' ' || c == '\t';
+}
+
+char *skipchar(char *c)
+{
+	
+	while(_isspace(*c)) {
+		c++;
+	}
+
+	return c;
+}
+
+__code q1(char *c, int size, int count)
+{
+//	char *ch = skipchar(c);
+	char *ch = c;
+	ch++;
+	count++;
+	switch(*c) {
+	case '0':
+		goto q1(ch, size, count);
+		break;
+	case '1':
+		goto q2(ch, size, count);
+		break;
+	default:
+		if(count >= size) 
+			goto no_recognize();
+		else 
+			goto recognize();
+		
+	}
+
+}
+
+__code q2(char *c, int size, int count)
+{
+//	char *ch = skipchar(c);
+	char *ch = c;
+	ch++;
+	count++;
+	switch(*c) {
+	case '0':
+		goto q1(ch, size, count);
+		break;
+	case '1':
+		goto q2(ch, size, count);
+		break;
+	default:
+		if(count >= size)
+			goto recognize();
+		else 
+			goto no_recognize();
+	}
+	
+}
+
+
+int main(int argc, char *argv[])
+{
+	if(argc == 1 ) goto print_error();
+	int size = strlen(argv[1]);
+	char *c = argv[1];
+	goto q1(c, size, 0);
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/automaton/test.c	Thu Apr 19 13:41:11 2012 +0900
@@ -0,0 +1,19 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+	long size = sizeof(argv[1])/sizeof(char);
+	char *c = argv[0];
+	printf("argv[0] = %s\n",argv[0]);
+	
+	printf("size = %ld\n",size);
+	long i;
+	for(i=0; i<size; i++,c++) {
+		printf("%c",*c);
+	}
+	
+	int s = strlen(argv[0]);
+//	long s = sizeof(char);
+	printf("s = %d\n",s);
+
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/automaton/test.c~	Thu Apr 19 13:41:11 2012 +0900
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[]) {
+	long size = sizeof(argv[0])/sizeof(char);
+	char *c = argv[0];
+	printf("argv[0] = %s\n",argv[0]);
+	
+	printf("size = %ld\n",size);
+	long i;
+	for(i=0; i<size; i++,c++) {
+		printf("%c",*c);
+	}
+	
+	return 0;
+}