Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/oldagsrc/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 AnaGram Syntax Analyzer. | |
3 Copyright (c) Parsifal Software, 1993-1999. | |
4 All Rights Reserved. | |
5 | |
6 Configuration file module | |
7 */ | |
8 | |
9 //#define INCLUDE_LOGGING | |
10 | |
11 #include "arrays.h" //ARRAYS | |
12 #include "assert.h" //ASSERT | |
13 #include "cint.h" | |
14 #include "config.h" | |
15 #include "data.h" //DATA | |
16 #include "error.h" | |
17 #include "log.hpp" | |
18 #include "myalloc.h" //MYALLOC | |
19 #include "pf.h" //PF | |
20 #include "tfile.h" //TFILE | |
21 #include <ctype.h> //CTYPE | |
22 #include <stdlib.h> //STDLIB | |
23 #include <string.h> //STRING | |
24 | |
25 #undef MODULE | |
26 #define MODULE 50 | |
27 } | |
28 [ | |
29 auto resynch | |
30 context type = cint | |
31 grammar token = config file | |
32 ~declare pcb | |
33 diagnose errors | |
34 lines and columns | |
35 line numbers | |
36 ~allow macros | |
37 line numbers | |
38 error frame | |
39 nest comments | |
40 ~test range | |
41 token names | |
42 pointer input | |
43 default token type = int | |
44 parser file name = "#.cpp" | |
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(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 *); | |
271 | |
272 class CfErrorHandler : public ConfigParam::ErrorHandler { | |
273 void badParam(const char *s){cf_error(s);} | |
274 } cfErrorHandler; | |
275 | |
276 | |
277 | |
278 static cf_pcb_type cfcb; | |
279 #define PCB cfcb | |
280 | |
281 extern unsigned char *input_base; | |
282 | |
283 static AgString config_file; | |
284 | |
285 void read_config(const AgString path) { | |
286 LOGSECTION("read_config"); | |
287 LOGV(path); | |
288 config_file = path.lastCut(PATH_DELIMITER).leftI().concat("AnaGram.cfg"); | |
289 text_file tf(config_file); | |
290 cfcb.pointer = input_base = (unsigned char *) tf; | |
291 if (input_base) cf(); | |
292 config_file = "AnaGram.cfg"; | |
293 tf = text_file(config_file); | |
294 cfcb.pointer = input_base = (unsigned char *) tf; | |
295 LOGS("Starting parse"); | |
296 if (input_base) cf(); | |
297 } | |
298 | |
299 static void cf_error(const char *msg) { | |
300 errorList.push(Error(config_file, msg, 1)); | |
301 } | |
302 | |
303 Error::Error(AgString f, AgString msg, int contextFlag) | |
304 : file(f), | |
305 line(contextFlag? ERROR_CONTEXT.y : PCB.line), | |
306 column(contextFlag? ERROR_CONTEXT.y :PCB.column), | |
307 key(warn), | |
308 message(msg) | |
309 { | |
310 // Nothing here | |
311 } | |
312 | |
313 | |
314 static void cf_syn_error(void) { | |
315 reset_stk(); | |
316 cf_error(PCB.error_message); | |
317 } | |
318 | |
319 | |
320 int allow_macros = 1; | |
321 int auto_init = 1; | |
322 int auto_resynch = 0; | |
323 int backtrack = 1; | |
324 int bottom_margin = 3; | |
325 int bright_background = 1; | |
326 | |
327 int case_sensitive = 1; | |
328 AgString compile_command(""); | |
329 int const_data = 1; | |
330 AgString context_type; | |
331 AgString coverage_file_name("#.nrc"); | |
332 | |
333 int declare_pcb = 1; | |
334 int default_input_type; | |
335 int default_token_type; | |
336 int default_reductions = 1; | |
337 int diagnose_errors = 1; | |
338 int distinguish_lexemes = 0; | |
339 | |
340 AgString edit_command("ed #.syn"); | |
341 int enable_mouse = 1; | |
342 AgString enum_constant_name("$_%_token"); | |
343 int error_frame = 0; | |
344 int error_trace = 0; | |
345 int escape_backslashes = 0; | |
346 int event_driven = 0; | |
347 | |
348 int far_tables = 0; | |
349 | |
350 int grammar_token = 0; | |
351 AgString header_file_name("#.h"); | |
352 int input_values = 0; | |
353 int iso_latin_1 = 1; | |
354 | |
355 int line_length = 80; | |
356 int line_numbers = 0; | |
357 AgString line_numbers_path; | |
358 int lines_and_columns = 1; | |
359 | |
360 int main_program = 1; | |
361 int max_conflicts = 50; | |
362 //AgString mutex_type; | |
363 | |
364 int near_functions = 0; | |
365 int nest_comments = 0; | |
366 | |
367 int old_style = 0; | |
368 | |
369 int page_length = 66; | |
370 AgString parser_file_name("#.c"); | |
371 AgString parser_name("#"); | |
372 int parser_stack_alignment; | |
373 int parser_stack_size = 32; | |
374 int pointer_input = 0; | |
375 AgString pointer_type("unsigned char *"); | |
376 AgString print_file_name("LPT1"); | |
377 | |
378 int quick_reference = 0; | |
379 | |
380 int reduction_choices =0; | |
381 int reentrant_parser = 0; | |
382 int rule_coverage = 0; | |
383 | |
384 int tab_spacing = 8; | |
385 int test_file_binary = 0; | |
386 AgString test_file_mask("*.*"); | |
387 int test_range = 1; | |
388 int token_names = 0; | |
389 int top_margin = 3; | |
390 int traditional_engine = 0; | |
391 | |
392 int video_mode = -1; | |
393 | |
394 int trial_copy_code = 0; | |
395 | |
396 int error_token; | |
397 int eof_token = 0; | |
398 | |
399 } | |
400 | |
401 | |
402 |