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