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