home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 290_01 / parse.c < prev    next >
C/C++ Source or Header  |  1990-05-14  |  27KB  |  1,096 lines

  1.  
  2. /*  A Bison parser, made from parse.y  */
  3.  
  4. #define    CHAR    258
  5. #define    NUMBER    259
  6. #define    SECTEND    260
  7. #define    SCDECL    261
  8. #define    XSCDECL    262
  9. #define    WHITESPACE    263
  10. #define    NAME    264
  11. #define    PREVCCL    265
  12.  
  13.  
  14. #include "flexdef.h"
  15. #include "ecs.h"            /* RA.1989.12.30 */
  16. #include "nfa.h"            /* RA.1989.12.30 */
  17. #include "sym.h"            /* RA.1989.12.30 */
  18. #include "ccl.h"            /* RA.1989.12.30 */
  19. #include "misc.h"            /* RA.1989.12.30 */
  20.  
  21. int pat, scnum, eps,
  22.  headcnt, trailcnt, anyccl,
  23.  lastchar, i, actvp, rulelen;
  24. int trlcontxt, xcluflg,
  25.  cclsorted, varlength;
  26.  
  27. static int madeany = false;  /* whether we've made the '.' character class */
  28.  
  29.  
  30. #ifndef YYLTYPE
  31. typedef
  32.   struct yyltype
  33.     {
  34.       int timestamp;
  35.       int first_line;
  36.       int first_column;
  37.       int last_line;
  38.       int last_column;
  39.       char *text;
  40.    }
  41.   yyltype;
  42.  
  43. #define YYLTYPE yyltype
  44. #endif
  45.  
  46. #define    YYACCEPT    return(0)
  47. #define    YYABORT    return(1)
  48. #define    YYERROR    goto yyerrlab
  49. #ifndef YYSTYPE
  50. #define YYSTYPE int
  51. #endif
  52. #include <stdio.h>
  53.  
  54. #ifndef __STDC__
  55. #define const
  56. #endif
  57.  
  58.  
  59.  
  60. #define    YYFINAL        81
  61. #define    YYFLAG        -32767
  62. #define    YYNTBASE    31
  63.  
  64. #define YYTRANSLATE(x) ((unsigned)(x) <= 265 ? yytranslate[x] : 50)
  65.  
  66. static const char yytranslate[] = {     0,
  67.    2,   2,   2,   2,   2,   2,   2,   2,   2,  11,
  68.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  69.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  70.    2,   2,   2,  25,   2,  16,   2,   2,   2,  26,
  71.   27,  19,  20,  15,  30,  24,  18,   2,   2,   2,
  72.    2,   2,   2,   2,   2,   2,   2,   2,   2,  13,
  73.    2,  14,  21,   2,   2,   2,   2,   2,   2,   2,
  74.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  75.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  76.   28,   2,  29,  12,   2,   2,   2,   2,   2,   2,
  77.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  78.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  79.    2,   2,  22,  17,  23,   2,   2,   2,   2,   2,
  80.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  81.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  82.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  83.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  84.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  85.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  86.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  87.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  88.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  89.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  90.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  91.    2,   2,   2,   2,   2,   2,   2,   2,   2,   2,
  92.    2,   2,   2,   2,   2,   1,   2,   3,   4,   5,
  93.    6,   7,   8,   9,  10
  94. };
  95.  
  96. static const short yyrline[] = {     0,
  97.   46,  65,  74,  75,  76,  80,  83,  93,  97, 100,
  98.  103, 107, 108, 111, 119, 128, 137, 151, 161, 165,
  99.  168, 177, 185, 189, 211, 227, 234, 237, 242, 265,
  100.  273, 277, 284, 291, 298, 311, 325, 343, 365, 382,
  101.  389, 392, 395, 409, 412, 426, 454, 466, 474, 485
  102. };
  103.  
  104. static const char * const yytname[] = {     0,
  105. "error","$illegal.","CHAR","NUMBER","SECTEND","SCDECL","XSCDECL","WHITESPACE","NAME","PREVCCL",
  106. "'\\n'","'^'","'<'","'>'","','","'$'","'|'","'/'","'*'","'+'",
  107. "'?'","'{'","'}'","'.'","'\"'","'('","')'","'['","']'","'-'",
  108. "goal"
  109. };
  110.  
  111. static const short yyr1[] = {     0,
  112.   31,  32,  33,  33,  33,  34,  35,  35,  36,  36,
  113.   36,  37,  37,  38,  39,  39,  39,  39,  39,  40,
  114.   41,  41,  41,  42,  42,  43,  43,  43,  44,  45,
  115.   45,  46,  46,  46,  46,  46,  46,  46,  46,  46,
  116.   46,  46,  46,  47,  47,  48,  48,  48,  49,  49
  117. };
  118.  
  119. static const short yyr2[] = {     0,
  120.    4,   0,   5,   0,   2,   1,   1,   1,   3,   1,
  121.    1,   4,   0,   0,   4,   3,   3,   2,   1,   3,
  122.    3,   1,   1,   1,   0,   3,   2,   1,   2,   2,
  123.    1,   2,   2,   2,   6,   5,   4,   1,   1,   1,
  124.    3,   3,   1,   3,   4,   4,   2,   0,   2,   0
  125. };
  126.  
  127. static const short yydefact[] = {   2,
  128.    0,   0,   0,   5,   6,   7,   8,  13,   0,  14,
  129.    0,   0,  11,  10,   0,  19,  43,  40,   0,   0,
  130.   38,  50,   0,  48,   0,   0,  25,   0,  28,  31,
  131.   39,   0,   3,  25,  23,  22,   0,   0,   0,  48,
  132.    0,  12,   0,  25,  24,   0,  29,  18,  27,  30,
  133.   32,  33,  34,   0,   9,  17,  20,   0,  49,  41,
  134.   42,   0,  47,  44,  25,  16,  26,   0,  21,  45,
  135.    0,  15,   0,  37,  46,   0,  36,  35,   0,   0,
  136.    0
  137. };
  138.  
  139. static const short yydefgoto[] = {    79,
  140.      1,     3,     8,     9,    15,    10,    12,    25,    26,    37,
  141.     48,    27,    28,    29,    30,    31,    41,    38
  142. };
  143.  
  144. static const short yypact[] = {-32767,
  145.     61,    -5,    43,-32767,-32767,-32767,-32767,-32767,     8,     9,
  146.      1,     2,-32767,-32767,    28,-32767,-32767,-32767,    32,    45,
  147. -32767,-32767,    32,    13,    42,    19,    57,    32,    32,    50,
  148. -32767,    55,-32767,    57,-32767,-32767,    62,    15,    34,-32767,
  149.      4,-32767,    32,    57,-32767,    32,-32767,-32767,    32,    50,
  150. -32767,-32767,-32767,    74,-32767,-32767,-32767,    56,-32767,-32767,
  151. -32767,     5,   -17,-32767,    57,-32767,    32,    40,-32767,-32767,
  152.     76,-32767,     0,-32767,-32767,    36,-32767,-32767,    80,    81,
  153. -32767
  154. };
  155.  
  156. static const short yypgoto[] = {-32767,
  157. -32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,-32767,
  158.    -33,    -2,-32767,    -9,   -29,-32767,    44,-32767
  159. };
  160.  
  161.  
  162. #define    YYLAST        84
  163.  
  164.  
  165. static const short yytable[] = {  50,
  166.   56,  13,  16,  76,  17,   4,  63,  63,  -1,  14,
  167.   66,  18,  71,  19,  20,  11,  34,  59,  49,  50,
  168.   39,  17,  77,  44,  40,  21,  22,  23,  18,  24,
  169.   43,  72,  64,  70,  17,  32,  67,  50,  33,  60,
  170.   65,  18,  21,  22,  23,  35,  24,   5,   6,   7,
  171.   46,  47,  42,  36,  73,  21,  22,  23,  78,  24,
  172.   61,   2,  74,  55,  69,  -4,  -4,  -4,  51,  52,
  173.   53,  54,  45,  46,  47,  57,  58,  68,  75,  80,
  174.   81,   0,   0,  62
  175. };
  176.  
  177. static const short yycheck[] = {  29,
  178.   34,   1,   1,   4,   3,  11,   3,   3,   0,   9,
  179.   44,  10,  30,  12,  13,   8,  19,   3,  28,  49,
  180.   23,   3,  23,  26,  12,  24,  25,  26,  10,  28,
  181.   12,  65,  29,  29,   3,   8,  46,  67,  11,  25,
  182.   43,  10,  24,  25,  26,   1,  28,   5,   6,   7,
  183.   17,  18,  11,   9,  15,  24,  25,  26,  23,  28,
  184.   27,   1,  23,   9,   9,   5,   6,   7,  19,  20,
  185.   21,  22,  16,  17,  18,  14,  15,   4,   3,   0,
  186.    0,  -1,  -1,  40
  187. };
  188. #define YYPURE 1
  189.  
  190.  
  191. /* Skeleton output parser for bison,
  192.    copyright (C) 1984 Bob Corbett and Richard Stallman
  193.  
  194.  
  195. /* This is the parser code that is written into each bison parser
  196.   when the %semantic_parser declaration is not specified in the grammar.
  197.   It was written by Richard Stallman by simplifying the hairy parser
  198.   used when %semantic_parser is specified.  */
  199.  
  200. /* Note: there must be only one dollar sign in this file.
  201.    It is replaced by the list of actions, each action
  202.    as one case of the switch.  */
  203.  
  204. #define yyerrok        (yyerrstatus = 0)
  205. #define yyclearin    (yychar = YYEMPTY)
  206. #define YYEMPTY        -2
  207. #define YYEOF        0
  208. #define YYFAIL        goto yyerrlab;
  209.  
  210. #define YYTERROR    1
  211.  
  212. #ifndef YYIMPURE
  213. extern int yylex( void) ;
  214. #define YYLEX        yylex()
  215. #endif
  216.  
  217. #ifndef YYPURE
  218. extern int yylex( YYLTYPE *, YYLTYPE *) ;
  219. #define YYLEX        yylex(&yylval, &yylloc)
  220. #endif
  221.  
  222. /* If nonreentrant, generate the variables here */
  223.  
  224. #ifndef YYIMPURE
  225.  
  226. int    yychar;            /*  the lookahead symbol        */
  227. YYSTYPE    yylval;            /*  the semantic value of the        */
  228.                 /*  lookahead symbol            */
  229.  
  230. YYLTYPE yylloc;            /*  location data for the lookahead    */
  231.                 /*  symbol                */
  232.  
  233. int yynerr;            /*  number of parse errors so far       */
  234.  
  235. #ifdef YYDEBUG
  236. int yydebug = 0;        /*  nonzero means print parse trace    */
  237. #endif
  238.  
  239. #endif  /* YYIMPURE */
  240.  
  241.  
  242. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  243.  
  244. #ifndef    YYMAXDEPTH
  245. #define YYMAXDEPTH 200
  246. #endif
  247.  
  248. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  249.     (effective only if the built-in stack extension method is used).  */
  250.  
  251. #ifndef YYMAXLIMIT
  252. #define YYMAXLIMIT 10000
  253. #endif
  254.  
  255.  
  256. int
  257. yyparse()
  258. {
  259.   register int yystate;
  260.   register int yyn;
  261.   register short *yyssp;
  262.   register YYSTYPE *yyvsp;
  263.   YYLTYPE *yylsp;
  264.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  265.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  266.  
  267.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  268.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  269.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  270.  
  271.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  272.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  273.   YYLTYPE *yyls = yylsa;
  274.  
  275.   int yymaxdepth = YYMAXDEPTH;
  276.  
  277. #ifndef YYPURE
  278.   int yychar;
  279.   YYSTYPE yylval;
  280.   YYLTYPE yylloc;
  281. #endif
  282.  
  283. #ifdef YYDEBUG
  284.   extern int yydebug;
  285. #endif
  286.  
  287.  
  288.   YYSTYPE yyval;        /*  the variable used to return        */
  289.                 /*  semantic values from the action    */
  290.                 /*  routines                */
  291.  
  292.   int yylen;
  293.  
  294. #ifdef YYDEBUG
  295.   if (yydebug)
  296.     fprintf(stderr, "Starting parse\n");
  297. #endif
  298.  
  299.   yystate = 0;
  300.   yyerrstatus = 0;
  301.   yynerr = 0;
  302.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  303.  
  304.   /* Initialize stack pointers.
  305.      Waste one element of value and location stack
  306.      so that they stay on the same level as the state stack.  */
  307.  
  308.   yyssp = yyss - 1;
  309.   yyvsp = yyvs;
  310.   yylsp = yyls;
  311.  
  312. /* Push a new state, which is found in  yystate  .  */
  313. /* In all cases, when you get here, the value and location stacks
  314.    have just been pushed. so pushing a state here evens the stacks.  */
  315. yynewstate:
  316.  
  317.   *++yyssp = yystate;
  318.  
  319.   if (yyssp >= yyss + yymaxdepth - 1)
  320.     {
  321.       /* Give user a chance to reallocate the stack */
  322.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  323.       YYSTYPE *yyvs1 = yyvs;
  324.       YYLTYPE *yyls1 = yyls;
  325.       short *yyss1 = yyss;
  326.  
  327.       /* Get the current used size of the three stacks, in elements.  */
  328.       int size = yyssp - yyss + 1;
  329.  
  330. #ifdef yyoverflow
  331.       /* Each stack pointer address is followed by the size of
  332.      the data in use in that stack, in bytes.  */
  333.       yyoverflow("parser stack overflow",
  334.          &yyss1, size * sizeof (*yyssp),
  335.          &yyvs1, size * sizeof (*yyvsp),
  336.          &yyls1, size * sizeof (*yylsp),
  337.          &yymaxdepth);
  338.  
  339.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  340. #else /* no yyoverflow */
  341.       /* Extend the stack our own way.  */
  342.       if (yymaxdepth >= YYMAXLIMIT)
  343.     yyerror("parser stack overflow");
  344.       yymaxdepth *= 2;
  345.       if (yymaxdepth > YYMAXLIMIT)
  346.     yymaxdepth = YYMAXLIMIT;
  347.       yyss = (short *) malloc (yymaxdepth * sizeof (*yyssp));
  348.       memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
  349.       yyvs = (YYSTYPE *) malloc (yymaxdepth * sizeof (*yyvsp));
  350.       memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
  351. #ifdef YYLSP_NEEDED
  352.       yyls = (YYLTYPE *) malloc (yymaxdepth * sizeof (*yylsp));
  353.       memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
  354. #endif
  355. #endif /* no yyoverflow */
  356.  
  357.       yyssp = yyss + size - 1;
  358.       yyvsp = yyvs + size - 1;
  359. #ifdef YYLSP_NEEDED
  360.       yylsp = yyls + size - 1;
  361. #endif
  362.  
  363. #ifdef YYDEBUG
  364.       if (yydebug)
  365.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  366. #endif
  367.  
  368.       if (yyssp >= yyss + yymaxdepth - 1)
  369.     YYABORT;
  370.     }
  371.  
  372. #ifdef YYDEBUG
  373.   if (yydebug)
  374.     fprintf(stderr, "Entering state %d\n", yystate);
  375. #endif
  376.  
  377. /* Do appropriate processing given the current state.  */
  378. /* Read a lookahead token if we need one and don't already have one.  */
  379. yyresume:
  380.  
  381.   /* First try to decide what to do without reference to lookahead token.  */
  382.  
  383.   yyn = yypact[yystate];
  384.   if (yyn == YYFLAG)
  385.     goto yydefault;
  386.  
  387.   /* Not known => get a lookahead token if don't already have one.  */
  388.  
  389.   /* yychar is either YYEMPTY or YYEOF
  390.      or a valid token in external form.  */
  391.  
  392.   if (yychar == YYEMPTY)
  393.     {
  394. #ifdef YYDEBUG
  395.       if (yydebug)
  396.     fprintf(stderr, "Reading a token: ");
  397. #endif
  398.       yychar = YYLEX;
  399.     }
  400.  
  401.   /* Convert token to internal form (in yychar1) for indexing tables with */
  402.  
  403.   if (yychar <= 0)        /* This means end of input. */
  404.     {
  405.       yychar1 = 0;
  406.       yychar = YYEOF;        /* Don't call YYLEX any more */
  407.  
  408. #ifdef YYDEBUG
  409.       if (yydebug)
  410.     fprintf(stderr, "Now at end of input.\n");
  411. #endif
  412.     }
  413.   else
  414.     {
  415.       yychar1 = YYTRANSLATE(yychar);
  416.  
  417. #ifdef YYDEBUG
  418.       if (yydebug)
  419.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  420. #endif
  421.     }
  422.  
  423.   yyn += yychar1;
  424.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  425.     goto yydefault;
  426.  
  427.   yyn = yytable[yyn];
  428.  
  429.   /* yyn is what to do for this token type in this state.
  430.      Negative => reduce, -yyn is rule number.
  431.      Positive => shift, yyn is new state.
  432.        New state is final state => don't bother to shift,
  433.        just return success.
  434.      0, or most negative number => error.  */
  435.  
  436.   if (yyn < 0)
  437.     {
  438.       if (yyn == YYFLAG)
  439.     goto yyerrlab;
  440.       yyn = -yyn;
  441.       goto yyreduce;
  442.     }
  443.   else if (yyn == 0)
  444.     goto yyerrlab;
  445.  
  446.   if (yyn == YYFINAL)
  447.     YYACCEPT;
  448.  
  449.   /* Shift the lookahead token.  */
  450.  
  451. #ifdef YYDEBUG
  452.   if (yydebug)
  453.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  454. #endif
  455.  
  456.   /* Discard the token being shifted unless it is eof.  */
  457.   if (yychar != YYEOF)
  458.     yychar = YYEMPTY;
  459.  
  460.   *++yyvsp = yylval;
  461. #ifdef YYLSP_NEEDED
  462.   *++yylsp = yylloc;
  463. #endif
  464.  
  465.   /* count tokens shifted since error; after three, turn off error status.  */
  466.   if (yyerrstatus) yyerrstatus--;
  467.  
  468.   yystate = yyn;
  469.   goto yynewstate;
  470.  
  471. /* Do the default action for the current state.  */
  472. yydefault:
  473.  
  474.   yyn = yydefact[yystate];
  475.   if (yyn == 0)
  476.     goto yyerrlab;
  477.  
  478. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  479. yyreduce:
  480.   yylen = yyr2[yyn];
  481.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  482.  
  483. #ifdef YYDEBUG
  484.   if (yydebug)
  485.     {
  486.       if (yylen == 1)
  487.     fprintf (stderr, "Reducing 1 value via line %d, ",
  488.          yyrline[yyn]);
  489.       else
  490.     fprintf (stderr, "Reducing %d values via line %d, ",
  491.          yylen, yyrline[yyn]);
  492.     }
  493. #endif
  494.  
  495.    /* the action file gets copied in in place of this dollarsign */
  496.  
  497.   switch (yyn) {
  498.  
  499. case 1:
  500. { /* add default rule */
  501.             int def_rule;
  502.  
  503.             pat = cclinit();
  504.             cclnegate( pat );
  505.  
  506.             def_rule = mkstate( -pat );
  507.  
  508.             add_accept( def_rule, 0, 0 );
  509.  
  510.             for ( i = 1; i <= lastsc; ++i )
  511.                 scset[i] = mkbranch( scset[i], def_rule );
  512.  
  513.             fputs( "YY_DEFAULT_ACTION;\n\tYY_BREAK\n",
  514.                    temp_action_file );
  515.             ;
  516.     break;}
  517. case 2:
  518. {
  519.             /* initialize for processing rules */
  520.  
  521.             /* create default DFA start condition */
  522.             scinstal( "INITIAL", false );
  523.             ;
  524.     break;}
  525. case 5:
  526. { synerr( "unknown error processing section 1" ); ;
  527.     break;}
  528. case 7:
  529. {
  530.             /* these productions are separate from the s1object
  531.              * rule because the semantics must be done before
  532.              * we parse the remainder of an s1object
  533.              */
  534.  
  535.             xcluflg = false;
  536.             ;
  537.     break;}
  538. case 8:
  539. { xcluflg = true; ;
  540.     break;}
  541. case 9:
  542. { scinstal( nmstr, xcluflg ); ;
  543.     break;}
  544. case 10:
  545. { scinstal( nmstr, xcluflg ); ;
  546.     break;}
  547. case 11:
  548. { synerr( "bad start condition list" ); ;
  549.     break;}
  550. case 14:
  551. {
  552.             /* initialize for a parse of one rule */
  553.             trlcontxt = varlength = false;
  554.             trailcnt = headcnt = rulelen = 0;
  555.             ;
  556.     break;}
  557. case 15:
  558. {
  559.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  560.             add_accept( pat, headcnt, trailcnt );
  561.  
  562.             for ( i = 1; i <= actvp; ++i )
  563.                 scbol[actvsc[i]] = mkbranch( scbol[actvsc[i]], pat );
  564.             ;
  565.     break;}
  566. case 16:
  567. {
  568.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  569.             add_accept( pat, headcnt, trailcnt );
  570.  
  571.             for ( i = 1; i <= actvp; ++i )
  572.                 scset[actvsc[i]] = mkbranch( scset[actvsc[i]], pat );
  573.             ;
  574.     break;}
  575. case 17:
  576. {
  577.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  578.             add_accept( pat, headcnt, trailcnt );
  579.  
  580.             /* add to all non-exclusive start conditions,
  581.              * including the default (0) start condition
  582.              */
  583.  
  584.             for ( i = 1; i <= lastsc; ++i )
  585.                 if ( ! scxclu[i] )
  586.                 scbol[i] = mkbranch( scbol[i], pat );
  587.             ;
  588.     break;}
  589. case 18:
  590. {
  591.             pat = link_machines( yyvsp[-1], yyvsp[0] );
  592.             add_accept( pat, headcnt, trailcnt );
  593.  
  594.             for ( i = 1; i <= lastsc; ++i )
  595.                 if ( ! scxclu[i] )
  596.                 scset[i] = mkbranch( scset[i], pat );
  597.             ;
  598.     break;}
  599. case 19:
  600. { synerr( "unrecognized rule" ); ;
  601.     break;}
  602. case 21:
  603. {
  604.             if ( (scnum = sclookup( nmstr )) == 0 )
  605.                 synerr( "undeclared start condition" );
  606.  
  607.             else
  608.                 actvsc[++actvp] = scnum;
  609.             ;
  610.     break;}
  611. case 22:
  612. {
  613.             if ( (scnum = sclookup( nmstr )) == 0 )
  614.                 synerr( "undeclared start condition" );
  615.             else
  616.                 actvsc[actvp = 1] = scnum;
  617.             ;
  618.     break;}
  619. case 23:
  620. { synerr( "bad start condition list" ); ;
  621.     break;}
  622. case 24:
  623. {
  624.             if ( trlcontxt )
  625.                 {
  626.                 synerr( "trailing context used twice" );
  627.                 yyval = mkstate( SYM_EPSILON );
  628.                 }
  629.             else
  630.                 {
  631.                 trlcontxt = true;
  632.  
  633.                 if ( ! varlength )
  634.                 headcnt = rulelen;
  635.  
  636.                 ++rulelen;
  637.                 trailcnt = 1;
  638.  
  639.                 eps = mkstate( SYM_EPSILON );
  640.                 yyval = link_machines( eps, mkstate( '\n' ) );
  641.                 }
  642.             ;
  643.     break;}
  644. case 25:
  645. {
  646.                 yyval = mkstate( SYM_EPSILON );
  647.  
  648.             if ( trlcontxt )
  649.                 {
  650.                 if ( varlength && headcnt == 0 )
  651.                 /* both head and trail are variable-length */
  652.                 synerr( "illegal trailing context" );
  653.  
  654.                 else
  655.                 trailcnt = rulelen;
  656.                 }
  657.                 ;
  658.     break;}
  659. case 26:
  660. {
  661.             varlength = true;
  662.  
  663.             yyval = mkor( yyvsp[-2], yyvsp[0] );
  664.             ;
  665.     break;}
  666. case 27:
  667. { yyval = link_machines( yyvsp[-1], yyvsp[0] ); ;
  668.     break;}
  669. case 28:
  670. { yyval = yyvsp[0]; ;
  671.     break;}
  672. case 29:
  673. {
  674.             /* this rule is separate from the others for "re" so
  675.              * that the reduction will occur before the trailing
  676.              * series is parsed
  677.              */
  678.  
  679.             if ( trlcontxt )
  680.                 synerr( "trailing context used twice" );
  681.             else
  682.                 trlcontxt = true;
  683.  
  684.             if ( varlength )
  685.                 /* the trailing context had better be fixed-length */
  686.                 varlength = false;
  687.             else
  688.                 headcnt = rulelen;
  689.  
  690.             rulelen = 0;
  691.             yyval = yyvsp[-1];
  692.             ;
  693.     break;}
  694. case 30:
  695. {
  696.             /* this is where concatenation of adjacent patterns
  697.              * gets done
  698.              */
  699.             yyval = link_machines( yyvsp[-1], yyvsp[0] );
  700.             ;
  701.     break;}
  702. case 31:
  703. { yyval = yyvsp[0]; ;
  704.     break;}
  705. case 32:
  706. {
  707.             varlength = true;
  708.  
  709.             yyval = mkclos( yyvsp[-1] );
  710.             ;
  711.     break;}
  712. case 33:
  713. {
  714.             varlength = true;
  715.  
  716.             yyval = mkposcl( yyvsp[-1] );
  717.             ;
  718.     break;}
  719. case 34:
  720. {
  721.             varlength = true;
  722.  
  723.             yyval = mkopt( yyvsp[-1] );
  724.             ;
  725.     break;}
  726. case 35:
  727. {
  728.             varlength = true;
  729.  
  730.             if ( yyvsp[-3] > yyvsp[-1] || yyvsp[-3] <= 0 )
  731.                 {
  732.                 synerr( "bad iteration values" );
  733.                 yyval = yyvsp[-5];
  734.                 }
  735.             else
  736.                 yyval = mkrep( yyvsp[-5], yyvsp[-3], yyvsp[-1] );
  737.             ;
  738.     break;}
  739. case 36:
  740. {
  741.             varlength = true;
  742.  
  743.             if ( yyvsp[-2] <= 0 )
  744.                 {
  745.                 synerr( "iteration value must be positive" );
  746.                 yyval = yyvsp[-4];
  747.                 }
  748.  
  749.             else
  750.                 yyval = mkrep( yyvsp[-4], yyvsp[-2], INFINITY );
  751.             ;
  752.     break;}
  753. case 37:
  754. {
  755.             /* the singleton could be something like "(foo)",
  756.              * in which case we have no idea what its length
  757.              * is, so we punt here.
  758.              */
  759.             varlength = true;
  760.  
  761.             if ( yyvsp[-1] <= 0 )
  762.                 {
  763.                 synerr( "iteration value must be positive" );
  764.                 yyval = yyvsp[-3];
  765.                 }
  766.  
  767.             else
  768.                 yyval = link_machines( yyvsp[-3], copysingl( yyvsp[-3], yyvsp[-1] - 1 ) );
  769.             ;
  770.     break;}
  771. case 38:
  772. {
  773.             if ( ! madeany )
  774.                 {
  775.                 /* create the '.' character class */
  776.                 anyccl = cclinit();
  777.                 ccladd( anyccl, '\n' );
  778.                 cclnegate( anyccl );
  779.  
  780.                 if ( useecs )
  781.                 mkeccl( ccltbl + cclmap[anyccl],
  782.                     ccllen[anyccl], nextecm,
  783.                     ecgroup, CSIZE );
  784.                 
  785.                 madeany = true;
  786.                 }
  787.  
  788.             ++rulelen;
  789.  
  790.             yyval = mkstate( -anyccl );
  791.             ;
  792.     break;}
  793. case 39:
  794. {
  795.             if ( ! cclsorted )
  796.                 /* sort characters for fast searching.  We use a
  797.                  * shell sort since this list could be large.
  798.                  */
  799.                 cshell( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]] );
  800.  
  801.             if ( useecs )
  802.                 mkeccl( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]],
  803.                     nextecm, ecgroup, CSIZE );
  804.                      
  805.             ++rulelen;
  806.  
  807.             yyval = mkstate( -yyvsp[0] );
  808.             ;
  809.     break;}
  810. case 40:
  811. {
  812.             ++rulelen;
  813.  
  814.             yyval = mkstate( -yyvsp[0] );
  815.             ;
  816.     break;}
  817. case 41:
  818. { yyval = yyvsp[-1]; ;
  819.     break;}
  820. case 42:
  821. { yyval = yyvsp[-1]; ;
  822.     break;}
  823. case 43:
  824. {
  825.             ++rulelen;
  826.  
  827.             if ( yyvsp[0] == '\0' )
  828.                 synerr( "null in rule" );
  829.  
  830.             if ( caseins && yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  831.                 yyvsp[0] = clower( yyvsp[0] );
  832.  
  833.             yyval = mkstate( yyvsp[0] );
  834.             ;
  835.     break;}
  836. case 44:
  837. { yyval = yyvsp[-1]; ;
  838.     break;}
  839. case 45:
  840. {
  841.             /* *Sigh* - to be compatible Unix lex, negated ccls
  842.              * match newlines
  843.              */
  844. #ifdef NOTDEF
  845.             ccladd( yyvsp[-1], '\n' ); /* negated ccls don't match '\n' */
  846.             cclsorted = false; /* because we added the newline */
  847. #endif
  848.             cclnegate( yyvsp[-1] );
  849.             yyval = yyvsp[-1];
  850.             ;
  851.     break;}
  852. case 46:
  853. {
  854.             if ( yyvsp[-2] > yyvsp[0] )
  855.                 synerr( "negative range in character class" );
  856.  
  857.             else
  858.                 {
  859.                 if ( caseins )
  860.                 {
  861.                 if ( yyvsp[-2] >= 'A' && yyvsp[-2] <= 'Z' )
  862.                     yyvsp[-2] = clower( yyvsp[-2] );
  863.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  864.                     yyvsp[0] = clower( yyvsp[0] );
  865.                 }
  866.  
  867.                 for ( i = yyvsp[-2]; i <= yyvsp[0]; ++i )
  868.                     ccladd( yyvsp[-3], i );
  869.  
  870.                 /* keep track if this ccl is staying in alphabetical
  871.                  * order
  872.                  */
  873.                 cclsorted = cclsorted && (yyvsp[-2] > lastchar);
  874.                 lastchar = yyvsp[0];
  875.                 }
  876.             
  877.             yyval = yyvsp[-3];
  878.             ;
  879.     break;}
  880. case 47:
  881. {
  882.             if ( caseins )
  883.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  884.                 yyvsp[0] = clower( yyvsp[0] );
  885.  
  886.             ccladd( yyvsp[-1], yyvsp[0] );
  887.             cclsorted = cclsorted && (yyvsp[0] > lastchar);
  888.             lastchar = yyvsp[0];
  889.             yyval = yyvsp[-1];
  890.             ;
  891.     break;}
  892. case 48:
  893. {
  894.             cclsorted = true;
  895.             lastchar = 0;
  896.             yyval = cclinit();
  897.             ;
  898.     break;}
  899. case 49:
  900. {
  901.             if ( caseins )
  902.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  903.                 yyvsp[0] = clower( yyvsp[0] );
  904.  
  905.             ++rulelen;
  906.  
  907.             yyval = link_machines( yyvsp[-1], mkstate( yyvsp[0] ) );
  908.             ;
  909.     break;}
  910. case 50:
  911. { yyval = mkstate( SYM_EPSILON ); ;
  912.     break;}
  913. }
  914.  
  915.   yyvsp -= yylen;
  916.   yyssp -= yylen;
  917. #ifdef YYLSP_NEEDED
  918.   yylsp -= yylen;
  919. #endif
  920.  
  921. #ifdef YYDEBUG
  922.   if (yydebug)
  923.     {
  924.       short *ssp1 = yyss - 1;
  925.       fprintf (stderr, "state stack now");
  926.       while (ssp1 != yyssp)
  927.     fprintf (stderr, " %d", *++ssp1);
  928.       fprintf (stderr, "\n");
  929.     }
  930. #endif
  931.  
  932.   *++yyvsp = yyval;
  933.  
  934. #ifdef YYLSP_NEEDED
  935.   yylsp++;
  936.   if (yylen == 0)
  937.     {
  938.       yylsp->first_line = yylloc.first_line;
  939.       yylsp->first_column = yylloc.first_column;
  940.       yylsp->last_line = (yylsp-1)->last_line;
  941.       yylsp->last_column = (yylsp-1)->last_column;
  942.       yylsp->text = 0;
  943.     }
  944.   else
  945.     {
  946.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  947.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  948.     }
  949. #endif
  950.  
  951.   /* Now "shift" the result of the reduction.
  952.      Determine what state that goes to,
  953.      based on the state we popped back to
  954.      and the rule number reduced by.  */
  955.  
  956.   yyn = yyr1[yyn];
  957.  
  958.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  959.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  960.     yystate = yytable[yystate];
  961.   else
  962.     yystate = yydefgoto[yyn - YYNTBASE];
  963.  
  964.   goto yynewstate;
  965.  
  966. yyerrlab:   /* here on detecting error */
  967.  
  968.   if (! yyerrstatus)
  969.     /* If not already recovering from an error, report this error.  */
  970.     {
  971.       ++yynerr;
  972.       yyerror("parse error");
  973.     }
  974.  
  975.   if (yyerrstatus == 3)
  976.     {
  977.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  978.  
  979.       /* return failure if at end of input */
  980.       if (yychar == YYEOF)
  981.     YYABORT;
  982.  
  983. #ifdef YYDEBUG
  984.       if (yydebug)
  985.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  986. #endif
  987.  
  988.       yychar = YYEMPTY;
  989.     }
  990.  
  991.   /* Else will try to reuse lookahead token
  992.      after shifting the error token.  */
  993.  
  994.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  995.  
  996.   goto yyerrhandle;
  997.  
  998. yyerrdefault:  /* current state does not do anything special for the error token. */
  999.  
  1000. #if 0
  1001.   /* This is wrong; only states that explicitly want error tokens
  1002.      should shift them.  */
  1003.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1004.   if (yyn) goto yydefault;
  1005. #endif
  1006.  
  1007. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1008.  
  1009.   if (yyssp == yyss) YYABORT;
  1010.   yyvsp--;
  1011.   yystate = *--yyssp;
  1012. #ifdef YYLSP_NEEDED
  1013.   yylsp--;
  1014. #endif
  1015.  
  1016. #ifdef YYDEBUG
  1017.   if (yydebug)
  1018.     {
  1019.       short *ssp1 = yyss - 1;
  1020.       fprintf (stderr, "Error: state stack now");
  1021.       while (ssp1 != yyssp)
  1022.     fprintf (stderr, " %d", *++ssp1);
  1023.       fprintf (stderr, "\n");
  1024.     }
  1025. #endif
  1026.  
  1027. yyerrhandle:
  1028.  
  1029.   yyn = yypact[yystate];
  1030.   if (yyn == YYFLAG)
  1031.     goto yyerrdefault;
  1032.  
  1033.   yyn += YYTERROR;
  1034.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1035.     goto yyerrdefault;
  1036.  
  1037.   yyn = yytable[yyn];
  1038.   if (yyn < 0)
  1039.     {
  1040.       if (yyn == YYFLAG)
  1041.     goto yyerrpop;
  1042.       yyn = -yyn;
  1043.       goto yyreduce;
  1044.     }
  1045.   else if (yyn == 0)
  1046.     goto yyerrpop;
  1047.  
  1048.   if (yyn == YYFINAL)
  1049.     YYACCEPT;
  1050.  
  1051. #ifdef YYDEBUG
  1052.   if (yydebug)
  1053.     fprintf(stderr, "Shifting error token, ");
  1054. #endif
  1055.  
  1056.   *++yyvsp = yylval;
  1057. #ifdef YYLSP_NEEDED
  1058.   *++yylsp = yylloc;
  1059. #endif
  1060.  
  1061.   yystate = yyn;
  1062.   goto yynewstate;
  1063. }
  1064.  
  1065.  
  1066.  
  1067. /*
  1068. **    function:    synerr
  1069. **    purpose:    Report a syntax error
  1070. **    mods:        1989.12.30 - Roberto Artigas Jr
  1071. **            Changed return type to void
  1072. */
  1073. void
  1074. synerr( str )
  1075. char str[];                /* Error message */
  1076. {
  1077.   syntaxerror = true;            /* We have an error! */
  1078.   fprintf(stderr,            /* Error file */
  1079.     "Syntax error at line %d: %s\n",    /* Message text */
  1080.     linenum,                /* Line number */
  1081.     str);                /* Error message */
  1082. };                    /* synerr */
  1083.  
  1084.  
  1085. /*
  1086. **    function:    yyerror
  1087. **    purpose:    Eat up an error message from the parser
  1088. **    mods:        1989.12.30 - Roberto Artigas Jr
  1089. **            Changed return type to void
  1090. */
  1091. void
  1092. yyerror( msg )
  1093. char msg[];                /* Error message */
  1094. {
  1095. };                    /* yyerror */
  1096.