source: git/Singular/libparse.l @ 64d729

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