1 | %{ |
---|
2 | /**************************************** |
---|
3 | * Computer Algebra System SINGULAR * |
---|
4 | ****************************************/ |
---|
5 | /* $Id: libparse.l,v 1.8 1998-04-22 08:40:55 krueger Exp $ */ |
---|
6 | #include <stdio.h> |
---|
7 | #include <string.h> |
---|
8 | #include <stdlib.h> |
---|
9 | #include <ctype.h> |
---|
10 | #ifdef STANDALONE_PARSER |
---|
11 | # include "utils.h" |
---|
12 | # define HAVE_LIBPARSER |
---|
13 | //# define YYLPDEBUG 3 |
---|
14 | #else |
---|
15 | # include "mod2.h" |
---|
16 | # include "subexpr.h" |
---|
17 | # include "grammar.h" |
---|
18 | # include "ipshell.h" |
---|
19 | # include "ipid.h" |
---|
20 | # include "tok.h" |
---|
21 | # include "febase.h" |
---|
22 | # include "mmemory.h" |
---|
23 | #endif |
---|
24 | #include "libparse.h" |
---|
25 | |
---|
26 | #ifdef HAVE_LIBPARSER |
---|
27 | #define YY_SKIP_YYWRAP |
---|
28 | |
---|
29 | typedef enum { LP_NONE, LP_INFO, LP_VERSION} lib_cmds; |
---|
30 | |
---|
31 | int libread(FILE* f, char* buf, int max_size); |
---|
32 | int current_pos(int i); |
---|
33 | void print_version(lp_modes mode, char *p); |
---|
34 | void copy_string(lp_modes mode); |
---|
35 | void make_version(char *p, int what); |
---|
36 | |
---|
37 | int brace1 = 0; /* { } */ |
---|
38 | int brace2 = 0; /* ( ) */ |
---|
39 | int brace3 = 0; /* [ ] */ |
---|
40 | int quote = 0; /* " */ |
---|
41 | int offset = 0; |
---|
42 | BOOLEAN p_static = FALSE; |
---|
43 | int old_state = 0; |
---|
44 | lib_cmds last_cmd = LP_NONE; |
---|
45 | |
---|
46 | char libnamebuf[128]; |
---|
47 | char *text_buffer; |
---|
48 | long string_start; |
---|
49 | |
---|
50 | char *yylp_buffer_start; |
---|
51 | int yylplineno = 1; |
---|
52 | |
---|
53 | char *yylp_errlist[]= { |
---|
54 | "", |
---|
55 | "missing close bracket ')' for proc definition in line %d.", /* 1 */ |
---|
56 | "missing close bracket ')' for procbody in line %d.", /* 2 */ |
---|
57 | "missing close bracket ']' for procbody in line %d.", /* 3 */ |
---|
58 | "too many ')' closed brackets in line %d.", /* 4 */ |
---|
59 | "too many ']' closed brackets in line %d.", /* 5 */ |
---|
60 | "missing close bracket ')' for example in line %d.", /* 6 */ |
---|
61 | "missing close bracket ']' for example in line %d.", /* 7 */ |
---|
62 | "cannot assign charater in line %d to any group.", /* 8 */ |
---|
63 | "there must be a quote missing somewhere before line %d.", /* 9 */ |
---|
64 | "missing close bracket '}' at end of library in line %d.", /* 10 */ |
---|
65 | "missing close bracket ')' at end of library in line %d.", /* 11 */ |
---|
66 | "missing close bracket ']' at end of library in line %d.", /* 12 */ |
---|
67 | NULL |
---|
68 | }; |
---|
69 | int yylp_errno = 0; |
---|
70 | |
---|
71 | #define YYLP_ERR_NONE 0 |
---|
72 | #define YYLP_DEF_BR2 1 |
---|
73 | #define YYLP_BODY_BR2 2 |
---|
74 | #define YYLP_BODY_BR3 3 |
---|
75 | #define YYLP_BODY_TMBR2 4 |
---|
76 | #define YYLP_BODY_TMBR3 5 |
---|
77 | #define YYLP_EX_BR2 6 |
---|
78 | #define YYLP_EX_BR3 7 |
---|
79 | #define YYLP_BAD_CHAR 8 |
---|
80 | #define YYLP_MISSQUOT 9 |
---|
81 | #define YYLP_MISS_BR1 10 |
---|
82 | #define YYLP_MISS_BR2 11 |
---|
83 | #define YYLP_MISS_BR3 12 |
---|
84 | |
---|
85 | #ifdef __MWERKS__ |
---|
86 | #ifdef __cplusplus |
---|
87 | extern "C" { |
---|
88 | #endif |
---|
89 | #ifdef macintosh |
---|
90 | int fileno(FILE *stream); |
---|
91 | FILE *fdopen(int filedes, char *type); |
---|
92 | long ftell(FILE *fp); |
---|
93 | long tell(int filedes); |
---|
94 | int isatty(int filedes); |
---|
95 | #else |
---|
96 | int _fileno(FILE *stream); |
---|
97 | FILE *_fdopen(int filedes, char *type); |
---|
98 | long _ftell(FILE *fp); |
---|
99 | long _tell(int filedes); |
---|
100 | int _isatty(int filedes); |
---|
101 | #define fileno _fileno |
---|
102 | #define fdopen _fdopen |
---|
103 | #define ftell _ftell |
---|
104 | #define tell _tell |
---|
105 | #define isatty _isatty |
---|
106 | #endif /* macintosh */ |
---|
107 | #ifdef __cplusplus |
---|
108 | } |
---|
109 | #endif |
---|
110 | #endif |
---|
111 | |
---|
112 | #ifdef STANDALONE_PARSER |
---|
113 | procinfov pi; |
---|
114 | printpi(procinfov pi); |
---|
115 | pi_clear(procinfov pi); |
---|
116 | extern "C" { |
---|
117 | int yylpwrap(); |
---|
118 | } |
---|
119 | #else /* STANDALONE_PARSER */ |
---|
120 | idhdl h0; |
---|
121 | # define pi IDPROC(h0) |
---|
122 | extern "C" |
---|
123 | { |
---|
124 | int yylpwrap(); |
---|
125 | } |
---|
126 | extern libstackv library_stack; |
---|
127 | #endif /* STANDALONE_PARSER */ |
---|
128 | |
---|
129 | #define SET_DEF_END(mode, pi, p) \ |
---|
130 | if ( mode == LOAD_LIB) pi->data.s.def_end = p; |
---|
131 | #define SET_HELP_START(mode, pi, p) \ |
---|
132 | if ( mode == LOAD_LIB) pi->data.s.help_start = p; \ |
---|
133 | |
---|
134 | #define SET_BODY_START(mode, pi, l, p) \ |
---|
135 | if ( mode == LOAD_LIB) { \ |
---|
136 | pi->data.s.body_lineno = l; \ |
---|
137 | pi->data.s.body_start = p; \ |
---|
138 | } |
---|
139 | #define SET_BODY_END(mode, pi, p) \ |
---|
140 | if ( mode == LOAD_LIB) { \ |
---|
141 | pi->data.s.body_end = p-1; \ |
---|
142 | pi->data.s.proc_end = p-1; \ |
---|
143 | } |
---|
144 | |
---|
145 | #define SET_EXAMPLE_START(mode, pi, l, p) \ |
---|
146 | if ( mode == LOAD_LIB) { \ |
---|
147 | pi->data.s.example_lineno = l; \ |
---|
148 | pi->data.s.example_start = p; \ |
---|
149 | } |
---|
150 | #define SET_PROC_END(mode, pi, p) \ |
---|
151 | if ( mode == LOAD_LIB) { \ |
---|
152 | pi->data.s.proc_end = p-1; \ |
---|
153 | if(pi->data.s.body_end==0) pi->data.s.body_end = p-1; \ |
---|
154 | } |
---|
155 | |
---|
156 | #undef YY_DECL |
---|
157 | #define YY_DECL int yylex(char *newlib, char *libfile, \ |
---|
158 | lib_style_types *lib_style, \ |
---|
159 | lp_modes mode) |
---|
160 | |
---|
161 | #undef YY_INPUT |
---|
162 | #define YY_INPUT(buf,result,max_size) \ |
---|
163 | if ( ((result = libread( (yyin), (char *) buf, max_size )) < 0 ) \ |
---|
164 | && ferror( yyin ) ) \ |
---|
165 | YY_FATAL_ERROR( "read in flex scanner failed" ); |
---|
166 | |
---|
167 | #define YY_USER_INIT { \ |
---|
168 | BEGIN(header); \ |
---|
169 | yylplineno = 1; \ |
---|
170 | yylp_errno = 0; \ |
---|
171 | *lib_style = OLD_LIBSTYLE; \ |
---|
172 | strcpy(libnamebuf,"(**unknown version**)"); \ |
---|
173 | } |
---|
174 | |
---|
175 | #if 0 |
---|
176 | <pbody>proc[ \t]+{name} { |
---|
177 | printf("MISSING: PROC-cmd found. ERROR!\n"); } |
---|
178 | <pbody>example[ \t]*\n { |
---|
179 | yylplineno++; |
---|
180 | printf("MISSING: EXAMPLE-cmd found. ERROR!\n"); } |
---|
181 | #endif |
---|
182 | %} |
---|
183 | |
---|
184 | digit [0-9] |
---|
185 | letter [@a-zA-Z\'] |
---|
186 | name ({letter}({letter}*{digit}*_*)*|_) |
---|
187 | letters ({letter}|{digit}|[_./#%^*:,]) |
---|
188 | string ({letters}*) |
---|
189 | comment [\/][\/] |
---|
190 | dolar [$] |
---|
191 | symbols [~!@#$%^&*()_+-={}\\\|\[\];:,<.>/\?\' \n\~\`\r] |
---|
192 | aletters ({letter}|{digit}|{symbols}|{dolar}|{escquote}) |
---|
193 | strings ({aletters}*) |
---|
194 | quote [\"] |
---|
195 | escquote (\\\") |
---|
196 | taborspace [ \t] |
---|
197 | tos ({taborspace}*) |
---|
198 | |
---|
199 | /* %start START */ |
---|
200 | |
---|
201 | %x header |
---|
202 | %x help |
---|
203 | %x libcmd |
---|
204 | %x pdef |
---|
205 | %x phead |
---|
206 | %x pbody |
---|
207 | %x pstr |
---|
208 | %x pexample |
---|
209 | %x pestr |
---|
210 | %x string |
---|
211 | %x comment |
---|
212 | |
---|
213 | %% |
---|
214 | (\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { } |
---|
215 | \/\/* { old_state = YYSTATE; BEGIN(comment); } |
---|
216 | |
---|
217 | info=+"\"" { old_state = YYSTATE; quote++; BEGIN(string); |
---|
218 | string_start = current_pos(yyleng); |
---|
219 | *lib_style = NEW_LIBSTYLE; |
---|
220 | last_cmd = LP_INFO; |
---|
221 | } |
---|
222 | |
---|
223 | (version=+{quote}+{strings}+{quote})|(version+{tos}+=+{quote}+{strings}+{quote})|(version+{tos}+=+{tos}+{quote}+{strings}+{quote})|(version=+{tos}+{quote}+{strings}+{quote}) { |
---|
224 | if ( mode != GET_INFO ) { |
---|
225 | make_version(yytext,1); |
---|
226 | #ifdef STANDALONE_PARSER |
---|
227 | printf("Version:%s;\n", libnamebuf); |
---|
228 | #else |
---|
229 | //text_buffer = mstrdup(libnamebuf); |
---|
230 | print_version(mode, libnamebuf); |
---|
231 | #endif |
---|
232 | } |
---|
233 | } |
---|
234 | |
---|
235 | static { p_static=TRUE; } |
---|
236 | |
---|
237 | (proc[ \t]+{name})|([ \t]proc[ \t]+{name}) { |
---|
238 | char proc[256]; |
---|
239 | BEGIN(pdef); |
---|
240 | #if YYLPDEBUG > 0 |
---|
241 | printf("Newlib:%s\n", newlib); |
---|
242 | #endif |
---|
243 | #ifdef STANDALONE_PARSER |
---|
244 | if ( pi != NULL ) { |
---|
245 | printpi(pi); |
---|
246 | pi_clear(pi); |
---|
247 | } |
---|
248 | pi = (procinfo *)malloc(sizeof(procinfo)); |
---|
249 | iiInitSingularProcinfo(pi, newlib, yytext+5, yylplineno, |
---|
250 | current_pos(0), p_static); |
---|
251 | #else STANDALONE_PARSER |
---|
252 | if( mode == LOAD_LIB) { |
---|
253 | proc[0]='\0'; |
---|
254 | sscanf( yytext, "%*[^p]proc %s", proc); |
---|
255 | if(strlen(proc)<1) sscanf( yytext, "proc %s", proc); |
---|
256 | h0 = enterid( mstrdup(proc), myynest, PROC_CMD, |
---|
257 | &idroot, FALSE ); |
---|
258 | if (h0!=NULL) { |
---|
259 | iiInitSingularProcinfo(IDPROC(h0), newlib, proc, |
---|
260 | yylplineno, current_pos(0),p_static); |
---|
261 | if (BVERBOSE(V_LOAD_PROC)) |
---|
262 | Warn( " proc %s loaded", proc ); |
---|
263 | } |
---|
264 | #endif STANDALONE_PARSER |
---|
265 | SET_DEF_END(mode, pi, current_pos(yyleng+1)); |
---|
266 | #if YYLPDEBUG |
---|
267 | printf("PROC %d at %d/%d: (%d) %s\n", p_static, |
---|
268 | yylplineno, current_pos(0), brace1, yytext); |
---|
269 | #endif |
---|
270 | p_static=FALSE; |
---|
271 | #ifndef STANDALONE_PARSER |
---|
272 | } |
---|
273 | #endif STANDALONE_PARSER |
---|
274 | } |
---|
275 | example { |
---|
276 | BEGIN(pexample); |
---|
277 | SET_EXAMPLE_START(mode, pi, yylplineno, current_pos(0)); |
---|
278 | #if YYLPDEBUG |
---|
279 | printf("EXAMPLE at %d/%d (%d)\n", yylplineno, |
---|
280 | current_pos(0), brace1); |
---|
281 | #endif |
---|
282 | } |
---|
283 | |
---|
284 | LIB[ \t]+"\"" { quote++; |
---|
285 | BEGIN(libcmd); |
---|
286 | } |
---|
287 | |
---|
288 | <header>({comment}+{tos}+{dolar}+Id:+{string}+[^\n]*)|({comment}+{tos}+{dolar}+Header:+{string}+[^\n]*) { |
---|
289 | make_version(yytext, 0); |
---|
290 | //print_version(mode, ""); |
---|
291 | #if YYLPDEBUG > 1 |
---|
292 | printf("+(id)HEAD:%s\n", yytext); |
---|
293 | #endif |
---|
294 | } |
---|
295 | <header>(^{comment}+[^\n]*) { |
---|
296 | #if YYLPDEBUG > 1 |
---|
297 | printf("+(cmt)HEAD:%s\n", yytext); |
---|
298 | #endif |
---|
299 | } |
---|
300 | <header>(^#![^\n]*) { |
---|
301 | #if YYLPDEBUG > 1 |
---|
302 | printf("-HEAD:%s\n", yytext); |
---|
303 | #endif |
---|
304 | } |
---|
305 | <header>^proc\ { yyless(0); |
---|
306 | //print_version(mode, libfile); |
---|
307 | BEGIN(INITIAL); |
---|
308 | yymore(); |
---|
309 | } |
---|
310 | <header>(info=\")|(version=\")|(version+{tos}+=\")|(version+{tos}+=+{tos}+\")|(version=+{tos}+\") { yyless(0); |
---|
311 | *lib_style = NEW_LIBSTYLE; |
---|
312 | BEGIN(INITIAL); |
---|
313 | yymore(); |
---|
314 | } |
---|
315 | |
---|
316 | <header>^LIB[ \t]+"\"" { quote++; |
---|
317 | //print_version(mode, libfile); |
---|
318 | BEGIN(libcmd); |
---|
319 | } |
---|
320 | <header>\n { yylplineno++; } |
---|
321 | <header>. { |
---|
322 | #if YYLPDEBUG > 1 |
---|
323 | printf(" HEAD:%s\n", yytext); |
---|
324 | #endif |
---|
325 | //print_version(mode, libfile); |
---|
326 | BEGIN(help); |
---|
327 | } |
---|
328 | <help>(^{comment}+[^\n]*) { |
---|
329 | #if YYLPDEBUG > 1 |
---|
330 | printf(" HELP:%s\n", yytext); |
---|
331 | #endif |
---|
332 | BEGIN(INITIAL); } |
---|
333 | <help>(^#![^\n]*) { |
---|
334 | #if YYLPDEBUG > 1 |
---|
335 | printf(" HELP:%s\n", yytext); |
---|
336 | #endif |
---|
337 | BEGIN(INITIAL); |
---|
338 | } |
---|
339 | <help>(info=\")|(version=\")|(version+{tos}+=\")|(version+{tos}+=+{tos}+\")|(version=+{tos}+\") { yyless(0); |
---|
340 | *lib_style = NEW_LIBSTYLE; |
---|
341 | BEGIN(INITIAL); |
---|
342 | yymore(); |
---|
343 | } |
---|
344 | <help>^proc\ { |
---|
345 | yyless(0); |
---|
346 | //printf("2) proc found.\n"); |
---|
347 | BEGIN(INITIAL); |
---|
348 | yymore(); |
---|
349 | } |
---|
350 | <help>^LIB[ \t]+"\"" { quote++; |
---|
351 | BEGIN(libcmd); |
---|
352 | } |
---|
353 | |
---|
354 | <help>\n { yylplineno++; } |
---|
355 | <help>. { |
---|
356 | #if YYLPDEBUG > 1 |
---|
357 | printf("-HELP:%s\n", yytext); |
---|
358 | #endif |
---|
359 | } |
---|
360 | |
---|
361 | |
---|
362 | <libcmd>{string}"\"" { quote--; |
---|
363 | yytext[yyleng-1] = '\0'; |
---|
364 | #ifndef STANDALONE_PARSER |
---|
365 | if ( mode == LOAD_LIB ) { |
---|
366 | library_stack->push(newlib, yytext); |
---|
367 | } |
---|
368 | #endif /* STANDALONE_PARSER */ |
---|
369 | #if YYLPDEBUG |
---|
370 | printf("LIB:'%s'\n", yytext); |
---|
371 | #endif |
---|
372 | BEGIN(INITIAL); |
---|
373 | } |
---|
374 | |
---|
375 | <pdef>[ \t] { } |
---|
376 | <pdef>\( { |
---|
377 | brace2++; |
---|
378 | #if YYLPDEBUG |
---|
379 | printf("%s", yytext); |
---|
380 | #endif |
---|
381 | } |
---|
382 | <pdef>\) { |
---|
383 | brace2--; |
---|
384 | #if YYLPDEBUG |
---|
385 | printf(">%s<\n", yytext); |
---|
386 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
387 | #endif |
---|
388 | if(brace2<=0) { |
---|
389 | #if YYLPDEBUG |
---|
390 | printf("BEGIN(phead){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
391 | #endif |
---|
392 | SET_DEF_END(mode, pi, current_pos(yyleng)); |
---|
393 | SET_HELP_START(mode, pi, current_pos(yyleng)); |
---|
394 | BEGIN(phead); |
---|
395 | } |
---|
396 | } |
---|
397 | <pdef>"{" { |
---|
398 | if(brace2>0) { |
---|
399 | #if YYLPDEBUG |
---|
400 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
401 | #endif |
---|
402 | yylp_errno = YYLP_DEF_BR2; |
---|
403 | return(1); |
---|
404 | } else { |
---|
405 | brace1++; BEGIN(pbody); |
---|
406 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
407 | } |
---|
408 | } |
---|
409 | <pdef>\n { yylplineno++; |
---|
410 | if(brace2<=0) { |
---|
411 | #if YYLPDEBUG |
---|
412 | printf("BEGIN(phead-2){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
413 | #endif |
---|
414 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
415 | BEGIN(phead); |
---|
416 | } |
---|
417 | } |
---|
418 | <pdef>. { |
---|
419 | if(brace2<=0) { |
---|
420 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
421 | BEGIN(phead); |
---|
422 | } |
---|
423 | } |
---|
424 | |
---|
425 | <phead>"\\{" { } |
---|
426 | <phead>"{" { |
---|
427 | brace1++; BEGIN(pbody); |
---|
428 | #if YYLPDEBUG |
---|
429 | printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
430 | #endif |
---|
431 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
432 | #if YYLPDEBUG |
---|
433 | printf("BODY at %d/%d", yylplineno, current_pos(0)); |
---|
434 | #endif |
---|
435 | } |
---|
436 | <phead>\n { yylplineno++; } |
---|
437 | <phead>. { } |
---|
438 | |
---|
439 | <pbody>({comment}[^\n]*) { } |
---|
440 | <pbody>"\"" { quote++; old_state = YYSTATE; |
---|
441 | BEGIN(string); /* printf("%s", yytext); */ |
---|
442 | } |
---|
443 | <pbody>"{" { |
---|
444 | brace1++; |
---|
445 | #if YYLPDEBUG |
---|
446 | printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); |
---|
447 | #endif |
---|
448 | } |
---|
449 | <pbody>"}" { |
---|
450 | #if YYLPDEBUG |
---|
451 | printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); |
---|
452 | #endif |
---|
453 | brace1--; |
---|
454 | if(brace2>0) { |
---|
455 | yylp_errno = YYLP_BODY_BR2; |
---|
456 | return(1); |
---|
457 | } |
---|
458 | if(brace3>0) { |
---|
459 | yylp_errno = YYLP_BODY_BR3; |
---|
460 | return(1); |
---|
461 | } |
---|
462 | if(brace1<=0) { |
---|
463 | SET_BODY_END(mode, pi, current_pos(yyleng)); |
---|
464 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
465 | #if YYLPDEBUG |
---|
466 | printf("-%d\n", current_pos(0)); |
---|
467 | #endif |
---|
468 | BEGIN(INITIAL); |
---|
469 | } |
---|
470 | } |
---|
471 | <pbody>"(" { |
---|
472 | brace2++; /* printf("%s", yytext); */ |
---|
473 | } |
---|
474 | <pbody>")" { |
---|
475 | brace2--; /* printf("%s", yytext); */ |
---|
476 | if(brace2<0) { |
---|
477 | yylp_errno = YYLP_BODY_TMBR2; |
---|
478 | return(1); |
---|
479 | } |
---|
480 | } |
---|
481 | <pbody>"[" { |
---|
482 | brace3++; /* printf("%s", yytext); */ |
---|
483 | } |
---|
484 | <pbody>"]" { |
---|
485 | brace3--; /* printf("%s", yytext); */ |
---|
486 | if(brace3<0) { |
---|
487 | yylp_errno = YYLP_BODY_TMBR3; |
---|
488 | return(1); |
---|
489 | } |
---|
490 | } |
---|
491 | <pbody>\n { yylplineno++; } |
---|
492 | <pbody>. { } |
---|
493 | |
---|
494 | <string>"\"" { quote--; |
---|
495 | copy_string(mode); |
---|
496 | last_cmd = LP_NONE; |
---|
497 | BEGIN(old_state); /* printf("%s", yytext); */ |
---|
498 | } |
---|
499 | <string>(\\\\)|(\\\") { } |
---|
500 | <string>\n { yylplineno++; } |
---|
501 | <string>. { } |
---|
502 | |
---|
503 | <pexample>(\/\/[^\n]*) { } |
---|
504 | <pexample>"\"" { quote++; old_state = YYSTATE; |
---|
505 | BEGIN(string); /* printf("%s", yytext); */ |
---|
506 | } |
---|
507 | <pexample>"{" { |
---|
508 | brace1++; /* printf("(%d)%s", brace1, yytext); */ |
---|
509 | } |
---|
510 | <pexample>"}" { |
---|
511 | brace1--; /* printf("(%d)%s", brace1, yytext); */ |
---|
512 | if(brace1<=0) { |
---|
513 | if(brace2>0) { yylp_errno=YYLP_EX_BR2; return(1); } |
---|
514 | if(brace3>0) { yylp_errno=YYLP_EX_BR3; return(1); } |
---|
515 | BEGIN(INITIAL); |
---|
516 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
517 | } |
---|
518 | } |
---|
519 | <pexample>"(" { |
---|
520 | brace2++; /* printf("%s", yytext); */ |
---|
521 | } |
---|
522 | <pexample>")" { |
---|
523 | brace2--; /* printf("%s", yytext); */ |
---|
524 | } |
---|
525 | <pexample>"[" { |
---|
526 | brace3++; /* printf("%s", yytext); */ |
---|
527 | } |
---|
528 | <pexample>"]" { |
---|
529 | brace3--; /* printf("%s", yytext); */ |
---|
530 | } |
---|
531 | <pexample>\n { yylplineno++; } |
---|
532 | <pexample>. { } |
---|
533 | |
---|
534 | <pestr>"\"" { quote--; |
---|
535 | BEGIN(pexample); /* printf("%s", yytext); */ |
---|
536 | } |
---|
537 | <pestr>\\\\ { } |
---|
538 | <pestr>\\\" { } |
---|
539 | <pestr>\n { yylplineno++; } |
---|
540 | <pestr>. { } |
---|
541 | |
---|
542 | <comment>\*\/ { BEGIN(old_state); } |
---|
543 | <comment>\n { yylplineno++; } |
---|
544 | <comment>. { } |
---|
545 | |
---|
546 | \n { yylplineno++; } |
---|
547 | ; { p_static = FALSE; |
---|
548 | #if YYLPDEBUG |
---|
549 | printf("%s", yytext); |
---|
550 | #endif |
---|
551 | } |
---|
552 | . { p_static = FALSE; |
---|
553 | yylp_errno = YYLP_BAD_CHAR; |
---|
554 | #if YYLPDEBUG |
---|
555 | printf("[%s]", yytext); |
---|
556 | #endif |
---|
557 | return(1); |
---|
558 | } |
---|
559 | |
---|
560 | %% |
---|
561 | |
---|
562 | int current_pos(int i) |
---|
563 | { |
---|
564 | return(i+offset+(int)(yytext-yylp_buffer_start)); |
---|
565 | } |
---|
566 | |
---|
567 | int libread(FILE* f, char* buf, int max_size) |
---|
568 | { int rc; |
---|
569 | |
---|
570 | offset = ftell(f); |
---|
571 | rc = fread( buf, 1, max_size, f ); |
---|
572 | #if YYLPDEBUG >2 |
---|
573 | printf("fread: %d of %d\n", rc, max_size); |
---|
574 | #endif |
---|
575 | #ifdef macintosh |
---|
576 | char *p = buf, *q; |
---|
577 | while( (q = strchr(p, '\r')) != NULL) { |
---|
578 | *q = '\n'; |
---|
579 | p = q; |
---|
580 | } |
---|
581 | #endif |
---|
582 | yylp_buffer_start = buf; |
---|
583 | return rc; |
---|
584 | } |
---|
585 | |
---|
586 | extern "C" { |
---|
587 | int yylpwrap() { |
---|
588 | //printf("======================= YYWRAP ====================\n"); |
---|
589 | if(brace1>0) { yylp_errno=YYLP_MISS_BR1; } |
---|
590 | if(brace2>0) { yylp_errno=YYLP_MISS_BR2; } |
---|
591 | if(brace3>0) { yylp_errno=YYLP_MISS_BR3; } |
---|
592 | if(quote>0) { yylp_errno=YYLP_MISSQUOT; } |
---|
593 | /* printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3);/**/ |
---|
594 | if(feof(yyin)) return 1; else return 0; |
---|
595 | } |
---|
596 | } |
---|
597 | |
---|
598 | void reinit_yylp() |
---|
599 | { |
---|
600 | brace1 = 0; |
---|
601 | brace2 = 0; |
---|
602 | brace3 = 0; |
---|
603 | quote = 0; |
---|
604 | yy_init=1; |
---|
605 | yy_delete_buffer(yy_current_buffer); |
---|
606 | } |
---|
607 | |
---|
608 | void make_version(char *p,int what) |
---|
609 | { |
---|
610 | char ver[10]; |
---|
611 | char date[16]; |
---|
612 | ver[0]='?'; ver[1]='.'; ver[2]='?'; ver[3]='\0'; |
---|
613 | date[0]='?'; date[1]='\0'; |
---|
614 | if(what) sscanf(p,"%*[^=]= %*s %*s %10s %16s",ver,date); |
---|
615 | else sscanf(p,"// %*s %*s %10s %16s",ver,date); |
---|
616 | strcpy(libnamebuf,"("); |
---|
617 | strcat(libnamebuf,ver); |
---|
618 | strcat(libnamebuf,","); |
---|
619 | strcat(libnamebuf,date); |
---|
620 | strcat(libnamebuf,")"); |
---|
621 | // printf("ID=(%d)%s; \n", what, p); |
---|
622 | } |
---|
623 | |
---|
624 | void copy_string(lp_modes mode) |
---|
625 | { |
---|
626 | #ifndef STANDALONE_PARSER |
---|
627 | if((last_cmd == LP_INFO)&&(mode == GET_INFO)) { |
---|
628 | long current_location = ftell(yylpin); |
---|
629 | int len = (int)(current_pos(0) - string_start); |
---|
630 | fseek(yylpin, string_start, SEEK_SET); |
---|
631 | text_buffer = (char *)AllocL(len+1); |
---|
632 | fread(text_buffer, len, 1, yylpin); |
---|
633 | fseek(yylpin, current_location, SEEK_SET); |
---|
634 | } |
---|
635 | #endif /* STANDALONE_PARSER */ |
---|
636 | } |
---|
637 | |
---|
638 | void print_init() |
---|
639 | { |
---|
640 | printf("Init=%d\n", yy_init); |
---|
641 | } |
---|
642 | |
---|
643 | void print_version(lp_modes mode, char *p) |
---|
644 | { |
---|
645 | #ifdef STANDALONE_PARSER |
---|
646 | //printf("loading %s%s", p, libnamebuf); |
---|
647 | #else |
---|
648 | if ( mode == LOAD_LIB ) { |
---|
649 | if (BVERBOSE(V_LOAD_LIB) && p!=NULL ) Print(" %s...", p); |
---|
650 | //Warn( "loading %s%s", p, libnamebuf); |
---|
651 | } |
---|
652 | #endif |
---|
653 | } |
---|
654 | |
---|
655 | #ifdef STANDALONE_PARSER |
---|
656 | main( int argc, char *argv[] ) |
---|
657 | { |
---|
658 | lib_style_types lib_style; |
---|
659 | ++argv, --argc; /* skip over program name */ |
---|
660 | if ( argc > 0 ) |
---|
661 | yyin = fopen( argv[0], "rb" ); |
---|
662 | else |
---|
663 | yyin = stdin; |
---|
664 | |
---|
665 | printf( " %-15s %20s %s,%s %s,%s %s,%s\n", "Library", |
---|
666 | "function", "line", "start-eod", "line", "body-eob", |
---|
667 | "line", "example-eoe"); |
---|
668 | yylplex(argv[0], argv[0], &lib_style); |
---|
669 | if(yylp_errno) { |
---|
670 | printf("ERROR occured: [%d] ", yylp_errno); |
---|
671 | printf(yylp_errlist[yylp_errno], yylplineno); |
---|
672 | printf("\n"); |
---|
673 | } |
---|
674 | else if(pi!=NULL) printpi(pi); |
---|
675 | } |
---|
676 | |
---|
677 | #endif /* STANDALONE_PARSER */ |
---|
678 | #endif /* HAVE_LIBPARSE */ |
---|