changeset 7:d6ac7ec2c6a7

merge 5,6
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 03 Jun 2012 14:28:07 +0900
parents 636a4f0cd8f4 (current diff) afa536eef659 (diff)
children bdf156058529
files DPP/Makefile
diffstat 3 files changed, 126 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file automaton/a.out has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/automaton/fautomaton1.cbc	Sun Jun 03 14:28:07 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/test.c	Sun Jun 03 14:28:07 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;
+}