1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * M2C Modula-2 Compiler & Translator *
3
+ * *
4
+ * Copyright (c) 2015-2023 Benjamin Kowarsch *
5
+ * *
6
+ * @synopsis *
7
+ * *
8
+ * M2C is a portable Modula-2 to C translator and via-C compiler for the *
9
+ * bootstrap subset of the revised Modula-2 language described in *
10
+ * *
11
+ * https://github.com/m2sf/m2bsk/wiki/Language-Specification *
12
+ * *
13
+ * In translator mode, M2C translates Modula-2 source files to semantically *
14
+ * equivalent C source files. In compiler mode, it translates the Modula-2 *
15
+ * source files to C, then compiles the resulting C sources to object and *
16
+ * executable files using the host system's resident C compiler and linker. *
17
+ * *
18
+ * Further information at https://github.com/m2sf/m2c/wiki *
19
+ * *
20
+ * @file *
21
+ * *
22
+ * m2c-import-parser.c *
23
+ * *
24
+ * Implementation of identifier to snake-case translation dictionary. *
25
+ * *
26
+ * @license *
27
+ * *
28
+ * M2C is free software: You can redistribute and modify it under the terms *
29
+ * of the GNU Lesser General Public License (LGPL) either version 2.1 or at *
30
+ * your choice version 3, both published by the Free Software Foundation. *
31
+ * *
32
+ * M2C is distributed in the hope it may be useful, but strictly WITHOUT ANY *
33
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
34
+ * FOR ANY PARTICULAR PURPOSE. Read the license for more details. *
35
+ * *
36
+ * You should have received a copy of the GNU Lesser General Public License *
37
+ * along with M2C. If not, see <https://www.gnu.org/copyleft/lesser.html>. *
38
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39
+
40
+ static void m2c_parse_file ();
41
+
42
+ static void parse_start_symbol ();
43
+
44
+
45
+ /* --------------------------------------------------------------------------
46
+ * private function module_header_and_import()
47
+ * --------------------------------------------------------------------------
48
+ * moduleHeaderAndImport :=
49
+ * defModHdrAndImport | impOrPgmModHdrAndImport
50
+ * ;
51
+ * ----------------------------------------------------------------------- */
52
+
53
+ static m2c_token_t module_header_and_import () {
54
+ m2c_token_t lookahead ;
55
+
56
+ lookahead = m2c_next_sym ();
57
+
58
+ switch (lookahead ) {
59
+ case TOKEN_DEFINITION :
60
+ lookahead = definition_module (p );
61
+ break ;
62
+
63
+ case TOKEN_IMPLEMENTATION :
64
+ lookahead = implementation_module (p );
65
+ break ;
66
+
67
+ case TOKEN_MODULE :
68
+ lookahead = program_module (p );
69
+ break ;
70
+ } /* end switch */
71
+
72
+ return lookahead ;
73
+ } /* end module_header_and_import */
74
+
75
+
76
+ /* --------------------------------------------------------------------------
77
+ * private function def_mod_hdr_and_import()
78
+ * --------------------------------------------------------------------------
79
+ * defModHdrAndImport :=
80
+ * DEFINITION MODULE moduleIdent ';'
81
+ * import* endOfDefModImport;
82
+ * ;
83
+ *
84
+ * alias moduleIdent = Ident ;
85
+ *
86
+ * endOfDefModImport := CONST | TYPE | VAR | PROCEDURE | TO | EndOfFile ;
87
+ * ----------------------------------------------------------------------- */
88
+
89
+ static m2c_token_t def_mod_hdr_and_import () {
90
+ m2c_token_t lookahead ;
91
+
92
+
93
+
94
+ return lookahead ;
95
+ } /* end def_mod_hdr_and_import */
96
+
97
+
98
+ /* --------------------------------------------------------------------------
99
+ * private function import()
100
+ * --------------------------------------------------------------------------
101
+ * import :=
102
+ * IMPORT libIdent reExport? ( ',' libIdent reExport? )* ';'
103
+ * ;
104
+ *
105
+ * alias libIdent = Ident ;
106
+ *
107
+ * alias reExport = '+' ;
108
+ * ----------------------------------------------------------------------- */
109
+
110
+ static m2c_token_t import () {
111
+ m2c_token_t lookahead ;
112
+
113
+
114
+
115
+ return lookahead ;
116
+ } /* end import */
117
+
118
+
119
+ /* --------------------------------------------------------------------------
120
+ * private function imp_or_pgm_mod_hdr_and_import()
121
+ * --------------------------------------------------------------------------
122
+ * impOrPgmModHdrAndImport :=
123
+ * IMPLEMENTATION? MODULE moduleIdent ';'
124
+ * privateImport* endOfImpAndPgmModImport;
125
+ * ;
126
+ *
127
+ * endOfImpAndPgmModImport := BEGIN | endOfDefModImport ;
128
+ * ----------------------------------------------------------------------- */
129
+
130
+ static m2c_token_t imp_or_pgm_mod_hdr_and_import () {
131
+ m2c_token_t lookahead ;
132
+
133
+
134
+
135
+ return lookahead ;
136
+ } /* end imp_or_pgm_mod_hdr_and_import */
137
+
138
+
139
+ /* --------------------------------------------------------------------------
140
+ * private function private_import()
141
+ * --------------------------------------------------------------------------
142
+ * privateImport :=
143
+ * IMPORT moduleList
144
+ * ;
145
+ *
146
+ * alias moduleList = identList;
147
+ * ----------------------------------------------------------------------- */
148
+
149
+ static m2c_token_t private_import () {
150
+ m2c_token_t lookahead ;
151
+
152
+
153
+
154
+ return lookahead ;
155
+ } /* end private_import */
156
+
157
+
158
+ /* --------------------------------------------------------------------------
159
+ * private function ident_list()
160
+ * --------------------------------------------------------------------------
161
+ * identList :=
162
+ * Ident ( ',' Ident )*
163
+ * ;
164
+ * ----------------------------------------------------------------------- */
165
+
166
+ static m2c_token_t ident_list () {
167
+ m2c_token_t lookahead ;
168
+
169
+
170
+
171
+ return lookahead ;
172
+ } /* end ident_list */
173
+
174
+
175
+ /* END OF FILE */
0 commit comments