Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/agcore/cf.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 { | |
2 /* | |
3 * AnaGram, A System for Syntax Directed Programming | |
4 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
5 * | |
6 * cf.syn - Configuration file module | |
7 */ | |
8 | |
9 #include "port.h" | |
10 | |
11 #include "agstring.h" | |
12 #include "assert.h" | |
13 #include "cf-defs.h" | |
14 #include "cint.h" | |
15 #include "config.h" | |
16 #include "configparam.h" | |
17 #include "error.h" | |
18 #include "file.h" | |
19 #include "operations.h" | |
20 #include "stacks.h" | |
21 #include "textfile.h" | |
22 | |
23 //#define INCLUDE_LOGGING | |
24 #include "log.h" | |
25 } | |
26 | |
27 [ | |
28 auto resynch | |
29 context type = cint | |
30 grammar token = config file | |
31 ~declare pcb | |
32 diagnose errors | |
33 lines and columns | |
34 line numbers | |
35 ~allow macros | |
36 line numbers | |
37 error frame | |
38 nest comments | |
39 ~test range | |
40 token names | |
41 pointer input | |
42 default token type = int | |
43 parser file name = "#.cpp" | |
44 line numbers path = "cf.syn" | |
45 escape backslashes | |
46 ] | |
47 | |
48 any digit = digit + hex letter | |
49 backslash = '\\' | |
50 blank char = ' ' + '\t' | |
51 carriage return = '\r' | |
52 digit = '0-9' | |
53 double quote = '"' | |
54 eof = 0 + 26 | |
55 eol chars = newline + carriage return | |
56 hex letter = 'a-f' + 'A-F' | |
57 letter = 'a-z' + 'A-Z' + '_' | |
58 newline = '\n' | |
59 nonoctal digit = any digit - octal digit | |
60 octal digit = '0-7' | |
61 simple string char = ~eof - (any digit + double quote + backslash + eol chars) | |
62 tab = '\t' | |
63 vertical space = '\f' + '\v' | |
64 | |
65 equals | |
66 -> '=', space? | |
67 | |
68 minus | |
69 -> '-', space? | |
70 | |
71 plus | |
72 -> '+', space? | |
73 | |
74 tilde | |
75 -> '~', space? | |
76 | |
77 left parenthesis | |
78 -> '(', space? | |
79 | |
80 right parenthesis | |
81 -> ')', blank?... | |
82 | |
83 | |
84 config file | |
85 -> blank?..., [global parameter | end of line]/..., eof | |
86 | |
87 (void) global parameter | |
88 -> name =ConfigParam::set(1, cfErrorHandler); //cf_gp4(1); | |
89 -> tilde, name =ConfigParam::set(0, cfErrorHandler); //cf_gp4(0); | |
90 -> name, equals, data type =ConfigParam::set(cfErrorHandler); //cf_gp2(); | |
91 -> name, equals, keyword string =ConfigParam::set(cfErrorHandler); //cf_gp3(); | |
92 -> name, equals, number:n =ConfigParam::set(n, cfErrorHandler); //cf_gp5(n); | |
93 | |
94 (void) data type | |
95 -> name | |
96 -> name, abstract declarator =concat_string(); | |
97 | |
98 (void) abstract declarator | |
99 -> indirect data type | |
100 -> direct abstract declarator | |
101 -> indirect data type, direct abstract declarator =concat_string(); | |
102 | |
103 | |
104 (void) direct abstract declarator | |
105 -> {left parenthesis =scs('('),0;}, abstract declarator, | |
106 right parenthesis =concat_string(), acs(')'); | |
107 | |
108 (void) pointer | |
109 -> star | |
110 -> star, name =concat_string(); | |
111 | |
112 (void) star | |
113 -> '*', blank?... =sss(" *"); | |
114 | |
115 (void) indirect data type | |
116 -> pointer | |
117 -> indirect data type, pointer =concat_string(); | |
118 | |
119 (void) name string | |
120 -> letter:a =scs(a); | |
121 -> name string, letter + digit :a =acs(a); | |
122 -> name string, blank..., letter + digit :a =acs(' '), acs(a); | |
123 | |
124 name | |
125 -> name string, blank?... | |
126 | |
127 blank | |
128 -> blank char | |
129 -> c comment | |
130 | |
131 space | |
132 -> blank... | |
133 -> blank..., continuation | |
134 -> continuation | |
135 | |
136 continuation | |
137 -> comment, next line | |
138 -> next line | |
139 | |
140 next line | |
141 -> carriage return?, newline | |
142 -> carriage return?, newline, blank... | |
143 | |
144 white | |
145 -> blank | |
146 -> carriage return?, newline | |
147 -> comment, carriage return?, newline | |
148 | |
149 end of line | |
150 -> comment, carriage return?, newline | |
151 -> carriage return?, newline | |
152 -> end of line, white | |
153 -> end of line, vertical space //form feed | |
154 | |
155 comment | |
156 -> "//", ~eol chars & ~eof?... | |
157 | |
158 decimal number | |
159 -> '1-9':d =d - '0'; | |
160 -> decimal number:n, '0-9':d =10*n + d - '0'; | |
161 | |
162 octal number | |
163 -> '0' =0; | |
164 -> octal number:n, '0-7':d =8*n + d - '0'; | |
165 | |
166 hex number | |
167 -> "0x" =0; | |
168 -> "0X" =0; | |
169 -> hex number:n, '0-9':d =16*n + d - '0'; | |
170 -> hex number:n, 'A-F' + 'a-f':d =16*n + (d&7) + 9; | |
171 | |
172 simple number | |
173 -> decimal number | |
174 -> octal number | |
175 -> hex number | |
176 | |
177 number | |
178 -> sign:s, simple number:n, blank?... =s*n; | |
179 | |
180 sign | |
181 -> plus? =1; | |
182 -> minus =-1; | |
183 | |
184 keyword string | |
185 -> keyword string head, string, double quote, blank?... | |
186 | |
187 string | |
188 -> string A | string B | string C | |
189 | |
190 (void) keyword string head | |
191 -> double quote =ics(); | |
192 | |
193 string char | |
194 -> simple string char | |
195 -> escape sequence | |
196 | |
197 escape sequence | |
198 -> "\\a" ='\a'; | |
199 -> "\\b" ='\b'; | |
200 -> "\\f" ='\f'; | |
201 -> "\\n" ='\n'; | |
202 -> "\\r" ='\r'; | |
203 -> "\\t" ='\t'; | |
204 -> "\\v" ='\v'; | |
205 -> "\\\\" ='\\'; | |
206 -> "\\?" = '\?'; | |
207 -> "\\'" ='\''; | |
208 -> "\\\"" ='"'; | |
209 -> three octal:n =n==0?cf_error("Null character in string"),0 : n; | |
210 | |
211 one octal | |
212 -> backslash, '0-7':n =n&7; | |
213 | |
214 two octal | |
215 -> one octal:n, '0-7':d = n*8 + (d&7); | |
216 | |
217 three octal | |
218 -> two octal:n, '0-7':d = n*8 + (d&7); | |
219 | |
220 octal escape | |
221 -> {one octal | two octal}:n = | |
222 n==0?cf_error("Null character in string"),0 : n; | |
223 | |
224 hex escape | |
225 -> "\\x", hex number:n =n; | |
226 | |
227 (void) string A | |
228 -> string char:c =acs(c); | |
229 -> any digit:c =acs(c); | |
230 -> string, string char:c =acs(c); | |
231 -> string A, any digit:c =acs(c); | |
232 -> string B, nonoctal digit:c =acs(c); | |
233 | |
234 (void) string B | |
235 -> octal escape:n =acs(n); | |
236 -> string, octal escape:n =acs(n); | |
237 | |
238 (void) string C | |
239 -> hex escape:n =acs(n); | |
240 -> string, hex escape:n =acs(n); | |
241 | |
242 (void) c comment | |
243 -> c comment text, "*/" | |
244 | |
245 (void) c comment text | |
246 -> "/*" | |
247 -> c comment text, ~eof | |
248 | |
249 c comment, c comment text | |
250 -> c comment text, c comment = | |
251 { if (nest_comments) PCB.reduction_token = cf_c_comment_text_token; } | |
252 | |
253 [ | |
254 hidden { | |
255 left parenthesis, right parenthesis, | |
256 pointer, indirect data type, name string, | |
257 space, next line, sign, one octal, two octal, three octal, | |
258 string A, string B, string C, c comment text, escape sequence, | |
259 octal escape, hex escape, name string | |
260 } | |
261 ] | |
262 | |
263 { | |
264 | |
265 #define PARSER_STACK_OVERFLOW assert(0) | |
266 #define REDUCTION_TOKEN_ERROR assert(0) | |
267 #define SYNTAX_ERROR cf_syn_error() | |
268 #define GET_CONTEXT CONTEXT.x = PCB.column, CONTEXT.y = PCB.line | |
269 | |
270 static void cf_error(const char *, int = 1); | |
271 | |
272 class CfErrorHandler : public ConfigParam::ErrorHandler { | |
273 public: | |
274 virtual ~CfErrorHandler() {} | |
275 virtual void badParam(const char *s){cf_error(s);} | |
276 } cfErrorHandler; | |
277 | |
278 | |
279 | |
280 static cf_pcb_type cfcb; | |
281 #define PCB cfcb | |
282 | |
283 static AgString config_file; | |
284 | |
285 static void read_one_config(const AgString &dir) { | |
286 LOGSECTION("read_one_config"); | |
287 LOGV(dir); | |
288 | |
289 char delim[2]; | |
290 delim[0] = PATH_DELIMITER; | |
291 delim[1] = 0; | |
292 | |
293 config_file = dir.concat(delim).concat("AnaGram.cfg"); | |
294 LOGV(config_file); | |
295 | |
296 text_file tf(config_file); | |
297 cfcb.pointer = input_base = (unsigned char *) tf; | |
298 if (input_base) cf(); | |
299 } | |
300 | |
301 void read_config(const AgString mydir) { | |
302 LOGSECTION("read_config"); | |
303 LOGV(mydir); | |
304 LOGV(work_dir_name); | |
305 | |
306 read_one_config(mydir); | |
307 read_one_config(work_dir_name); | |
308 } | |
309 | |
310 static void cf_error(const char *msg, int contextFlag) { | |
311 int line, column; | |
312 if (contextFlag) { | |
313 line = CONTEXT.y; | |
314 column = CONTEXT.x; | |
315 } | |
316 else { | |
317 line = PCB.line; | |
318 column = PCB.column; | |
319 } | |
320 errorList.push(Error(line, column, config_file, msg)); | |
321 } | |
322 | |
323 static void cf_syn_error(void) { | |
324 reset_stk(); | |
325 cf_error(PCB.error_message, 0); | |
326 } | |
327 | |
328 } |