home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2_LEX.ZIP / YTAB.C < prev    next >
C/C++ Source or Header  |  1989-10-07  |  25KB  |  868 lines

  1. /*
  2.  *                   * * *   W A R N I N G    * * *
  3.  *
  4.  * This file has been hand-modified from that which was produced by Yacc
  5.  * from 'lex.y'. If you plan on rebuilding this with Yacc, be SURE to run
  6.  * the virgin supplied 'lex.y' thru Yacc first, do a source compare of it's
  7.  * output 'ytab.c' with this file, and note & understand the manual mods
  8.  * that were made here.
  9.  *                                              Bob Denny
  10.  *
  11.  * Modified 02-Dec-80 Bob Denny -- Conditionalized debug code for smaller size
  12.  *                                 YYSMALL no longer used.
  13.  *                                 Removed hackish accent grave's.
  14.  *                           01    Moved calls do dfa build, min, print and
  15.  *                                  write, and to stat() to lex.c, so this
  16.  *                                  module could be put in overlay region.
  17.  *                                  Moved impure data out into ytdata.c to
  18.  *                                  go to the root.
  19.  *
  20.  *          29-May-81 Bob Denny -- Define yysterm fwd. Remove from LEXLEX.H.
  21.  *                                   for RSX overlaying.
  22.  *          19-Mar-82 Bob Denny -- New compiler and library. Typcasts needed.
  23.  *                                  Conditionally compile remote formats, not
  24.  *                                  supported in VAX C.
  25.  * More     03-May-82 Bob Denny -- Final touches, remove unreferenced autos
  26.  * More        20-Nov-83 Scott Guthery -- Adapt for IBM PC & DeSmet C
  27.  */
  28.  
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <ctype.h>
  33. #include <stdarg.h>
  34. #include "ytab.h"
  35. #include "lexlex.h"
  36. #include "lextern.h"
  37.  
  38. char *yysterm[] = {
  39. "error",
  40. "NAME",
  41. "CCLASS",
  42. "STRING",
  43. "CONCAT",
  44. 0 };
  45.  
  46. /* char copr[] = "Copyright (c) 1978 Charles H. Forsyth";*/
  47.  
  48. struct des {
  49.         struct nfa *d_start;
  50.         struct nfa *d_final;
  51. };
  52. struct nlist {
  53.         struct  nlist   *nl_next;
  54.         struct  nfa     *nl_base;
  55.         struct  nfa     *nl_end;
  56.         struct  nfa     *nl_start;
  57.         struct  nfa     *nl_final;
  58.         char    *nl_name;
  59. } *nlist;
  60.  
  61. int     str_length;
  62. int     yydebug = 0;                /* 1 for debugging */
  63. int     yychar = -1;     /* current input token number */
  64. int     yynerrs = 0;               /* number of errors */
  65. int     yyerrflag = 0;          /* error recovery flag */
  66.  
  67. #define yyclearin yychar = -1
  68. #define yyerrok yyerrflag = 0
  69.  
  70. #ifndef YYSTYPE
  71. #define YYSTYPE char *
  72. #endif
  73. #ifndef YYVCOPY
  74. #define YYVCOPY(x,y)    strcpy((x),(y))
  75. #endif
  76.  
  77. void yyactr(int);
  78. void yyerror(char *, ...);
  79. int yyexcp(int);
  80. void unget(int);
  81. int get(void);
  82. void spccl(char *, char *, struct des *, char **);
  83. void copy(char *, char *, int);
  84. void copynfa(struct nlist *, struct nfa *, struct des *);
  85. struct nlist *lookup(char *);
  86. void copycode(void);
  87. void skipstr(int);
  88. void action(void);
  89. struct des *newdp(struct nfa *, struct nfa *);
  90. struct nfa *elem(int, YYSTYPE);
  91. void name(int);
  92. int mapc(int);
  93. void string(int);
  94. int cclass(void);
  95. int yylex(void);
  96.  
  97. YYSTYPE yyval = NULL;
  98. YYSTYPE *yypv;
  99. YYSTYPE yylval = NULL;
  100.  
  101. # define YYMAXDEPTH 150
  102. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  103.  
  104. int      nlook = 0;
  105. int      yyline = 0;
  106. char     *breakc;
  107. char     *ignore;
  108. char     *illeg;
  109.  
  110. void yyactr(int __np__)
  111. {
  112.  
  113.         struct nfa *np, *nbase;
  114.         char *cp;
  115.         struct des *dp;
  116.         struct trans *tp;
  117.         struct nlist *nl;
  118.         int i, c;
  119.  
  120. switch(__np__){
  121.  
  122. case 7:
  123. {
  124.                 dp = yypv[3];
  125.                 nl = yypv[1];
  126.                 np = nl->nl_base;
  127.                 nl->nl_start = dp->d_start;
  128.                 nl->nl_final = dp->d_final;
  129.                 nl->nl_end = nfap;
  130. #ifdef DEBUG
  131.                 fprintf(lexlog, "NFA (auxiliary definition) for %s\n",
  132.                                 nl->nl_name);
  133.                 nfaprint(dp->d_start, nl->nl_base);
  134. #endif
  135.                 nbase = lalloc(i = nl->nl_end-nl->nl_base, sizeof(*nbase),
  136.                         "nfa storage");
  137.                 copynfa(nl, nbase, dp);
  138.                 nl->nl_start = dp->d_start;
  139.                 nl->nl_final = dp->d_final;
  140.                 nl->nl_end = nbase+i;
  141.                 nl->nl_base = nbase;
  142.                 nfap = np;
  143.                 spccl(nl->nl_name, "ignore", dp, &ignore);
  144.                 spccl(nl->nl_name, "break", dp, &breakc);
  145.                 spccl(nl->nl_name, "illegal", dp, &illeg);
  146.         } break;
  147. case 8:
  148. { copycode(); } break;
  149. case 9:
  150. {
  151.                 yyval = lookup(yypv[1]);
  152.                 ((struct nlist *)yyval)->nl_base = nfap;
  153.                 if (((struct nlist *)yyval)->nl_start)
  154.                         yyerror("%s redefined", ((struct nlist *)yyval)->nl_name);
  155.         } break;
  156. case 10:
  157. { yyval = lookup(yypv[1]); } break;
  158. case 11:
  159. {
  160.                 np = elem(CCL, yypv[1]);
  161.                 yyval = newdp(np, np->n_succ[0] = elem(FIN));
  162.         } break;
  163. case 12:
  164. {
  165.                 cp = yypv[1];
  166.                 if (str_length == 0) {
  167.                         np = elem(EPSILON);
  168.                         yyval = newdp(np, np->n_succ[0] = elem(FIN));
  169.                         return;
  170.                 }
  171.                 yyval = np = elem(*cp++);
  172.                 while (--str_length > 0)
  173.                         np = np->n_succ[0] = elem(*cp++);
  174.                 yyval = newdp(yyval, np->n_succ[0] = elem(FIN));
  175.         } break;
  176. case 13:
  177. {
  178.                 if ((nl = yypv[1])->nl_end == 0) {
  179.                         yyerror("%s not defined", nl->nl_name);
  180.                         nl->nl_base = nl->nl_end = elem(FIN);
  181.                         nl->nl_start = nl->nl_final = nl->nl_base;
  182.                 }
  183.                 yyval = dp = lalloc(1, sizeof(*dp), "dfa input");
  184.                 nbase = nfap;
  185.                 i = nl->nl_end-nl->nl_base;
  186.                 if ((nfap += i) >= &nfa[MAXNFA]) {
  187.                         yyerror("Out of NFA nodes", NULL);
  188.                         exit(1);
  189.                 }
  190.                 copynfa(nl, nbase, dp);
  191.         } break;
  192. case 14:
  193. {
  194.                 yyval = dp = yypv[1];
  195.                 dp->d_start = newnfa(EPSILON, np = dp->d_start, 0);
  196.                 dp->d_final->n_char = EPSILON;
  197.                 dp->d_final->n_succ[0] = np;
  198.                 dp->d_final->n_succ[1] = np = elem(FIN);
  199.                 dp->d_start->n_succ[1] = np;
  200.                 dp->d_final = np;
  201.         } break;
  202. case 15:
  203. {
  204.                 yyval = dp = yypv[1];
  205.                 dp->d_start = newnfa(EPSILON, dp->d_start,
  206.                         ((struct des *)yypv[3])->d_start);
  207.                 dp->d_final->n_char = EPSILON;
  208.                 dp->d_final = dp->d_final->n_succ[0] = np = elem(FIN);
  209.                 dp = yypv[3];
  210.                 dp->d_final->n_char = EPSILON;
  211.                 dp->d_final->n_succ[0] = np;
  212.                 free(yypv[3]);
  213.         } break;
  214. case 16:
  215. {
  216.                 yyval = yypv[1];
  217.                 dp = yypv[2];
  218.                 np = ((struct des *)yyval)->d_final;
  219.                 ((struct des *)yyval)->d_final = dp->d_final;
  220.                 np->n_char = dp->d_start->n_char;
  221.                 np->n_ccl = dp->d_start->n_ccl;
  222.                 np->n_succ[0] = dp->d_start->n_succ[0];
  223.                 np->n_succ[1] = dp->d_start->n_succ[1];
  224.                 free(yypv[2]);
  225.         } break;
  226. case 17:
  227. { yyval = yypv[2]; } break;
  228. case 18:
  229. {
  230.                 ending();
  231.         trans1:
  232. #ifdef DEBUG
  233.                 fprintf(lexlog, "\nNFA for complete syntax\n");
  234.                 fprintf(lexlog, "state 0\n");
  235.                 for (tp = trans; tp < transp; tp++)
  236.                         fprintf(lexlog, "\tepsilon\t%d\n", tp->t_start-nfa);
  237.                 for (tp = trans; tp < transp; tp++)
  238.                         nfaprint(tp->t_start, nfa);
  239. #else
  240.                 ;
  241. #endif
  242.                                                                 /* 01 */
  243.         } break;
  244. case 19:
  245. { goto trans1; } break;
  246. case 22:
  247. {
  248.                 llactr();
  249.         } break;
  250. case 23:
  251. { dp = yypv[1];  newtrans(dp->d_start, dp->d_final); } break;
  252. case 24:
  253. { copycode(); } break;
  254. case 25:
  255. {
  256.                 ending();
  257.                 while ((c = get()) != EOF)
  258.                         putc(c, llout);
  259.         } break;
  260. case 26:
  261. { action(); } break;
  262. case 27:
  263. {
  264.                 if (nlook >= NBPW)
  265.                         yyerror("More than %d translations with lookahead",
  266.                                         NBPW);
  267.                 yyval = dp = yypv[1];
  268.                 np = dp->d_final;
  269.                 np->n_char = EPSILON;
  270.                 np->n_flag |= LOOK;
  271.                 np->n_succ[0] = ((struct des *)yypv[3])->d_start;
  272.                 dp->d_final = ((struct des *)yypv[3])->d_final;
  273.                 np->n_look = nlook;
  274.                 dp->d_final->n_look = nlook++;
  275.                 dp->d_final->n_flag |= FLOOK;
  276.                 free(yypv[3]);
  277.         } break;
  278. }
  279. }
  280. int yyerrval = 256;
  281.  
  282. /*
  283.  * Lexical analyser
  284.  * (it isn't done with lex...)
  285.  */
  286. char     buffer[150];                                    /* 01 */
  287.  
  288. int yylex(void)
  289. {
  290.         register c;
  291.         register char *cp;
  292.         int lno;
  293.  
  294.         if (yyline == 0)
  295.                 yyline++;
  296. loop:
  297.         c = get();
  298.         if (isupper(c)) {
  299.                 name(c);
  300.                 for (cp = yylval; c = *cp; cp++)
  301.                         if (isupper(c))
  302.                                 *cp = tolower(c);
  303.                 return(STRING);
  304.         } else if (islower(c) || c == '_') {
  305.                 name(c);
  306.                 return(NAME);
  307.         }
  308.         switch (c) {
  309.         case -1 /*EOF*/:
  310.                 return(0);
  311.  
  312.         case '[':
  313.                 return(cclass());
  314.  
  315.         case '(':
  316.         case ')':
  317.         case '{':
  318.         case '}':
  319.         case '*':
  320.         case '|':
  321.         case '=':
  322.         case ';':
  323.         case '%':
  324.                 return(c);
  325.  
  326.         case '/':
  327.                 if ((c = get()) != '*') {
  328.                         unget(c);
  329.                         return('/');
  330.                 }
  331.                 lno = yyline;
  332.                 for (; c != EOF; c = get())
  333.                         if (c == '*')
  334.                                 if ((c = get()) == '/')
  335.                                         goto loop; else
  336.                                         unget(c);
  337.                 yyline = lno;
  338.                 yyerror("End of file in comment", NULL);
  339.  
  340.         case '\'':
  341.         case '"':
  342.                 yylval = buffer;
  343.                 string(c);
  344.                 return(STRING);
  345.  
  346.         case '\n':
  347.         case '\r':
  348.         case ' ':
  349.         case '\t':
  350.                 goto loop;
  351.  
  352.         default:
  353.                 yylval = buffer;
  354.                 buffer[0] = c;
  355.                 buffer[1] = 0;
  356.                 str_length = 1;
  357.                 return(STRING);
  358.         }
  359. }
  360.  
  361. char     ccl[(NCHARS+1)/NBPC];                           /* 01 */
  362.  
  363. int cclass(void)
  364. {
  365.         register c, i, lc;
  366.         int compl;
  367.  
  368.         compl = 0;
  369.         for (i = 0; i < sizeof ccl; i++)
  370.                 ccl[i] = 0;
  371.         if ((c = get()) == '^')
  372.                 compl++; else
  373.                 unget(c);
  374.         lc = -1;
  375.         while ((c = mapc(']')) != EOF) {
  376.                 if (c == '-' && lc >= 0) {
  377.                         if ((c = mapc(']')) == EOF)
  378.                                 break;
  379.                         for (i = lc; i <= c; i++)
  380.                                 ccl[i/NBPC] |= 1<<(i%NBPC);
  381.                         lc = -1;
  382.                         continue;
  383.                 }
  384.                 ccl[c/NBPC] |= 1<<(c%NBPC);
  385.                 lc = c;
  386.         }
  387.         if (compl) {
  388.                 for (i = 0; i < sizeof ccl; i++)
  389.                         ccl[i] ^= -1;
  390.                 if (aflag == 0)
  391.                         for (i = 0200; i < (1<<NBPC); i++)
  392.                                 ccl[i/NBPC] &= ~(1 << (i%NBPC));
  393.         }
  394.         yylval = newccl(ccl);
  395.         return(CCLASS);
  396. }
  397.  
  398. void string(int ec)
  399. {
  400.         register char *cp;
  401.         register c;
  402.  
  403.         for (cp = buffer; (c = mapc(ec)) != EOF;)
  404.                 *cp++ = c;
  405.         *cp = 0;
  406.         str_length = cp-buffer;
  407. }
  408.  
  409. int mapc(int ec)
  410. {
  411.         register c, v, i;
  412.  
  413.         if ((c = get()) == ec)
  414.                 return(EOF);
  415.         switch(c) {
  416.         case -1 /*EOF*/:
  417.                 yyerror("End of file in string", NULL);
  418.                 return(c);
  419.  
  420.         case '\\':
  421.                 if ((c = get()) >= '0' && c <= '7') {
  422.                         i = 0;
  423.                         for (v = 0; c>='0' && c<='7' && i++<3; c = get())
  424.                                 v = v*010 + c-'0';
  425.                         unget(c);
  426.                         return(v&0377);
  427.                 }
  428.                 switch (c) {
  429.                 case 'n':
  430.                         return('\n');
  431.                 case 't':
  432.                         return('\t');
  433.  
  434.                 case 'b':
  435.                         return('\b');
  436.  
  437.                 case 'r':
  438.                         return('\r');
  439.  
  440.                 case '\n':
  441.                         yyline++;
  442.                         return(mapc(ec));
  443.                 }
  444.  
  445.         default:
  446.                 return(c);
  447.         }
  448. }
  449.  
  450. void name(int c)
  451. {
  452.         register char *cp;
  453.  
  454.         for (yylval=cp=buffer; isalpha(c) || isdigit(c) || c=='_'; c=get())
  455.                 *cp++ = c;
  456.         *cp = 0;
  457.         str_length = cp-buffer;
  458.         unget(c);
  459. }
  460.  
  461. /*
  462.  * Miscellaneous functions
  463.  * used only by lex.y
  464.  */
  465. struct nfa *elem(int k, YYSTYPE v)
  466. {
  467.         struct nfa *fp;
  468.  
  469.         fp = newnfa(k, 0, 0);
  470.         if (k == CCL)
  471.                 fp->n_ccl = v;
  472.         return(fp);
  473. }
  474.  
  475. struct des *newdp(struct nfa *st, struct nfa *fi)
  476. {
  477.         register struct des *dp;
  478.  
  479.         dp = (struct des *)lalloc(1, sizeof(*dp), "dfa input");
  480.         dp->d_start = st;
  481.         dp->d_final = fi;
  482.         return(dp);
  483. }
  484.  
  485. void action(void)
  486. {
  487.         register c;
  488.         int lno, lev;
  489.         newcase(transp-trans);
  490.         lno = yyline;
  491.         lev = 0;
  492.         for (; (c = get()) != EOF && (c != '}' || lev); putc(c, llout))
  493.                 if (c == '{')
  494.                         lev++;
  495.                 else if (c == '}')
  496.                         lev--;
  497.                 else if (c == '\'' || c == '"') {
  498.                         putc(c, llout);
  499.                         skipstr(c);
  500.                 }
  501.         fprintf(llout, "\n         break;\n");
  502.         if (c == EOF) {
  503.                 yyline = lno;
  504.                 yyerror("End of file in action", NULL);
  505.         }
  506. }
  507.  
  508. void skipstr(int ec)
  509. {
  510.         register c;
  511.  
  512.         while ((c = get()) != ec && c != EOF) {
  513.                 putc(c, llout);
  514.                 if (c == '\\' && (c = get()) != EOF)
  515.                         putc(c, llout);
  516.         }
  517. }
  518.  
  519. void copycode(void)
  520. {
  521.         int lno;
  522.         register c;
  523.  
  524.         setline();
  525.         lno = yyline;
  526.         for (; (c = get()) != EOF; putc(c, llout))
  527.                 if (c == '%') {
  528.                         if ((c = get()) == '}')
  529.                                 return;
  530.                         unget(c);
  531.                         c = '%';
  532.                 }
  533.         yyline = lno;
  534.         yyerror("Incomplete %{ declaration", NULL);
  535.         exit(1);
  536. }
  537.  
  538. struct nlist *lookup(char *s)
  539. {
  540.         register struct nlist *nl;
  541.         register char *cp;
  542.         int i;
  543.         for (nl = nlist; nl; nl = nl->nl_next)
  544.                 if (!strcmp(s, nl->nl_name))
  545.                         return(nl);
  546.         nl = (struct nlist *)lalloc(1, sizeof(*nl), "namelist");
  547.         nl->nl_start = nl->nl_end = nl->nl_base = nl->nl_end = 0;
  548.         nl->nl_next = nlist;
  549.         nlist = nl;
  550.         i = 0;
  551.         nl->nl_name = cp = lalloc(strlen(s) + 1, sizeof(*cp), "namelist");
  552.         strcpy(cp, s);
  553.         return(nl);
  554. }
  555.  
  556. void copynfa(struct nlist *nl, struct nfa *nbase, struct des *dp)
  557. {
  558.         register struct nfa *np, *ob;
  559.         register j;
  560.         int i;
  561.  
  562.         ob = nl->nl_base;
  563.         i = nl->nl_end-ob;
  564.         copy((char *)nbase, (char *)ob, sizeof(*np) * i);
  565.         for (np = nbase; i-- > 0; np++) {
  566.                 np->n_flag &= ~NPRT;
  567.                 for (j = 0; j < 2; j++)
  568.                         if (np->n_succ[j])
  569.                                 np->n_succ[j] = (np->n_succ[j]-ob)+nbase;
  570.         }
  571.         dp->d_start = (nl->nl_start-ob)+nbase;
  572.         dp->d_final = (nl->nl_final-ob)+nbase;
  573. }
  574.  
  575. void copy(char *out, char *in, int count)
  576. {
  577.         while (--count >= 0)
  578.                 *out++ = *in++;
  579. }
  580.  
  581. void spccl(char *nm, char *isit, struct des *dp, char **where)
  582. {
  583.  
  584.         if (!strcmp(nm, isit)) {
  585.                 if (*where != 0)
  586.                         yyerror("Redefinition of %s class", isit);
  587.                 if (dp->d_start->n_char == CCL &&
  588.                                 dp->d_start->n_succ[0] == dp->d_final)
  589.                         *where = dp->d_start->n_ccl;
  590.                 else
  591.                         yyerror("Illegal %s class", isit);
  592.         }
  593. }
  594.  
  595. int get(void)
  596. {
  597.         register int c;
  598.  
  599.         if ((c = getc(lexin)) == '\n')
  600.                 yyline++;
  601.         return(c);
  602. }
  603.  
  604. void unget(int c)
  605. {
  606.         if (c == '\n')
  607.                 yyline--;
  608.         ungetc(c, lexin);
  609. }
  610.  
  611. void yyerror(char *format, ...)
  612. {
  613.         char buffer[50];
  614.         va_list args;
  615.  
  616.         if (yyline)
  617.                 fprintf(stderr, "%d: ", yyline);
  618.         va_start(args, format);
  619.         vfprintf(stderr, format, args);
  620.         va_end(args);
  621.         if (yychar > 256)
  622.                 fprintf(stderr, " near '%s'", yysterm[yychar-256]);
  623.         else if (yychar < 256 && yychar > 0)
  624.                 fprintf(stderr, " near '%c'", yychar);
  625.         fprintf(stderr, "\n");
  626. }
  627.  
  628. int nterms = 15;
  629. int nnonter = 13;
  630. int nstate = 41;
  631.  
  632. char *yysnter[14] = {
  633. "$accept",
  634. "lexfile",
  635. "auxiliary_section",
  636. "translation_section",
  637. "auxiliaries",
  638. "auxiliary",
  639. "namedef",
  640. "regexp",
  641. "name",
  642. "translations",
  643. "translation",
  644. "llactr",
  645. "pattern",
  646. "action" };
  647.  
  648. int yylast = 245;
  649. int yyexcp(int s)
  650. {
  651.         switch(s){
  652.         case 1:
  653.                 if( yychar == 0 ) return( -1 );
  654.                 return( 0 );
  655.         case 2:
  656.                 if( yychar == 0 ) return( 19 );
  657.                 return( 22 );
  658.                 }
  659.         }
  660.  
  661. yyact[] = {
  662.  
  663.   23,  40,  32,  23,  29,  32,  23,  15,  32,  23,
  664.   31,  32,  23,  35,  32,  18,  26,  13,  23,  32,
  665.   34,  23,  37,  11,   4,   5,  16,  28,  17,  12,
  666.   19,  19,  10,   9,  22,   6,  27,  25,   3,   8,
  667.    2,   1,   0,   0,  36,   0,   0,   0,   0,   0,
  668.    0,   0,   0,   0,  38,   0,  39,   0,   0,   0,
  669.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  670.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  671.    0,   0,   0,   0,  33,   0,   0,  33,   0,   0,
  672.   33,   0,   0,  33,   0,   0,  30,   0,   0,   0,
  673.    0,   0,  14,  14,   0,   0,   0,   0,   0,   0,
  674.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  675.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  676.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  677.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  678.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  679.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  680.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  681.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  682.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  683.    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  684.    0,   0,   0,   0,   0,   0,   0,  24,  20,  21,
  685.   24,  20,  21,  24,  20,  21,  24,  20,  21,  24,
  686.   20,  21,   0,   0,   0,  24,  20,  21,  24,  20,
  687.   21,   0,   0,   7,   7 };
  688. yypact[] = {
  689.  
  690.  -13,-2000,-2000, -14, -20,-1000, -54,-1000,-1000, -22,
  691.  -22, -21,-1000,-1000,-1000, -19,-1000,-119, -27, -34,
  692. -1000,-1000,-1000, -19,-1000,-1000,-1000, -37,-1000,-1000,
  693. -1000,-1000,-1000, -19, -23, -19, -40,-1000, -28, -31,
  694. -1000 };
  695. yypgo[] = {
  696.  
  697.    0,  41,  40,  39,  38,  25,  35,  20,  34,  33,
  698.   26,  32,  28,  27 };
  699. yyr1[] = {
  700.  
  701.    0,   1,   1,   2,   2,   4,   4,   5,   5,   6,
  702.    8,   7,   7,   7,   7,   7,   7,   7,   3,   3,
  703.    9,   9,  11,  10,  10,  10,  13,  12,  12,  -1 };
  704. yyr2[] = {
  705.  
  706.    0,   2,   0,   3,   2,   2,   1,   4,   2,   1,
  707.    1,   1,   1,   1,   2,   3,   2,   3,   1,   0,
  708.    2,   2,   0,   2,   2,   2,   1,   3,   1,  -1 };
  709. yychk[] = {
  710.  
  711.    0,  -1,  -2,  -4,  37,  -5,  -6, 257,  -3,  -9,
  712.  -11,  37,  -5,  37, 123,  61, -10, -12,  37,  -7,
  713.  258, 259,  -8,  40, 257, -10,  37,  -7, -13, 123,
  714.  123,  37,  42, 124,  -7,  47,  -7,  59,  -7,  -7,
  715.   41 };
  716. yydef[] = {
  717.  
  718.    2,  -2,  -2,   0,   0,   6,   0,   9,   1,  18,
  719.    0,   0,   5,   4,   8,   0,  20,   0,   0,  28,
  720.   11,  12,  13,   0,  10,  21,   3,   0,  23,  26,
  721.   24,  25,  14,   0,  16,   0,   0,   7,  15,  27,
  722.   17 };
  723.  
  724. # define YYFLAG1 -1000
  725. # define YYFLAG2 -2000
  726.  
  727. /* test me on cases where there are more than one reduction
  728. per state, leading to the necessity to look ahead, and other
  729. arcane flows of control.
  730. */
  731.  
  732. /*      parser for yacc output  */
  733. /* extern YYSTYPE yyval;        -- defined in the table file
  734.  * extern YYSTYPE yylval;       -- defined in the table file
  735.  * extern YYSTYPE *yypv;        -- defined in the table file
  736.  */
  737.  
  738. #ifdef  DEBUG
  739. #define LOGOUT  lexlog
  740. #endif
  741.  
  742. int yyparse(void)
  743. {
  744.    int yys[YYMAXDEPTH];
  745.    int yyj;
  746.    register yyn, yystate, *yyps;
  747.  
  748.    yystate = 0;
  749.    yychar = -1;
  750.    yynerrs = 0;
  751.    yyerrflag = 0;
  752.    yyps= &yys[0]-1;
  753.    yypv= &yyv[0]-1;
  754.  
  755.  yystack:    /* put a state and value onto the stack */
  756.  
  757. #ifdef DEBUG
  758.    if( yydebug  )
  759.         fprintf(LOGOUT, "state %d, value %d, char %d\n",yystate,yyval,yychar);
  760. #endif
  761.  
  762.    *++yyps = yystate;
  763.    *++yypv = yyval;
  764.  
  765.  yynewstate:
  766.  
  767.    yyn = yypact[yystate];
  768.  
  769.    if( yyn<= YYFLAG1 ){ /* simple state */
  770.       if( yyn == YYFLAG2 && yychar<0 ) yychar = yylex();
  771.       goto yydefault;
  772.       }
  773.  
  774.    if( yychar<0 ) yychar = yylex();
  775.    if( (yyn += yychar)<0 || yyn >= yylast ) goto yydefault;
  776.  
  777.    if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
  778.       yychar = -1;
  779.       yyval = yylval;
  780.       yystate = yyn;
  781.       if( yyerrflag > 0 ) --yyerrflag;
  782.       goto yystack;
  783.       }
  784.  
  785.  yydefault:
  786.    /* default state action */
  787.  
  788.    if( (yyn=yydef[yystate]) == -2 ) yyn = yyexcp( yystate );
  789.  
  790.   if( yyn == -1 ){ /* accept */
  791.       return( 0 );
  792.       }
  793.  
  794.    if( yyn == 0 ){ /* error */
  795.       /* error ... attempt to resume parsing */
  796.  
  797.       switch( yyerrflag ){
  798.  
  799.       case 0:   /* brand new error */
  800.  
  801.          ++yynerrs;
  802.          yyerror("syntax error", NULL);
  803.  
  804.       case 1:
  805.       case 2: /* incompletely recovered error ... try again */
  806.  
  807.          yyerrflag = 3;
  808.  
  809.          /* find a state where "error" is a legal shift action */
  810.  
  811.          while ( yyps >= yys ) {
  812.             yyn = yypact[*yyps] + yyerrval;
  813.             if( yyn>= 0 && yyn < yylast && yychk[yyact[yyn]] == yyerrval ){
  814.                yystate = yyact[yyn];  /* simulate a shift of "error" */
  815.                goto yystack;
  816.                }
  817.             yyn = yypact[*yyps];
  818.  
  819.             /* the current yyps has no shift onn "error", pop stack */
  820.  
  821. #ifdef DEBUG
  822.             if(yydebug)
  823.                 fprintf(LOGOUT, "error recovery pops state %d, uncovers %d\n",
  824.                         *yyps, yyps[-1]);
  825. #endif
  826.             --yyps;
  827.             --yypv;
  828.             }
  829.  
  830.          /* there is no state on the stack with an error shift ... abort */
  831.  
  832.     abort:
  833.          return(1);
  834.  
  835.       case 3:  /* no shift yet; clobber input char */
  836.  
  837. #ifdef DEBUG
  838.          if (yydebug)
  839.                 fprintf(LOGOUT, "error recovery discards char %d\n", yychar );
  840. #endif
  841.  
  842.          if( yychar == 0 ) goto abort; /* don't discard EOF, quit */
  843.          yychar = -1;
  844.          goto yynewstate;   /* try again in the same state */
  845.  
  846.          }
  847.  
  848.       }
  849.  
  850.    /* reduction by production yyn */
  851.  
  852. #ifdef DEBUG
  853.       if(yydebug) fprintf(LOGOUT, "reduce %d\n",yyn);
  854. #endif
  855.  
  856.       yyps -= yyr2[yyn];
  857.       yypv -= yyr2[yyn];
  858. /*    YYVCOPY(yyval,yypv[1]);
  859.  */   yyval = yypv[1];
  860.       yyactr(yyn);
  861.          /* consult goto table to find next state */
  862.       yyn = yyr1[yyn];
  863.       yyj = yypgo[yyn] + *yyps + 1;
  864.       if( yyj>=yylast || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  865.       goto yystack;  /* stack new state and value */
  866.  
  867.    }
  868.