Commit MetaInfo

Revisión572e5c91aec9e9188e29d4bd58da2fa03b0712f8 (tree)
Tiempo2013-03-01 21:13:04
Autorttwilb <someone@exam...>
Commiterttwilb

Log Message

expression.c, stream.c, textfile.txt, token.cの追加

Cambiar Resumen

Diferencia incremental

--- a/common.h
+++ b/common.h
@@ -10,18 +10,68 @@
1010 #include <stdio.h>
1111 #include <string.h>
1212
13+#define FILENAME_MAX 256
1314
1415 /*** toplev.c ***/
1516
1617 int toplev_main(int argc, const char** argv);
1718
1819
19-/*** toplev_cpp.cpp ***/
20+/*** expression.c ***/
21+
22+struct Expression
23+{
24+ int aa;
25+};
26+
27+struct Expression* alloc_expression();
28+
29+
30+/*** stream.c ***/
31+
32+#define STREAM_FILE 1
33+
34+struct StreamInfo
35+{
36+ int type;
37+ union
38+ {
39+ struct
40+ {
41+ char filename[FILENAME_MAX];
42+ FILE *fp;
43+ }file;
44+ };
45+};
46+
47+struct StreamInfo open_stream_file(char fname[FILENAME_MAX]);
48+void close_stream(struct StreamInfo info);
49+char stream_nextchar(struct StreamInfo info);
50+
51+/*** token.c ***/
52+
53+#define NULL_TOKEN (struct Token *)0
54+
55+struct LexInfo
56+{
57+ struct StreamInfo *stream;
58+ char n;
59+};
60+
61+struct Token
62+{
63+
64+};
65+
66+
2067
2168 /* disable object mangling */
69+/* using this when calling C++ functions */
70+/*
2271 #ifdef __cplusplus
2372 extern "C" int toplev_main_cpp(int argc, const char** argv);
2473 #else
2574 extern int toplev_main_cpp(int argc, const char** argv);
2675 #endif
76+*/
2777
--- /dev/null
+++ b/expression.c
@@ -0,0 +1,27 @@
1+#include "common.h"
2+
3+/*
4+* expression.c --manage expressions
5+*
6+* Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
7+*
8+* This source code is released on the BSD licensing.
9+*
10+*/
11+
12+#define EXPRESSION_BUF_MAX 100
13+
14+struct Expression expression_buf[EXPRESSION_BUF_MAX];
15+int expression_buf_count = 0;
16+
17+struct Expression* alloc_expression()
18+{
19+ if(!expression_buf_count >= EXPRESSION_BUF_MAX)
20+ {
21+ return &expression_buf[expression_buf_count++];
22+ }else
23+ {
24+ printf("----Fatal: expression allocation error");
25+ return (struct Expression *) 0;
26+ }
27+}
--- /dev/null
+++ b/stream.c
@@ -0,0 +1,31 @@
1+#include "common.h"
2+
3+/*
4+* stream.c --manage stream
5+*
6+* Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
7+*
8+* This source code is released on the BSD licensing.
9+*
10+*/
11+
12+struct StreamInfo open_stream_file(char fname[FILENAME_MAX])
13+{
14+ struct StreamInfo res;
15+ strcpy(res.file.filename, fname);
16+ res.file.fp = fopen(fname, "r");
17+ res.type = STREAM_FILE;
18+ return res;
19+}
20+
21+void close_stream(struct StreamInfo info)
22+{
23+ if(info.type == STREAM_FILE)
24+ fclose(info.file.fp);
25+}
26+
27+char stream_nextchar(struct StreamInfo info)
28+{
29+ if(info.type == STREAM_FILE)
30+ return (getc(info.file.fp));
31+}
--- /dev/null
+++ b/testfile.txt
@@ -0,0 +1,12 @@
1+#
2+# testfile.txt --glent fource code
3+#
4+# Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
5+#
6+# This source code is released on the BSD licensing.
7+#
8+#
9+
10+
11+
12+3 + 2
\ No newline at end of file
--- /dev/null
+++ b/token.c
@@ -0,0 +1,63 @@
1+#include "common.h"
2+
3+/*
4+* token.c --glent tokenizer
5+*
6+* Copyright(C) 2013(Heisei 25) ttwilb All rights reserved.
7+*
8+* This source code is released on the BSD licensing.
9+*
10+*/
11+
12+#define BLANK_CH " \n\r\t\f\v"
13+#define NEWLINE_CH "\n"
14+
15+struct LexInfo open_lex(struct StreamInfo *st)
16+{
17+ struct LexInfo res;
18+ res.stream = st;
19+ res.n = stream_nextchar(*st);
20+}
21+
22+void close_lex(struct StreamInfo *st)
23+{
24+ close_stream(*st);
25+}
26+
27+bool pass_blank(struct LexInfo *le)
28+{
29+ bool is_in_onelinecomment = false;
30+ for(;;)
31+ {
32+ if(le->n == (char)0) return true;
33+ if(is_in_onelinecomment)
34+ {
35+ if(strstr(NEWLINE_CH, &le->n) != NULL)
36+ {
37+ is_in_onelinecomment = false;
38+ }
39+ }
40+ else if(strstr(BLANK_CH, &le->n) != NULL)
41+ {
42+ if(le->n == '#') is_in_onelinecomment = true;
43+ }
44+ else
45+ {
46+ break;
47+ }
48+ le->n = stream_nextchar(*le->stream);
49+ }
50+ return false;
51+}
52+
53+struct Token* next_token(struct LexInfo *le)
54+{
55+
56+}
57+
58+
59+
60+
61+
62+
63+
--- a/toplev.c
+++ b/toplev.c
@@ -9,8 +9,23 @@
99 *
1010 */
1111
12+int compile_file(const char *fname)
13+{
14+ return 0;
15+}
16+
1217 int toplev_main(int argc, const char** argv)
1318 {
14- return
15- toplev_main_cpp(argc, (const char **) argv);
19+ int i;
20+
21+ for(i = 1; i < argc; i++)
22+ {
23+ printf("Compiling %s ...\n", argv[i]);
24+ compile_file(argv[i]);
25+ }
26+
27+ getchar();
28+ return 0;
1629 }
30+
31+
Show on old repository browser