OSDN Git Service

expression.c, stream.c, textfile.txt, token.cの追加 master
authorttwilb <someone@example.com>
Fri, 1 Mar 2013 12:13:04 +0000 (21:13 +0900)
committerttwilb <someone@example.com>
Fri, 1 Mar 2013 12:13:04 +0000 (21:13 +0900)
common.h
expression.c [new file with mode: 0644]
stream.c [new file with mode: 0644]
testfile.txt [new file with mode: 0644]
token.c [new file with mode: 0644]
toplev.c

index 2c78a31..816e8f6 100644 (file)
--- a/common.h
+++ b/common.h
 #include <stdio.h>
 #include <string.h>
 
+#define FILENAME_MAX   256
 
 /*** toplev.c ***/
 
 int toplev_main(int argc, const char** argv);
 
 
-/*** toplev_cpp.cpp ***/
+/*** expression.c ***/
+
+struct Expression
+{
+       int aa;
+};
+
+struct Expression* alloc_expression();
+
+
+/*** stream.c ***/
+
+#define STREAM_FILE    1
+
+struct StreamInfo
+{
+       int type;
+       union
+       {
+               struct
+               {
+                       char filename[FILENAME_MAX];
+                       FILE *fp;
+               }file;
+       };
+};
+
+struct StreamInfo open_stream_file(char fname[FILENAME_MAX]);
+void close_stream(struct StreamInfo info);
+char stream_nextchar(struct StreamInfo info);
+
+/*** token.c ***/
+
+#define NULL_TOKEN     (struct Token *)0
+
+struct LexInfo
+{
+       struct StreamInfo *stream;
+       char n;
+};
+
+struct Token
+{
+
+};
+
+
 
 /* disable object mangling */
+/* using this when calling C++ functions */
+/*
 #ifdef __cplusplus
 extern "C" int toplev_main_cpp(int argc, const char** argv);
 #else
 extern int toplev_main_cpp(int argc, const char** argv);
 #endif
+*/
 
diff --git a/expression.c b/expression.c
new file mode 100644 (file)
index 0000000..99ad4b0
--- /dev/null
@@ -0,0 +1,27 @@
+#include "common.h"
+
+/*
+* expression.c --manage expressions
+* 
+* Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
+* 
+* This source code is released on the BSD licensing.
+* 
+*/
+
+#define EXPRESSION_BUF_MAX     100
+
+struct Expression expression_buf[EXPRESSION_BUF_MAX];
+int expression_buf_count = 0;
+
+struct Expression* alloc_expression()
+{
+       if(!expression_buf_count >= EXPRESSION_BUF_MAX)
+       {
+               return &expression_buf[expression_buf_count++];
+       }else
+       {
+               printf("----Fatal: expression allocation error");
+               return (struct Expression *) 0;
+       }
+}
diff --git a/stream.c b/stream.c
new file mode 100644 (file)
index 0000000..b95e257
--- /dev/null
+++ b/stream.c
@@ -0,0 +1,31 @@
+#include "common.h"
+
+/*
+* stream.c     --manage stream
+* 
+* Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
+* 
+* This source code is released on the BSD licensing.
+* 
+*/
+
+struct StreamInfo open_stream_file(char fname[FILENAME_MAX])
+{
+       struct StreamInfo res;
+       strcpy(res.file.filename, fname);
+       res.file.fp = fopen(fname, "r");
+       res.type = STREAM_FILE;
+       return res;
+}
+
+void close_stream(struct StreamInfo info)
+{
+       if(info.type == STREAM_FILE)
+               fclose(info.file.fp);
+}
+
+char stream_nextchar(struct StreamInfo info)
+{
+       if(info.type == STREAM_FILE)
+               return (getc(info.file.fp));
+}
diff --git a/testfile.txt b/testfile.txt
new file mode 100644 (file)
index 0000000..984fe64
--- /dev/null
@@ -0,0 +1,12 @@
+#
+# testfile.txt --glent fource code
+# 
+# Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
+# 
+# This source code is released on the BSD licensing.
+# 
+#
+
+
+
+3 + 2
\ No newline at end of file
diff --git a/token.c b/token.c
new file mode 100644 (file)
index 0000000..1febfe6
--- /dev/null
+++ b/token.c
@@ -0,0 +1,63 @@
+#include "common.h"
+
+/*
+* token.c      --glent tokenizer
+* 
+* Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
+* 
+* This source code is released on the BSD licensing.
+* 
+*/
+
+#define BLANK_CH       " \n\r\t\f\v"
+#define NEWLINE_CH     "\n"
+
+struct LexInfo open_lex(struct StreamInfo *st)
+{
+       struct LexInfo res;
+       res.stream = st;
+       res.n = stream_nextchar(*st);
+}
+
+void close_lex(struct StreamInfo *st)
+{
+       close_stream(*st);
+}
+
+bool pass_blank(struct LexInfo *le)
+{
+       bool is_in_onelinecomment = false;
+       for(;;)
+       {
+               if(le->n == (char)0) return true;
+               if(is_in_onelinecomment)
+               {
+                       if(strstr(NEWLINE_CH, &le->n) != NULL)
+                       {
+                               is_in_onelinecomment = false;
+                       }
+               }
+               else if(strstr(BLANK_CH, &le->n) != NULL)
+               {
+                       if(le->n == '#') is_in_onelinecomment = true;
+               }
+               else
+               {
+                       break;
+               }
+               le->n = stream_nextchar(*le->stream);
+       }
+       return false;
+}
+
+struct Token* next_token(struct LexInfo *le)
+{
+
+}
+
+
+
+
+
+
+
index d089af7..8112459 100644 (file)
--- a/toplev.c
+++ b/toplev.c
@@ -9,8 +9,23 @@
 * 
 */
 
+int compile_file(const char *fname)
+{
+       return 0;
+}
+
 int toplev_main(int argc, const char** argv)
 {
-       return 
-       toplev_main_cpp(argc, (const char **) argv);
+       int i;
+
+       for(i = 1; i < argc; i++)
+       {
+               printf("Compiling %s ...\n", argv[i]);
+               compile_file(argv[i]);
+       }
+
+       getchar();
+       return 0;
 }
+
+