Changeset d40d574 in git for Singular/libparse.l
- Timestamp:
- Dec 8, 1999, 5:58:34 PM (24 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'c5facdfddea2addfd91babd8b9019161dea4b695')
- Children:
- 4e4ece733801c7cfccc5608ce3ba27e782c16e93
- Parents:
- f4ecbe471974f4c2e100c437640bcde5f9b87b26
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/libparse.l
rf4ecbe4 rd40d574 3 3 * Computer Algebra System SINGULAR * 4 4 ****************************************/ 5 /* $Id: libparse.l,v 1.3 6 1999-11-15 17:20:18 obachmanExp $ */5 /* $Id: libparse.l,v 1.37 1999-12-08 16:58:34 Singular Exp $ */ 6 6 #include <stdio.h> 7 7 #include <string.h> … … 9 9 #include <ctype.h> 10 10 #ifdef STANDALONE_PARSER 11 #include "utils.h"12 #include "getopt.h"13 #define HAVE_LIBPARSER14 #define YYLPDEBUG 111 #include "utils.h" 12 #include "getopt.h" 13 #define HAVE_LIBPARSER 14 #define YYLPDEBUG 1 15 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"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 24 #endif 25 25 #include "libparse.h" 26 26 27 27 #ifdef HAVE_LIBPARSER 28 # 28 #define YY_SKIP_YYWRAP 29 29 30 30 typedef enum { LP_NONE, LP_INFO, LP_VERSION} lib_cmds; … … 81 81 int yylp_errno = 0; 82 82 83 # 84 # 83 #ifdef __MWERKS__ 84 #ifdef __cplusplus 85 85 extern "C" { 86 # 86 #endif 87 87 long ftell(FILE *fp); 88 # 88 #ifdef macintosh 89 89 int fileno(FILE *stream); 90 90 FILE *fdopen(int filedes, char *type); … … 94 94 FILE *_fdopen(int filedes, char *type); 95 95 int _isatty(int filedes); 96 # 97 # 98 # 99 # 100 # 101 } 102 # 103 # 104 105 # 96 #define fileno _fileno 97 #define fdopen _fdopen 98 #define isatty _isatty 99 #endif /* macintosh */ 100 #ifdef __cplusplus 101 } 102 #endif 103 #endif 104 105 #ifdef STANDALONE_PARSER 106 106 procinfov pi; 107 107 printpi(procinfov pi); … … 112 112 void main_init(int argc, char *argv[]); 113 113 void main_result(char *libname); 114 # 114 #else /* STANDALONE_PARSER */ 115 115 idhdl h0; 116 # 116 #ifdef HAVE_NAMESPACES 117 117 idhdl h_top; 118 118 extern namehdl namespaceroot; 119 # 120 # 119 #endif /* HAVE_NAMESPACES */ 120 #define pi IDPROC(h0) 121 121 extern "C" 122 122 { … … 124 124 } 125 125 extern libstackv library_stack; 126 # 126 #endif /* STANDALONE_PARSER */ 127 127 128 128 static unsigned long help_chksum; 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; help_chksum = 0;} 133 # define SET_HELP_END(mode, pi, p) \ 134 if ( mode == LOAD_LIB) {pi->data.s.help_end = p; \ 135 pi->data.s.help_chksum = help_chksum;} 136 137 # define SET_BODY_START(mode, pi, l, p) \ 138 if ( mode == LOAD_LIB) { \ 139 pi->data.s.body_lineno = l; \ 140 pi->data.s.body_start = p; \ 129 130 #define SET_DEF_END(mode, pi, p) \ 131 if ( mode == LOAD_LIB) pi->data.s.def_end = p; 132 #define SET_HELP_START(mode, pi, p) \ 133 if ( mode == LOAD_LIB) {pi->data.s.help_start = p; help_chksum = 0;} 134 #define SET_HELP_END(mode, pi, p) \ 135 if ( mode == LOAD_LIB) {pi->data.s.help_end = p; \ 136 pi->data.s.help_chksum = help_chksum;} 137 138 #define SET_BODY_START(mode, pi, l, p) \ 139 if ( mode == LOAD_LIB) \ 140 { \ 141 pi->data.s.body_lineno = l; \ 142 pi->data.s.body_start = p; \ 141 143 } 142 # define SET_BODY_END(mode, pi, p) \ 143 if ( mode == LOAD_LIB) { \ 144 #define SET_BODY_END(mode, pi, p) \ 145 if ( mode == LOAD_LIB) \ 146 { \ 144 147 pi->data.s.body_end = p-1; \ 145 148 pi->data.s.proc_end = p-1; \ 146 149 } 147 150 148 # define SET_EXAMPLE_START(mode, pi, l, p) \ 149 if ( mode == LOAD_LIB) { \ 150 pi->data.s.example_lineno = l; \ 151 pi->data.s.example_start = p; \ 152 } 153 # define SET_PROC_END(mode, pi, p) \ 154 if ( mode == LOAD_LIB) { \ 155 pi->data.s.proc_end = p-1; \ 156 if(pi->data.s.body_end==0) pi->data.s.body_end = p-1; \ 151 #define SET_EXAMPLE_START(mode, pi, l, p) \ 152 if ( mode == LOAD_LIB) \ 153 { \ 154 pi->data.s.example_lineno = l; \ 155 pi->data.s.example_start = p; \ 156 } 157 #define SET_PROC_END(mode, pi, p) \ 158 if ( mode == LOAD_LIB) \ 159 { \ 160 pi->data.s.proc_end = p-1; \ 161 if(pi->data.s.body_end==0) \ 162 pi->data.s.body_end = p-1; \ 157 163 } 158 164 159 165 #define ROTATE_RIGHT(c) if ((c) & 01) (c) = ((c) >>1) + 0x8000; else (c) >>= 1; 160 166 #define IncrCheckSum(c) \ 161 do 162 { 167 do \ 168 { \ 163 169 ROTATE_RIGHT(help_chksum); \ 164 170 help_chksum += c; \ 165 171 help_chksum &= 0xffff; \ 166 } 172 } \ 167 173 while(0) 168 174 169 # 170 # 171 # 172 173 174 # 175 # 176 177 178 # 179 180 # 181 # 175 #undef YY_DECL 176 #ifdef HAVE_NAMESPACES 177 #define YY_DECL int yylex(char *newlib, char *libfile, \ 178 lib_style_types *lib_style, \ 179 idhdl pl, BOOLEAN autoexport, lp_modes mode) 180 #else /* HAVE_NAMESPACES */ 181 #define YY_DECL int yylex(char *newlib, char *libfile, \ 182 lib_style_types *lib_style, \ 183 lp_modes mode) 184 #endif /* HAVE_NAMESPACES */ 185 186 #undef YY_INPUT 187 #define YY_INPUT(buf,result,max_size) \ 182 188 if ( ((result = libread( (yyin), (char *) buf, max_size )) < 0 ) \ 183 189 && ferror( yyin ) ) \ 184 190 YY_FATAL_ERROR( "read in flex scanner failed" ); 185 191 186 # 192 #define YY_USER_INIT { \ 187 193 BEGIN(header); \ 188 194 yylplineno = 1; \ … … 192 198 } 193 199 194 # 200 #if 0 195 201 <pbody>proc[ \t]+{name} { 196 202 printf("MISSING: PROC-cmd found. ERROR!\n"); } … … 199 205 printf("MISSING: EXAMPLE-cmd found. ERROR!\n"); } 200 206 info=+"\"" { 201 # endif 207 #endif 208 202 209 %} 203 210 … … 263 270 { 264 271 make_version(yytext,1); 265 #ifdef STANDALONE_PARSER266 if (texinfo_out) 272 #ifdef STANDALONE_PARSER 273 if (texinfo_out) 267 274 { 268 275 char *c = libnamebuf; … … 272 279 if (*c == '$' || *c == '@') putchar('\\'); 273 280 if (*c != '\r') putchar(*c); 274 if (*c == '\\') 281 if (*c == '\\') 275 282 { 276 283 c++; … … 284 291 else 285 292 printf("Version:%s;\n", libnamebuf); 286 #else287 #ifdef HAVE_NAMESPACES293 #else 294 #ifdef HAVE_NAMESPACES 288 295 h0 = enterid( mstrdup("version"), myynest, STRING_CMD, 289 296 &IDPACKAGE(pl)->idroot, FALSE ); 290 291 292 293 294 #else /* HAVE_NAMESPACES */297 if (h0!=NULL) 298 { 299 IDSTRING(h0) = mstrdup(libnamebuf); 300 } 301 #else /* HAVE_NAMESPACES */ 295 302 if (text_buffer!=NULL) FreeL((ADDRESS)text_buffer); 296 303 text_buffer = mstrdup(libnamebuf); 297 #endif /* HAVE_NAMESPACES */298 #endif304 #endif /* HAVE_NAMESPACES */ 305 #endif 299 306 } 300 307 } … … 309 316 sscanf( yytext, "%*[^p]proc %s", proc); 310 317 if(strlen(proc)<1) sscanf( yytext, "proc %s", proc); 311 #if YYLPDEBUG > 1318 #if YYLPDEBUG > 1 312 319 printf("Newlib:%s\n", newlib); 313 #endif314 #ifdef STANDALONE_PARSER315 316 317 318 319 320 321 322 323 #else STANDALONE_PARSER320 #endif 321 #ifdef STANDALONE_PARSER 322 if ( pi != NULL ) 323 { 324 printpi(pi); 325 pi_clear(pi); 326 } 327 pi = (procinfo *)malloc(sizeof(procinfo)); 328 iiInitSingularProcinfo(pi, newlib, proc, yylplineno, 329 current_pos(0), p_static); 330 #else STANDALONE_PARSER 324 331 if( mode == LOAD_LIB) 325 332 { 326 #ifdef HAVE_NAMESPACES327 h0 = enterid( mstrdup(proc), myynest, PROC_CMD,333 #ifdef HAVE_NAMESPACES 334 h0 = enterid( mstrdup(proc), 0 /*myynest*/, PROC_CMD, 328 335 &IDPACKAGE(pl)->idroot, TRUE); 329 336 if(!p_static && autoexport) … … 334 341 namespaceroot->pop(); 335 342 } 336 #else /* HAVE_NAMESPACES */337 h0 = enterid( mstrdup(proc), myynest, PROC_CMD,343 #else /* HAVE_NAMESPACES */ 344 h0 = enterid( mstrdup(proc), 0 /*myynest*/, PROC_CMD, 338 345 &idroot, TRUE ); 339 #endif /* HAVE_NAMESPACES */346 #endif /* HAVE_NAMESPACES */ 340 347 if (h0!=NULL) 341 348 { 342 349 iiInitSingularProcinfo(IDPROC(h0), newlib, proc, 343 350 yylplineno, current_pos(0),p_static); 344 #ifdef HAVE_NAMESPACES351 #ifdef HAVE_NAMESPACES 345 352 if (!p_static && h_top != NULL && autoexport) 346 353 { 347 354 if(IDPROC(h_top)!=NULL) piCleanUp((procinfo *)IDPROC(h_top)); 348 355 IDPROC(h_top)=IDPROC(h0); 349 356 IDPROC(h_top)->ref++; 350 357 } 351 #endif /* HAVE_NAMESPACES */358 #endif /* HAVE_NAMESPACES */ 352 359 if (BVERBOSE(V_LOAD_PROC)) 353 360 Warn( " proc '%s' registered", proc ); 354 361 } 355 #endif STANDALONE_PARSER362 #endif STANDALONE_PARSER 356 363 SET_DEF_END(mode, pi, current_pos(yyleng+1)); 357 #if YYLPDEBUG364 #if YYLPDEBUG 358 365 if(lpverbose) 359 366 { … … 363 370 yylplineno, current_pos(0), (int)pi->data.s.def_end, brace1); 364 371 } 365 #endif372 #endif 366 373 p_static=FALSE; 367 #ifndef STANDALONE_PARSER374 #ifndef STANDALONE_PARSER 368 375 } 369 #endif STANDALONE_PARSER376 #endif STANDALONE_PARSER 370 377 } 371 378 example { 372 379 BEGIN(pexample); 373 380 SET_EXAMPLE_START(mode, pi, yylplineno, current_pos(0)); 374 #if YYLPDEBUG381 #if YYLPDEBUG 375 382 if(lpverbose) 376 383 { … … 378 385 current_pos(0), brace1); 379 386 } 380 #endif387 #endif 381 388 } 382 389 … … 387 394 <header>({comment}+{tos}+{dolar}+Id:+{string}+[^\n]*)|({comment}+{tos}+{dolar}+Header:+{string}+[^\n]*) { 388 395 make_version(yytext, 0); 389 #if YYLPDEBUG > 1396 #if YYLPDEBUG > 1 390 397 printf("+(id)HEAD:%s\n", yytext); 391 #endif398 #endif 392 399 } 393 400 <header>(^{comment}+[^\n]*) { 394 #if YYLPDEBUG401 #if YYLPDEBUG 395 402 printf("+(cmt)HEAD:%s\n", yytext); 396 #endif403 #endif 397 404 } 398 405 <header>(^#![^\n]*) { 399 #if YYLPDEBUG > 1406 #if YYLPDEBUG > 1 400 407 printf("-HEAD:%s\n", yytext); 401 #endif408 #endif 402 409 } 403 410 <header>^proc\ { yyless(0); … … 417 424 <header>\n { yylplineno++; } 418 425 <header>. { 419 #if YYLPDEBUG > 1426 #if YYLPDEBUG > 1 420 427 printf(" HEAD:%s\n", yytext); 421 #endif428 #endif 422 429 yyless(0); 423 430 BEGIN(help); 424 431 } 425 432 <help>(^{comment}+[^\n]*) { 426 #if YYLPDEBUG > 1433 #if YYLPDEBUG > 1 427 434 printf(" HELP:%s\n", yytext); 428 #endif435 #endif 429 436 BEGIN(INITIAL); } 430 437 <help>(^#![^\n]*) { 431 #if YYLPDEBUG > 1438 #if YYLPDEBUG > 1 432 439 printf(" HELP:%s\n", yytext); 433 #endif440 #endif 434 441 BEGIN(INITIAL); 435 442 } … … 452 459 <help>\n { yylplineno++; } 453 460 <help>({tos}|{comment}+{fstring}) { 454 #if YYLPDEBUG461 #if YYLPDEBUG 455 462 if(lpverbose>2) printf("--->%s<---\n", yytext); 456 #endif463 #endif 457 464 } 458 465 <help>. { 459 466 found_oldhelp=1; 460 #if YYLPDEBUG > 1467 #if YYLPDEBUG > 1 461 468 printf("-HELP:%s\n", yytext); 462 #endif469 #endif 463 470 } 464 471 … … 466 473 <libcmd>{string}"\"" { quote--; 467 474 yytext[yyleng-1] = '\0'; 468 #ifndef STANDALONE_PARSER 469 if ( mode == LOAD_LIB ) { 470 library_stack->push(newlib, yytext); 471 } 472 #endif /* STANDALONE_PARSER */ 473 #if YYLPDEBUG 475 #ifndef STANDALONE_PARSER 476 if ( mode == LOAD_LIB ) 477 { 478 library_stack->push(newlib, yytext); 479 } 480 #endif /* STANDALONE_PARSER */ 481 #if YYLPDEBUG 474 482 if(lpverbose>1) printf("LIB:'%s'\n", yytext); 475 #endif483 #endif 476 484 BEGIN(INITIAL); 477 485 } … … 480 488 <pdef>\( { 481 489 brace2++; 482 #if YYLPDEBUG > 1490 #if YYLPDEBUG > 1 483 491 printf("%s", yytext); 484 #endif492 #endif 485 493 } 486 494 <pdef>\) { 487 495 brace2--; 488 #if YYLPDEBUG > 1496 #if YYLPDEBUG > 1 489 497 printf(">%s<\n", yytext); 490 498 printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); 491 #endif499 #endif 492 500 if(brace2<=0) 493 501 { 494 #if YYLPDEBUG > 1502 #if YYLPDEBUG > 1 495 503 printf("BEGIN(phead){=%d, (=%d, [=%d\n", brace1, brace2, brace3); 496 #endif504 #endif 497 505 SET_DEF_END(mode, pi, current_pos(yyleng)); 498 506 BEGIN(phead); … … 502 510 if(brace2>0) 503 511 { 504 #if YYLPDEBUG > 1512 #if YYLPDEBUG > 1 505 513 printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); 506 #endif514 #endif 507 515 yylp_errno = YYLP_DEF_BR2; 508 516 return(1); … … 537 545 538 546 <phead>({tnl}+{quote}+{strings}+{escquote}+{tnl}+"{") { 539 #if YYLPDEBUG547 #if YYLPDEBUG 540 548 if(lpverbose>2)printf("0-Len=%d;\n", yyleng); 541 #endif549 #endif 542 550 if(check) 543 551 { … … 550 558 } 551 559 <phead>({tnl}+{quote}+{strings}+{eos}) { 552 #if YYLPDEBUG560 #if YYLPDEBUG 553 561 if(lpverbose>2)printf("1-Len=%d;\n", yyleng); 554 #endif562 #endif 555 563 BEGIN(phelp); 556 564 yyless(0); … … 562 570 pi->procname, pi->data.s.proc_lineno); 563 571 } 564 #if YYLPDEBUG572 #if YYLPDEBUG 565 573 if(lpverbose>2 && yyleng>2) 566 574 printf("2-Len=%d, %s;\n", yyleng, pi->procname); 567 #endif575 #endif 568 576 SET_HELP_START(mode, pi, current_pos(0)); 569 577 BEGIN(poldhelp); … … 609 617 current_pos(0), brace1); 610 618 } 611 #if YYLPDEBUG > 1619 #if YYLPDEBUG > 1 612 620 printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3); 613 #endif621 #endif 614 622 SET_BODY_START(mode, pi, yylplineno, current_pos(0)); 615 #if YYLPDEBUG > 1623 #if YYLPDEBUG > 1 616 624 printf("BODY at %d/%d", yylplineno, current_pos(0)); 617 #endif625 #endif 618 626 } 619 627 <phelp>\n { yylplineno++;} … … 636 644 <pbody>"{" { 637 645 brace1++; 638 #if YYLPDEBUG > 1646 #if YYLPDEBUG > 1 639 647 printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); 640 #endif648 #endif 641 649 } 642 650 <pbody>"}" { 643 #if YYLPDEBUG > 1 644 printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); 645 #endif 651 #if YYLPDEBUG > 1 652 printf("line: %d, (%d)%s\n", 653 yylplineno, brace1, yytext); 654 #endif 646 655 brace1--; 647 656 if(brace2>0) … … 659 668 SET_BODY_END(mode, pi, current_pos(yyleng)); 660 669 SET_PROC_END(mode, pi, current_pos(yyleng)); 661 #if YYLPDEBUG > 1662 printf("-%d\n", current_pos(0));663 #endif670 #if YYLPDEBUG > 1 671 printf("-%d\n", current_pos(0)); 672 #endif 664 673 BEGIN(INITIAL); 665 674 } … … 699 708 700 709 <string>"\"" { quote--; 701 #ifdef HAVE_NAMESPACES702 copy_string(mode, pl);703 #else /* HAVE_NAMESPACES */704 copy_string(mode);705 #endif /* HAVE_NAMESPACES */710 #ifdef HAVE_NAMESPACES 711 copy_string(mode, pl); 712 #else /* HAVE_NAMESPACES */ 713 copy_string(mode); 714 #endif /* HAVE_NAMESPACES */ 706 715 last_cmd = LP_NONE; 707 716 if(old_state==phelp) 708 { 717 { 709 718 SET_HELP_END(mode, pi, current_pos(0)); 710 719 } … … 761 770 \r { } 762 771 ; { p_static = FALSE; 763 #if YYLPDEBUG > 1772 #if YYLPDEBUG > 1 764 773 printf("%s", yytext); 765 #endif774 #endif 766 775 } 767 776 . { p_static = FALSE; 768 777 yylp_errno = YYLP_BAD_CHAR; 769 #ifdef STANDALONE_PARSER778 #ifdef STANDALONE_PARSER 770 779 printf("[%d]", *yytext); 771 #else780 #else 772 781 if (text_buffer!=NULL) FreeL((ADDRESS)text_buffer); 773 782 text_buffer = mstrdup(yytext); 774 #endif775 #if YYLPDEBUG > 1776 printf("[%s]", yytext);777 #endif783 #endif 784 #if YYLPDEBUG > 1 785 printf("[%s]", yytext); 786 #endif 778 787 return(1); 779 788 } … … 791 800 offset = ftell(f); 792 801 rc = myfread( buf, 1, max_size, f ); 793 #if YYLPDEBUG >2794 printf("fread: %d of %d\n", rc, max_size);795 #endif802 #if YYLPDEBUG >2 803 printf("fread: %d of %d\n", rc, max_size); 804 #endif 796 805 yylp_buffer_start = buf; 797 806 return rc; … … 854 863 printf("$info = <<EOT;\n"); 855 864 fseek (yylpin, i, SEEK_SET); 856 while (i< current_location) 857 { 865 while (i< current_location) 866 { 858 867 c = fgetc(yylpin); 859 if (c == '\\') 868 if (c == '\\') 860 869 { 861 870 quote = (! quote); … … 898 907 if(offset>0) text_buffer[i-offset] = text_buffer[i]; 899 908 } 900 #ifdef HAVE_NAMESPACES909 #ifdef HAVE_NAMESPACES 901 910 if( mode != GET_INFO ) { 902 911 h0 = enterid( mstrdup("info"), myynest, STRING_CMD, … … 907 916 } 908 917 } 909 #endif /* HAVE_NAMESPACES */918 #endif /* HAVE_NAMESPACES */ 910 919 } 911 920 #endif /* STANDALONE_PARSER */ … … 919 928 void print_version(lp_modes mode, char *p) 920 929 { 921 # 930 #ifdef STANDALONE_PARSER 922 931 //printf("loading %s%s", p, libnamebuf); 923 # 932 #else 924 933 if ( mode == LOAD_LIB ) 925 934 { … … 927 936 //Warn( "loading %s%s", p, libnamebuf); 928 937 } 929 # 930 } 931 932 # 938 #endif 939 } 940 941 #ifdef STANDALONE_PARSER 933 942 main( int argc, char *argv[] ) 934 943 { … … 961 970 } 962 971 963 # 972 #endif /* STANDALONE_PARSER */ 964 973 #endif /* HAVE_LIBPARSE */
Note: See TracChangeset
for help on using the changeset viewer.