1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
|
/* output.c, output generator for dlg
*
* Output Notes:
*
* DfaStates == number of dfa nodes in automaton (just a #define)
* DfaState == type large enough to index every node in automaton
* <256 unsigned char, <65536 unsigned short, etc.
*
* Thus, the elements in each of the automaton states (st%d) are type DfaState
* and are size appropriately, since they must be able to index the next
* automaton state.
*
* dfa[] == a linear array that points to all the automaton states (st%d)
* (dfa_base[] should be the same, but isn't right now)
*
* accepts[] == Taking a closer look at this one, it probably shouldn't be type
* DfaState because there is no real requirement that the number of
* accepts states is less than the number of dfa state. However, if
* the number of accept states was more than the number of DFA states
* then the lexical specification would be really ambiguous.
*
* Another note. Is that is should be possible to fold accepts[] and
* actions[] together. If this is done, I would suggest get rid of
* accept[] and make actions[] have an entry for each state (st%d) in
* the automaton.
*
* dfa_base[] == starting location for each lexical mode. This should be
* Dfastate type (but isn't right now), since it points to the states
* in the automaton.
*
* dfa_class_no[] == indicates the number of columns each lexical mode has.
*
* b_class_no[] == pointer to the start of the translation array used to
* convert from input character to character class. This could cause
* problems if there are more than 256 classes
*
* shift%d[] == the actual translation arrays that convert the input character
* into the character class. These will have to change if there are
* more than 256 character classes.
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* DLG 1.33
* Will Cohen
* With mods by Terence Parr; AHPCRC, University of Minnesota
* 1989-2001
*/
#include <stdio.h>
#include <string.h>
#include "dlg.h"
#ifdef MEMCHK
#include "trax.h"
#else
#ifdef __STDC__
#include <stdlib.h>
#else
#include <malloc.h>
#endif /* __STDC__ */
#endif
static char *mode_name[MAX_MODES];
static int mode_number[MAX_MODES];
static int cur_mode=0;
int operation_no = 0; /* used to mark nodes so that infinite loops avoided */
int dfa_basep[MAX_MODES]; /* start of each group of states */
int dfa_class_nop[MAX_MODES]; /* number of elements in each group of states*/
int gen_ansi = FALSE; /* allows ansi code to be generated */
FILE *input_stream; /* where to read description from */
FILE *output_stream; /* where to put the output */
FILE *mode_stream; /* where to put the mode.h stuff */
FILE *class_stream; /* where to put the scan.h stuff (if gen_cpp) */
/* NOTE: This section is MACHINE DEPENDENT */
#define DIF_SIZE 4
#if defined(PC) && !defined(PC32)
unsigned long typesize[DIF_SIZE] = { 0x7f, 0x7fff, 0x7ffful, 0x7ffffffful }; /* MR20 */
char t0[] = "unsigned char";
char t1[] = "unsigned short";
char t2[] = "unsigned int";
char t3[] = "unsigned long";
char *typevar[DIF_SIZE] = { t0, t1, t2, t3};
#else
unsigned long typesize[DIF_SIZE] = { 0x7f, 0x7fff, 0x7ffffffful, 0x7ffffffful }; /* MR20 */
char t0[] = "unsigned char";
char t1[] = "unsigned short";
char t2[] = "unsigned int";
char t3[] = "unsigned long";
char *typevar[DIF_SIZE] = { t0, t1, t2, t3};
#endif
/* Added by TJP August 1994 */
/* Take in MyLexer and return MyLexer_h */
static char *
#ifdef __USE_PROTOS
gate_symbol(char *name)
#else
gate_symbol(name)
char *name;
#endif
{
static char buf[100];
sprintf(buf, "%s_h", name);
return buf;
}
/* Added by TJP August 1994 */
static char *
#ifdef __USE_PROTOS
mystrdup(char *s)
#else
mystrdup(s)
char *s;
#endif
{
char *p = (char *)malloc(strlen(s)+1);
strcpy(p, s);
return p;
}
#ifdef __USE_PROTOS
void p_class_hdr(void)
#else
void p_class_hdr()
#endif
{
if ( class_stream == NULL ) return;
fprintf(class_stream, "#ifndef %s\n", gate_symbol(ClassName("")));
fprintf(class_stream, "#define %s\n", gate_symbol(ClassName("")));
fprintf(class_stream, "/*\n");
fprintf(class_stream, " * D L G L e x e r C l a s s D e f i n i t i o n\n");
fprintf(class_stream, " *\n");
fprintf(class_stream, " * Generated from:");
fprintf(class_stream, " %s", file_str[0]);
fprintf(class_stream, "\n");
fprintf(class_stream, " *\n");
fprintf(class_stream, " * 1989-2001 by Will Cohen, Terence Parr, and Hank Dietz\n");
fprintf(class_stream, " * Purdue University Electrical Engineering\n");
fprintf(class_stream, " * DLG Version %s\n", version);
fprintf(class_stream, " */\n\n");
fprintf(class_stream, "\n");
fprintf(class_stream, "#include \"%s\"\n", DLEXERBASE_H);
}
/* MR1 */
/* MR1 16-Apr-97 Split printing of class header up into several parts */
/* MR1 so that #lexprefix <<...>>and #lexmember <<...>> */
/* MR1 can be inserted in the appropriate spots */
/* MR1 */
#ifdef __USE_PROTOS
void p_class_def1(void)
#else
void p_class_def1()
#endif
{
if ( class_stream == NULL ) return;
fprintf(class_stream, "\nclass %s : public DLGLexerBase {\n", ClassName(""));
fprintf(class_stream, "public:\n");
}
#ifdef __USE_PROTOS
void p_class_def2(void)
#else
void p_class_def2()
#endif
{
int i, m;
if ( class_stream == NULL ) return;
fprintf(class_stream, "public:\n");
fprintf(class_stream, "\tstatic const int MAX_MODE;\n");
fprintf(class_stream, "\tstatic const int DfaStates;\n");
for (i=0; i<cur_mode; i++) {
fprintf(class_stream, "\tstatic const int %s;\n", mode_name[i]);
}
fprintf(class_stream, "\ttypedef %s DfaState;\n\n", minsize(dfa_allocated));
fprintf(class_stream, "\t%s(DLGInputStream *in,\n",ClassName(""));
fprintf(class_stream, "\t\tunsigned bufsize=2000)\n");
fprintf(class_stream, "\t\t: DLGLexerBase(in, bufsize, %d)\n", interactive);
fprintf(class_stream, "\t{\n");
fprintf(class_stream, "\t;\n");
fprintf(class_stream, "\t}\n");
fprintf(class_stream, "\tvoid mode(int);\n");
fprintf(class_stream, "\tANTLRTokenType nextTokenType(void);\n");
fprintf(class_stream, "\tvoid advance(void);\n");
fprintf(class_stream, "protected:\n");
for (i=1; i<=action_no; ++i) {
fprintf(class_stream, "\tANTLRTokenType act%d();\n", i);
}
for(m=0; m<(mode_counter-1); ++m){
for(i=dfa_basep[m]; i<dfa_basep[m+1]; ++i)
fprintf(class_stream, "\tstatic DfaState st%d[%d];\n", i-1, dfa_class_nop[m]+1);
}
for(i=dfa_basep[m]; i<=dfa_allocated; ++i)
fprintf(class_stream, "\tstatic DfaState st%d[%d];\n", i-1, dfa_class_nop[m]+1);
fprintf(class_stream, "\tstatic DfaState *dfa[%d];\n", dfa_allocated);
fprintf(class_stream, "\tstatic DfaState dfa_base[];\n");
/* fprintf(class_stream, "\tstatic int dfa_base_no[];\n"); */
fprintf(class_stream, "\tstatic unsigned char *b_class_no[];\n");
fprintf(class_stream, "\tstatic DfaState accepts[%d];\n",dfa_allocated+1);
fprintf(class_stream, "\tstatic DLGChar alternatives[%d];\n",dfa_allocated+1);
/* WARNING: should be ANTLRTokenType for action table, but g++ 2.5.6 is hosed */
fprintf(class_stream, "\tstatic ANTLRTokenType (%s::*actions[%d])();\n", ClassName(""), action_no+1);
for(m=0; m<mode_counter; ++m) {
fprintf(class_stream, "\tstatic unsigned char shift%d[%d];\n",
m, CHAR_RANGE);
}
if (comp_level)
fprintf(class_stream, "\tint ZZSHIFT(int c) { return b_class_no[automaton][1+c]; }\n");
else
fprintf(class_stream, "\tint ZZSHIFT(int c) { return 1+c; }\n");
/* MR1 */
/* MR1 11-APr-97 Kludge to allow inclusion of user-defined code in */
/* MR1 DLGLexer class header */
/* MR1 Deprecated in favor of 133MR1 addition #lexmember <<>> */
/* MR1 */
/* MR1 */ fprintf(class_stream,"//\n");
/* MR1 */ fprintf(class_stream,
/* MR1 */ "// 133MR1 Deprecated feature to allow inclusion of ");
/* MR1 */ fprintf(class_stream,
/* MR1 */ "user-defined code in DLG class header\n");
/* MR1 */ fprintf(class_stream,"//\n");
/* MR1 */
/* MR1 */ fprintf(class_stream,"#ifdef DLGLexerIncludeFile\n");
/* MR1 */ fprintf(class_stream,"#include DLGLexerIncludeFile\n");
/* MR1 */ fprintf(class_stream,"#endif\n");
fprintf(class_stream, "};\n");
fprintf(class_stream, "typedef ANTLRTokenType (%s::*Ptr%sMemberFunc)();\n",
ClassName(""), ClassName(""));
fprintf(class_stream, "#endif\n");
}
/* generate required header on output */
#ifdef __USE_PROTOS
void p_head(void)
#else
void p_head()
#endif
{
fprintf(OUT, "/*\n");
fprintf(OUT, " * D L G tables\n");
fprintf(OUT, " *\n");
fprintf(OUT, " * Generated from:");
fprintf(OUT, " %s", file_str[0]);
fprintf(OUT, "\n");
fprintf(OUT, " *\n");
fprintf(OUT, " * 1989-2001 by Will Cohen, Terence Parr, and Hank Dietz\n");
fprintf(OUT, " * Purdue University Electrical Engineering\n");
fprintf(OUT, " * DLG Version %s\n", version);
fprintf(OUT, " */\n\n");
if ( gen_cpp) fprintf(OUT, "#include \"pcctscfg.h\"\n");
if ( gen_cpp ) fprintf(OUT, "#include \"pccts_stdio.h\"\n");
if ( !gen_cpp ) fprintf(OUT, "#include \"%s\"\n\n", mode_file);
fprintf(OUT,"\n");
}
#ifdef __USE_PROTOS
void p_includes(void)
#else
void p_includes()
#endif
{
fprintf(OUT, "#include \"%s\"\n", APARSER_H);
fprintf(OUT, "#include \"%s\"\n", DLEXERBASE_H);
fprintf(OUT, "#include \"%s\"\n", ClassName(".h"));
}
/* generate code to tie up any loose ends */
#ifdef __USE_PROTOS
void p_tail(void) /* MR1 */
#else
void p_tail() /* MR1 */
#endif
{
if ( gen_cpp ) {
if ( strcmp(ClassName(""), DEFAULT_CLASSNAME)!=0 )
fprintf(OUT, "#define DLGLexer %s\n", ClassName(""));
fprintf(OUT, "#include \"%s\"\n", DLEXER_H); /* MR23 Rename DLexer.cpp to DLexer.h */
return;
}
fprintf(OUT, "\n");
fprintf(OUT, "\n");
if (comp_level)
fprintf(OUT, "#define ZZSHIFT(c) (b_class_no[zzauto][1+c])\n");
else
fprintf(OUT, "#define ZZSHIFT(c) (1+c)\n");
if ( !gen_cpp ) fprintf(OUT, "#define MAX_MODE %d\n",mode_counter);
fprintf(OUT, "#include \"dlgauto.h\"\n");
}
/* output the table of DFA for general use */
#ifdef __USE_PROTOS
void p_tables()
#else
void p_tables()
#endif
{
if ( !gen_cpp ) {
fprintf(OUT, "#define DfaStates\t%d\n", dfa_allocated);
fprintf(OUT, "typedef %s DfaState;\n\n", minsize(dfa_allocated));
}
if ( gen_cpp ) {
int i;
fprintf(OUT, "\n");
fprintf(OUT, "const int %s::MAX_MODE=%d;\n",
ClassName(""),
mode_counter);
fprintf(OUT, "const int %s::DfaStates=%d;\n",
ClassName(""),
dfa_allocated);
for (i=0; i<cur_mode; i++) {
fprintf(OUT, "const int %s::%s=%d;\n",
ClassName(""), mode_name[i], mode_number[i]);
}
fprintf(OUT, "\n");
}
p_node_table();
p_dfa_table();
p_accept_table();
p_action_table();
p_base_table();
p_class_table();
if (comp_level)
p_bshift_table();
if (interactive || gen_cpp )
p_alternative_table();
}
/* figures out the smallest variable type that will hold the transitions
*/
#ifdef __USE_PROTOS
char *minsize(int elements)
#else
char *minsize(elements)
int elements;
#endif
{
int i = 0;
while ((unsigned long) elements > typesize[i]) /* MR20 */
++i;
return typevar[i];
}
#ifdef __USE_PROTOS
void p_node_table(void)
#else
void p_node_table()
#endif
{
register int i;
register int m = 0;
for(m=0; m<(mode_counter-1); ++m){
for(i=dfa_basep[m]; i<dfa_basep[m+1]; ++i)
p_single_node(i,dfa_class_nop[m]);
}
for(i=dfa_basep[m]; i<=dfa_allocated; ++i)
p_single_node(i,dfa_class_nop[m]);
}
#ifdef __USE_PROTOS
void p_single_node(int i,int classes)
#else
void p_single_node(i,classes)
int i,classes;
#endif
{
register int j;
register int trans, items_on_line;
#if 1
/* extra state (classes+1) for invalid characters */
fprintf(OUT, "%sDfaState %sst%d[%d] = {\n ",
gen_cpp?ClassName("::"):"static ",
gen_cpp?ClassName("::"):"",(i-1), (classes+1));
#else
fprintf(OUT, "static DfaState st%d[%d] = {\n ", (i-1), classes);
#endif
items_on_line = MAX_ON_LINE;
for(j=0; j<classes; ++j){
DAWDLE;
trans = DFA(i)->trans[j];
if (trans == NIL_INDEX)
trans = dfa_allocated+1;
/* all of DFA moved down one in array */
fprintf(OUT, "%d", trans-1);
fprintf(OUT, ", ");
if (!(--items_on_line)){
fprintf(OUT, "\n ");
items_on_line = MAX_ON_LINE;
}
}
#if 1
/* put in jump to error state */
fprintf(OUT, "%d\n};\n\n", dfa_allocated);
#else
fprintf(OUT, "\n};\n\n");
#endif
}
#ifdef __USE_PROTOS
void p_dfa_table(void)
#else
void p_dfa_table()
#endif
{
register int i;
fprintf(OUT, "\n%sDfaState *%sdfa[%d] = {\n",
gen_cpp?ClassName("::"):"",gen_cpp?ClassName("::"):"", dfa_allocated);
for (i=0; i<(dfa_allocated-1); ++i){
fprintf(OUT, "\tst%d,\n", i);
}
fprintf(OUT, "\tst%d\n", i);
fprintf(OUT, "};\n\n");
}
#ifdef __USE_PROTOS
void p_accept_table(void)
#else
void p_accept_table()
#endif
{
register int i = 1;
register int items_on_line = 0;
int true_interactive = TRUE;
/* make sure element for one past (zzerraction) -WEC 12/16/92 */
fprintf(OUT,"\n%sDfaState %saccepts[%d] = {\n ",
gen_cpp?ClassName("::"):"",
gen_cpp?ClassName("::"):"",
dfa_allocated+1);
/* don't do anything if no dfa nodes */
if (i>dfa_allocated) goto skip_accepts;
for (;;) {
int accept=0; /* MR14a - Manuel Kessler (mlkessle@cip.physik.uni-wuerzburg.de) */
set accept_set;
set nfa_states;
unsigned int *t, *nfa_i;
unsigned int *q, *regular_expr;
accept_set = empty;
nfa_states = DFA(i)->nfa_states;
t = nfa_i = set_pdq(nfa_states);
/* NOTE: picks lowest accept because accepts monotonic */
/* with respect to nfa node numbers and set_pdq */
/* returns in that order */
while((*nfa_i != nil) && (!(accept = NFA(*nfa_i)->accept))){
nfa_i++;
}
/* figure out if more than one accept state there */
if (warn_ambig ){
set_orel(accept, &accept_set);
while(*nfa_i != nil){
set_orel(NFA(*nfa_i)->accept, &accept_set);
nfa_i++;
}
/* remove error action from consideration */
set_rm(0, accept_set);
if( set_deg(accept_set)>1){
fprintf(stderr, "dlg warning: ambiguous regular expression ");
q = regular_expr = set_pdq(accept_set);
while(*regular_expr != nil){
fprintf(stderr," %d ", *regular_expr);
++regular_expr;
}
fprintf(stderr, "\n");
free(q);
}
}
if ((DFA(i)->alternatives) && (accept != 0)){
true_interactive = FALSE;
}
fprintf(OUT, "%d, ", accept);
/* free up memory before we "break" below -ATG 4/6/95 */
free(t);
set_free(accept_set);
if ((++i)>dfa_allocated)
break;
if ((++items_on_line)>=MAX_ON_LINE){
fprintf(OUT,"\n ");
items_on_line = 0;
}
/*
free(t);
set_free(accept_set);
*/
}
/* make sure element for one past (zzerraction) -WEC 12/16/92 */
skip_accepts:
fprintf(OUT, "0\n};\n\n");
}
#ifdef __USE_PROTOS
void p_action_table(void)
#else
void p_action_table()
#endif
{
register int i;
char* theClassName = ClassName("");
if ( gen_cpp )
fprintf(OUT, "Ptr%sMemberFunc %s::actions[%d] = {\n", theClassName,
theClassName, action_no+1);
else
fprintf(OUT, "void (*actions[%d])() = {\n", action_no+1);
if ( gen_cpp )
/* fprintf(OUT, "\t(Ptr%sMemberFunc)&%s::erraction,\n", theClassName, theClassName);*/
fprintf(OUT, "\t&%s::erraction,\n", theClassName);
else
fprintf(OUT, "\tzzerraction,\n");
for (i=1; i<action_no; ++i) {
if ( gen_cpp )
/* fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d,\n", theClassName, theClassName, i);*/
fprintf(OUT,"\t&%s::act%d,\n", theClassName, i);
else
fprintf(OUT,"\tact%d,\n", i);
DAWDLE;
}
if ( gen_cpp )
/* fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d\n", theClassName, theClassName, i);*/
fprintf(OUT,"\t&%s::act%d\n", theClassName, i);
else
fprintf(OUT,"\tact%d\n", i);
fprintf(OUT, "};\n\n");
}
#ifdef __USE_PROTOS
void p_shift_table(int m) /* MR1 */
#else
void p_shift_table(m) /* MR1 */
int m;
#endif
{
register int i = 0, j;
register int items_on_line = 0;
fprintf(OUT, "%s unsigned char %sshift%d[%d] = {\n ",
gen_cpp?"":"static",
gen_cpp?ClassName("::"):"", m, CHAR_RANGE);
for (;;) {
/* find which partition character i is in */
for (j=0; j<dfa_class_nop[mode_counter]; ++j){
if (set_el(i,class_sets[j]))
break;
}
fprintf(OUT,"%d",j);
if ((++i)>=CHAR_RANGE)
break;
fprintf(OUT,", ");
if ((++items_on_line)>=MAX_ON_LINE){
fprintf(OUT,"\n ");
items_on_line = 0;
}
}
fprintf(OUT, "\n};\n\n");
}
#ifdef __USE_PROTOS
void p_base_table(void)
#else
void p_base_table()
#endif
{
register int m;
fprintf(OUT, "%sDfaState %sdfa_base[] = {\n",
gen_cpp?ClassName("::"):"static ",
gen_cpp?ClassName("::"):"");
for(m=0; m<(mode_counter-1); ++m)
fprintf(OUT, "\t%d,\n", dfa_basep[m]-1);
fprintf(OUT, "\t%d\n};\n\n", dfa_basep[m]-1);
}
#ifdef __USE_PROTOS
void p_class_table(void) /* MR1 */
#else
void p_class_table() /* MR1 */
#endif
{
#if 0
register int m;
fprintf(OUT,"%s int %sdfa_class_no[] = {\n",
gen_cpp?"":"static",
gen_cpp?ClassName("::"):"");
for(m=0; m<(mode_counter-1); ++m)
fprintf(OUT,"\t%d,\n", dfa_class_nop[m]);
fprintf(OUT,"\t%d\n};\n\n", dfa_class_nop[m]);
#endif
}
#ifdef __USE_PROTOS
void p_bshift_table(void) /* MR1 */
#else
void p_bshift_table() /* MR1 */
#endif
{
register int m;
fprintf(OUT,"%s unsigned char *%sb_class_no[] = {\n",
gen_cpp?"":"static",
gen_cpp?ClassName("::"):"");
for(m=0; m<(mode_counter-1); ++m)
fprintf(OUT, "\tshift%d,\n", m);
fprintf(OUT, "\tshift%d\n};\n\n", m);
}
#ifdef __USE_PROTOS
void p_alternative_table(void) /* MR1 */
#else
void p_alternative_table() /* MR1 */
#endif
{
register int i;
if ( !gen_cpp ) fprintf(OUT, "#define ZZINTERACTIVE\n\n");
if ( gen_cpp )
fprintf(OUT, "DLGChar %salternatives[%d] = {\n", /* mr23 vhs %sDfaStates+1 */
ClassName("::"),
dfa_allocated+1); /* vhs ClassName("::")); */
else
fprintf(OUT, "static %s zzalternatives[DfaStates+1] = {\n",
minsize(dfa_allocated));
for(i=1; i<=dfa_allocated; ++i)
fprintf(OUT, "\t%d,\n", DFA(i)->alternatives);
fprintf(OUT, "/* must have 0 for zzalternatives[DfaStates] */\n");
fprintf(OUT, "\t0\n};\n\n");
}
#ifdef __USE_PROTOS
void p_mode_def(char *s,int m) /* MR1 */
#else
void p_mode_def(s,m) /* MR1 */
char *s;
int m;
#endif
{
if ( gen_cpp )
{
mode_name[cur_mode] = mystrdup(s);
mode_number[cur_mode] = m;
cur_mode++;
}
else
fprintf(mode_stream, "#define %s %d\n", s, m);
}
#ifdef __USE_PROTOS
char * ClassName(char *suffix)
#else
char * ClassName(suffix)
char *suffix;
#endif
{
static char buf[200];
extern char *class_name;
sprintf(buf, "%s%s", class_name, suffix);
return buf;
}
#ifdef DEBUG
/* print out a particular nfa node that is pointed to by p */
#ifdef __USE_PROTOS
void p_nfa_node(nfa_node *p)
#else
void p_nfa_node(p)
nfa_node *p;
#endif
{
register nfa_node *t;
if (p != NIL_INDEX){
printf("NFA state : %d\naccept state : %d\n",
NFA_NO(p),p->accept);
if (p->trans[0] != NIL_INDEX){
printf("trans[0] => %d on ", NFA_NO(p->trans[0]));
p_set(p->label);
printf("\n");
}
else
printf("trans[0] => nil\n");
if (p->trans[1] != NIL_INDEX)
printf("trans[1] => %d on epsilon\n",
NFA_NO(p->trans[1]));
else
printf("trans[1] => nil\n");
printf("\n");
}
}
#endif
#ifdef DEBUG
/* code to print out special structures when using a debugger */
#ifdef __USE_PROTOS
void p_nfa(p)
#else
void p_nfa(nfa_node *p)
nfa_node *p; /* state number also index into array */
#endif
{
/* each node has a marker on it so it only gets printed once */
operation_no++; /* get new number */
s_p_nfa(p);
}
#ifdef __USE_PROTOS
void s_p_nfa(nfa_node *p)
#else
void s_p_nfa(p)
nfa_node *p; /* state number also index into array */
#endif
{
if ((p != NIL_INDEX) && (p->nfa_set != operation_no)){
/* so it is only printed once */
p->nfa_set = operation_no;
p_nfa_node(p);
s_p_nfa(p->trans[0]);
s_p_nfa(p->trans[1]);
}
}
#ifdef __USE_PROTOS
void p_dfa_node(dfa_node *p)
#else
void p_dfa_node(p)
dfa_node *p;
#endif
{
int i;
if (p != NIL_INDEX){
printf("DFA state :%d\n",NFA_NO(p));
if (p->done)
printf("done\n");
else
printf("undone\n");
printf("from nfa states : ");
p_set(p->nfa_states);
printf("\n");
/* NOTE: trans arcs stored as ints rather than pointer*/
for (i=0; i<class_no; i++){
printf("%d ",p->trans[i]);
}
printf("\n\n");
}
}
#ifdef __USE_PROTOS
void p_dfa(void)
#else
void p_dfa()
#endif
{
/* prints out all the dfa nodes actually allocated */
int i;
for (i = 1; i<=dfa_allocated; i++)
p_dfa_node(NFA(i));
}
/* print out numbers in the set label */
#ifdef __USE_PROTOS
void p_set(set label)
#else
void p_set(label)
set label;
#endif
{
unsigned *t, *e;
if (set_nil(label)){
printf("epsilon\n");
}else{
t = e = set_pdq(label);
while(*e != nil){
printf("%d ", (*e+MIN_CHAR));
e++;
}
printf("\n");
free(t);
}
}
#endif
|