home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / rail.zip / GRAM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-15  |  20.3 KB  |  792 lines

  1. extern char *malloc(), *realloc();
  2.  
  3. # line 4 "gram.y"
  4.  
  5. #include <stdio.h>
  6.  
  7. #include "rail.h"
  8.  
  9. char optchar;
  10.  
  11. # define IDENTIFIER 257
  12. # define NUMBER 258
  13. # define ANNOT 259
  14. # define RAILI 260
  15. # define RAILP 261
  16. # define RAILT 262
  17. # define RAILCR 263
  18. # define CS 264
  19. # define STRING 265
  20. #define yyclearin yychar = -1
  21. #define yyerrok yyerrflag = 0
  22. extern int yychar;
  23. extern int yyerrflag;
  24. #ifndef YYMAXDEPTH
  25. #define YYMAXDEPTH 150
  26. #endif
  27. YYSTYPE yylval, yyval;
  28. # define YYERRCODE 256
  29.  
  30. # line 223 "gram.y"
  31.  
  32.  
  33. int yyexca[] ={
  34. -1, 1,
  35.     0, -1,
  36.     -2, 0,
  37. -1, 25,
  38.     125, 43,
  39.     59, 43,
  40.     124, 43,
  41.     -2, 0,
  42. -1, 43,
  43.     124, 43,
  44.     -2, 17,
  45.     };
  46. # define YYNPROD 46
  47. # define YYLAST 246
  48. int yyact[]={
  49.  
  50.     39,    44,    50,    51,    23,    39,    22,     6,    46,    16,
  51.     39,     3,     4,     5,    14,    39,    43,    64,    19,    39,
  52.     39,    17,    47,    25,    13,    11,     9,    53,    33,    37,
  53.     30,    27,    38,    60,    31,    36,    45,     2,    57,     7,
  54.     20,    18,    15,    12,    10,     8,     1,    34,    35,    26,
  55.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  56.      0,    48,     0,     0,     0,     0,     0,     0,     0,     0,
  57.     52,     0,     0,     0,    54,    56,    59,    55,     0,     0,
  58.     62,    62,    42,    61,    61,    63,    21,    66,    65,     0,
  59.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  60.     47,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  61.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  62.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  63.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  64.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  65.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  66.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  67.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  68.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  69.      0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
  70.      0,     0,    46,     0,     0,     0,     0,     0,     0,     0,
  71.      0,     0,     0,     0,     0,     0,     0,    49,    24,     0,
  72.      0,    28,    29,    41,    32,    40,     0,    49,    41,    32,
  73.     40,     0,    49,    41,    58,    40,    49,    29,    41,    32,
  74.     40,     0,    41,    41,    40,    40 };
  75. int yypact[]={
  76.  
  77.   -249,  -249, -1000,   -97,   -98,   -99, -1000, -1000, -1000,  -244,
  78.  -1000, -1000, -1000,  -248,  -104, -1000,  -107, -1000,   -39, -1000,
  79.   -100, -1000, -1000, -1000, -1000,   -35,   -43, -1000, -1000,   -57,
  80.  -1000,  -102,   -21, -1000,   -40, -1000, -1000, -1000,   -36,   -30,
  81.   -251, -1000, -1000,   -20, -1000, -1000, -1000,   -25, -1000,  -251,
  82.    -21,   -21, -1000, -1000,   -24, -1000, -1000,   -30,   -21, -1000,
  83.  -1000, -1000, -1000, -1000, -1000, -1000, -1000 };
  84. int yypgo[]={
  85.  
  86.      0,    31,    49,    30,    34,    28,    48,    47,    35,    33,
  87.     32,    29,    36,    46,    37,    45,    44,    43,    42,    41,
  88.     40,    38 };
  89. int yyr1[]={
  90.  
  91.      0,    13,    13,    14,    14,    14,    14,    18,    16,    19,
  92.     19,    19,    19,    17,    20,    15,     2,     2,     2,     2,
  93.     21,     1,     1,     3,     4,     4,     4,     4,     5,     5,
  94.      5,     6,     6,     7,     7,     8,     8,     9,     9,    10,
  95.     10,    10,    10,    11,    12,    12 };
  96. int yyr2[]={
  97.  
  98.      0,     4,     2,     4,     4,     4,     2,     1,     9,     0,
  99.      5,     5,     5,     7,     1,    15,     7,     5,     2,     3,
  100.      1,     9,     3,     3,     9,     7,     5,     2,     7,     7,
  101.      2,     2,     2,     5,     2,     5,     2,     2,     2,     7,
  102.      5,     5,     3,     1,     3,     1 };
  103. int yychk[]={
  104.  
  105.  -1000,   -13,   -14,   260,   261,   262,   256,   -14,   -15,   123,
  106.    -16,   123,   -17,   123,   258,   -18,   257,   125,   -19,   125,
  107.    -20,   125,    45,    43,   257,   123,    -2,    -1,   256,   257,
  108.     -3,    -4,   259,    -5,    -7,    -6,    -8,   -11,   -10,    40,
  109.    265,   263,   125,    59,    58,   -12,   259,   124,    -5,   257,
  110.     42,    43,    -8,    63,    -4,   -12,    -1,   -21,   259,    -5,
  111.     -9,   -10,   -11,    -9,    41,    -3,    -5 };
  112. int yydef[]={
  113.  
  114.      0,    -2,     2,     0,     0,     0,     6,     1,     3,     0,
  115.      4,     7,     5,     0,     0,     9,     0,    14,     0,    13,
  116.      0,     8,    10,    11,    12,    -2,     0,    18,    19,    45,
  117.     22,    23,    43,    27,    31,    30,    34,    32,    36,    43,
  118.     45,    42,    15,    -2,    20,    41,    44,    43,    26,    45,
  119.     43,    43,    33,    35,     0,    40,    16,    43,    43,    25,
  120.     28,    37,    38,    29,    39,    21,    24 };
  121. typedef struct { char *t_name; int t_val; } yytoktype;
  122. #ifndef YYDEBUG
  123. #    define YYDEBUG    0    /* don't allow debugging */
  124. #endif
  125.  
  126. #if YYDEBUG
  127.  
  128. yytoktype yytoks[] =
  129. {
  130.     "IDENTIFIER",    257,
  131.     "NUMBER",    258,
  132.     "ANNOT",    259,
  133.     "RAILI",    260,
  134.     "RAILP",    261,
  135.     "RAILT",    262,
  136.     "RAILCR",    263,
  137.     "CS",    264,
  138.     "STRING",    265,
  139.     "-unknown-",    -1    /* ends search */
  140. };
  141.  
  142. char * yyreds[] =
  143. {
  144.     "-no such reduction-",
  145.     "rails : rails rail",
  146.     "rails : rail",
  147.     "rail : RAILI raili",
  148.     "rail : RAILP railp",
  149.     "rail : RAILT railt",
  150.     "rail : error",
  151.     "railp : '{'",
  152.     "railp : '{' options '}'",
  153.     "options : /* empty */",
  154.     "options : options '-'",
  155.     "options : options '+'",
  156.     "options : options IDENTIFIER",
  157.     "railt : '{' IDENTIFIER '}'",
  158.     "raili : '{' NUMBER '}'",
  159.     "raili : '{' NUMBER '}' '{' rules '}'",
  160.     "rules : rules ';' rule",
  161.     "rules : rules ';'",
  162.     "rules : rule",
  163.     "rules : error",
  164.     "rule : IDENTIFIER ':'",
  165.     "rule : IDENTIFIER ':' body",
  166.     "rule : body",
  167.     "body : body0",
  168.     "body0 : body0 '|' ANNOT body1",
  169.     "body0 : body0 '|' body1",
  170.     "body0 : ANNOT body1",
  171.     "body0 : body1",
  172.     "body1 : body2 '*' body4e",
  173.     "body1 : body2 '+' body4e",
  174.     "body1 : body2e",
  175.     "body2e : body2",
  176.     "body2e : empty",
  177.     "body2 : body2 body3",
  178.     "body2 : body3",
  179.     "body3 : body4 '?'",
  180.     "body3 : body4",
  181.     "body4e : body4",
  182.     "body4e : empty",
  183.     "body4 : '(' body0 ')'",
  184.     "body4 : STRING annot",
  185.     "body4 : IDENTIFIER annot",
  186.     "body4 : RAILCR",
  187.     "empty : /* empty */",
  188.     "annot : ANNOT",
  189.     "annot : /* empty */",
  190. };
  191. #endif /* YYDEBUG */
  192. #line 1 "/usr/lib/yaccpar"
  193. /*    @(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10    */
  194.  
  195. /*
  196. ** Skeleton parser driver for yacc output
  197. */
  198.  
  199. /*
  200. ** yacc user known macros and defines
  201. */
  202. #define YYERROR        goto yyerrlab
  203. #define YYACCEPT    { free(yys); free(yyv); return(0); }
  204. #define YYABORT        { free(yys); free(yyv); return(1); }
  205. #define YYBACKUP( newtoken, newvalue )\
  206. {\
  207.     if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  208.     {\
  209.         yyerror( "syntax error - cannot backup" );\
  210.         goto yyerrlab;\
  211.     }\
  212.     yychar = newtoken;\
  213.     yystate = *yyps;\
  214.     yylval = newvalue;\
  215.     goto yynewstate;\
  216. }
  217. #define YYRECOVERING()    (!!yyerrflag)
  218. #ifndef YYDEBUG
  219. #    define YYDEBUG    1    /* make debugging available */
  220. #endif
  221.  
  222. /*
  223. ** user known globals
  224. */
  225. int yydebug;            /* set to 1 to get debugging */
  226.  
  227. /*
  228. ** driver internal defines
  229. */
  230. #define YYFLAG        (-1000)
  231.  
  232. /*
  233. ** static variables used by the parser
  234. */
  235. static YYSTYPE *yyv;            /* value stack */
  236. static int *yys;            /* state stack */
  237.  
  238. static YYSTYPE *yypv;            /* top of value stack */
  239. static int *yyps;            /* top of state stack */
  240.  
  241. static int yystate;            /* current state */
  242. static int yytmp;            /* extra var (lasts between blocks) */
  243.  
  244. int yynerrs;            /* number of errors */
  245.  
  246. int yyerrflag;            /* error recovery flag */
  247. int yychar;            /* current input token number */
  248.  
  249. /* register YYSTYPE *yypvt = 0;    /* top of value stack for $vars */
  250.  
  251. /*
  252. ** yyparse - return 0 if worked, 1 if syntax error not recovered from
  253. */
  254. int
  255. yyparse()
  256. {
  257.     register YYSTYPE *yypvt = 0;    /**/
  258.     unsigned yymaxdepth = YYMAXDEPTH;
  259.  
  260.     /*
  261.     ** Initialize externals - yyparse may be called more than once
  262.     */
  263.     yyv = (YYSTYPE*)malloc(yymaxdepth*sizeof(YYSTYPE));
  264.     yys = (int*)malloc(yymaxdepth*sizeof(int));
  265.     if (!yyv || !yys)
  266.     {
  267.         yyerror( "out of memory" );
  268.         return(1);
  269.     }
  270.     yypv = &yyv[-1];
  271.     yyps = &yys[-1];
  272.     yystate = 0;
  273.     yytmp = 0;
  274.     yynerrs = 0;
  275.     yyerrflag = 0;
  276.     yychar = -1;
  277.  
  278.     goto yystack;
  279.     yynewstate:
  280.     {
  281.         register YYSTYPE *yy_pv;    /* top of value stack */
  282.         register int *yy_ps;        /* top of state stack */
  283.         register int yy_state;        /* current state */
  284.         register int  yy_n;        /* internal state number info */
  285.  
  286.         /*
  287.         ** get globals into registers.
  288.         ** branch to here only if YYBACKUP was called.
  289.         */
  290.         yy_pv = yypv;
  291.         yy_ps = yyps;
  292.         yy_state = yystate;
  293.         goto yy_newstate;
  294.  
  295.         /*
  296.         ** get globals into registers.
  297.         ** either we just started, or we just finished a reduction
  298.         */
  299.     yystack:
  300.         yy_pv = yypv;
  301.         yy_ps = yyps;
  302.         yy_state = yystate;
  303.  
  304.         /*
  305.         ** top of for (;;) loop while no reductions done
  306.         */
  307.     yy_stack:
  308.         /*
  309.         ** put a state and value onto the stacks
  310.         */
  311. #if YYDEBUG
  312.         /*
  313.         ** if debugging, look up token value in list of value vs.
  314.         ** name pairs.  0 and negative (-1) are special values.
  315.         ** Note: linear search is used since time is not a real
  316.         ** consideration while debugging.
  317.         */
  318.         if ( yydebug )
  319.         {
  320.             register int yy_i;
  321.  
  322.             (void)printf( "State %d, token ", yy_state );
  323.             if ( yychar == 0 )
  324.                 (void)printf( "end-of-file\n" );
  325.             else if ( yychar < 0 )
  326.                 (void)printf( "-none-\n" );
  327.             else
  328.             {
  329.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  330.                     yy_i++ )
  331.                 {
  332.                     if ( yytoks[yy_i].t_val == yychar )
  333.                         break;
  334.                 }
  335.                 (void)printf( "%s\n", yytoks[yy_i].t_name );
  336.             }
  337.         }
  338. #endif /* YYDEBUG */
  339.         if ( ++yy_ps >= &yys[ yymaxdepth ] )    /* room on stack? */
  340.         {
  341.             /*
  342.             ** reallocate and recover.  Note that pointers
  343.             ** have to be reset, or bad things will happen
  344.             */
  345.             int yyps_index = (yy_ps - yys);
  346.             int yypv_index = (yy_pv - yyv);
  347.             int yypvt_index = (yypvt - yyv);
  348.             yymaxdepth += YYMAXDEPTH;
  349.             yyv = (YYSTYPE*)realloc((char*)yyv,
  350.                 yymaxdepth * sizeof(YYSTYPE));
  351.             yys = (int*)realloc((char*)yys,
  352.                 yymaxdepth * sizeof(int));
  353.             if (!yyv || !yys)
  354.             {
  355.                 yyerror( "yacc stack overflow" );
  356.                 return(1);
  357.             }
  358.             yy_ps = yys + yyps_index;
  359.             yy_pv = yyv + yypv_index;
  360.             yypvt = yyv + yypvt_index;
  361.         }
  362.         *yy_ps = yy_state;
  363.         *++yy_pv = yyval;
  364.  
  365.         /*
  366.         ** we have a new state - find out what to do
  367.         */
  368.     yy_newstate:
  369.         if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  370.             goto yydefault;        /* simple state */
  371. #if YYDEBUG
  372.         /*
  373.         ** if debugging, need to mark whether new token grabbed
  374.         */
  375.         yytmp = yychar < 0;
  376. #endif
  377.         if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  378.             yychar = 0;        /* reached EOF */
  379. #if YYDEBUG
  380.         if ( yydebug && yytmp )
  381.         {
  382.             register int yy_i;
  383.  
  384.             (void)printf( "Received token " );
  385.             if ( yychar == 0 )
  386.                 (void)printf( "end-of-file\n" );
  387.             else if ( yychar < 0 )
  388.                 (void)printf( "-none-\n" );
  389.             else
  390.             {
  391.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  392.                     yy_i++ )
  393.                 {
  394.                     if ( yytoks[yy_i].t_val == yychar )
  395.                         break;
  396.                 }
  397.                 (void)printf( "%s\n", yytoks[yy_i].t_name );
  398.             }
  399.         }
  400. #endif /* YYDEBUG */
  401.         if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  402.             goto yydefault;
  403.         if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )    /*valid shift*/
  404.         {
  405.             yychar = -1;
  406.             yyval = yylval;
  407.             yy_state = yy_n;
  408.             if ( yyerrflag > 0 )
  409.                 yyerrflag--;
  410.             goto yy_stack;
  411.         }
  412.  
  413.     yydefault:
  414.         if ( ( yy_n = yydef[ yy_state ] ) == -2 )
  415.         {
  416. #if YYDEBUG
  417.             yytmp = yychar < 0;
  418. #endif
  419.             if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  420.                 yychar = 0;        /* reached EOF */
  421. #if YYDEBUG
  422.             if ( yydebug && yytmp )
  423.             {
  424.                 register int yy_i;
  425.  
  426.                 (void)printf( "Received token " );
  427.                 if ( yychar == 0 )
  428.                     (void)printf( "end-of-file\n" );
  429.                 else if ( yychar < 0 )
  430.                     (void)printf( "-none-\n" );
  431.                 else
  432.                 {
  433.                     for ( yy_i = 0;
  434.                         yytoks[yy_i].t_val >= 0;
  435.                         yy_i++ )
  436.                     {
  437.                         if ( yytoks[yy_i].t_val
  438.                             == yychar )
  439.                         {
  440.                             break;
  441.                         }
  442.                     }
  443.                     (void)printf( "%s\n", yytoks[yy_i].t_name );
  444.                 }
  445.             }
  446. #endif /* YYDEBUG */
  447.             /*
  448.             ** look through exception table
  449.             */
  450.             {
  451.                 register int *yyxi = yyexca;
  452.  
  453.                 while ( ( *yyxi != -1 ) ||
  454.                     ( yyxi[1] != yy_state ) )
  455.                 {
  456.                     yyxi += 2;
  457.                 }
  458.                 while ( ( *(yyxi += 2) >= 0 ) &&
  459.                     ( *yyxi != yychar ) )
  460.                     ;
  461.                 if ( ( yy_n = yyxi[1] ) < 0 )
  462.                     YYACCEPT;
  463.             }
  464.         }
  465.  
  466.         /*
  467.         ** check for syntax error
  468.         */
  469.         if ( yy_n == 0 )    /* have an error */
  470.         {
  471.             /* no worry about speed here! */
  472.             switch ( yyerrflag )
  473.             {
  474.             case 0:        /* new error */
  475.                 yyerror( "syntax error" );
  476.                 goto skip_init;
  477.             yyerrlab:
  478.                 /*
  479.                 ** get globals into registers.
  480.                 ** we have a user generated syntax type error
  481.                 */
  482.                 yy_pv = yypv;
  483.                 yy_ps = yyps;
  484.                 yy_state = yystate;
  485.                 yynerrs++;
  486.             skip_init:
  487.             case 1:
  488.             case 2:        /* incompletely recovered error */
  489.                     /* try again... */
  490.                 yyerrflag = 3;
  491.                 /*
  492.                 ** find state where "error" is a legal
  493.                 ** shift action
  494.                 */
  495.                 while ( yy_ps >= yys )
  496.                 {
  497.                     yy_n = yypact[ *yy_ps ] + YYERRCODE;
  498.                     if ( yy_n >= 0 && yy_n < YYLAST &&
  499.                         yychk[yyact[yy_n]] == YYERRCODE)                    {
  500.                         /*
  501.                         ** simulate shift of "error"
  502.                         */
  503.                         yy_state = yyact[ yy_n ];
  504.                         goto yy_stack;
  505.                     }
  506.                     /*
  507.                     ** current state has no shift on
  508.                     ** "error", pop stack
  509.                     */
  510. #if YYDEBUG
  511. #    define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  512.                     if ( yydebug )
  513.                         (void)printf( _POP_, *yy_ps,
  514.                             yy_ps[-1] );
  515. #    undef _POP_
  516. #endif
  517.                     yy_ps--;
  518.                     yy_pv--;
  519.                 }
  520.                 /*
  521.                 ** there is no state on stack with "error" as
  522.                 ** a valid shift.  give up.
  523.                 */
  524.                 YYABORT;
  525.             case 3:        /* no shift yet; eat a token */
  526. #if YYDEBUG
  527.                 /*
  528.                 ** if debugging, look up token in list of
  529.                 ** pairs.  0 and negative shouldn't occur,
  530.                 ** but since timing doesn't matter when
  531.                 ** debugging, it doesn't hurt to leave the
  532.                 ** tests here.
  533.                 */
  534.                 if ( yydebug )
  535.                 {
  536.                     register int yy_i;
  537.  
  538.                     (void)printf( "Error recovery discards " );
  539.                     if ( yychar == 0 )
  540.                         (void)printf( "token end-of-file\n" );
  541.                     else if ( yychar < 0 )
  542.                         (void)printf( "token -none-\n" );
  543.                     else
  544.                     {
  545.                         for ( yy_i = 0;
  546.                             yytoks[yy_i].t_val >= 0;
  547.                             yy_i++ )
  548.                         {
  549.                             if ( yytoks[yy_i].t_val
  550.                                 == yychar )
  551.                             {
  552.                                 break;
  553.                             }
  554.                         }
  555.                         (void)printf( "token %s\n",
  556.                             yytoks[yy_i].t_name );
  557.                     }
  558.                 }
  559. #endif /* YYDEBUG */
  560.                 if ( yychar == 0 )    /* reached EOF. quit */
  561.                     YYABORT;
  562.                 yychar = -1;
  563.                 goto yy_newstate;
  564.             }
  565.         }/* end if ( yy_n == 0 ) */
  566.         /*
  567.         ** reduction by production yy_n
  568.         ** put stack tops, etc. so things right after switch
  569.         */
  570. #if YYDEBUG
  571.         /*
  572.         ** if debugging, print the string that is the user's
  573.         ** specification of the reduction which is just about
  574.         ** to be done.
  575.         */
  576.         if ( yydebug )
  577.             (void)printf( "Reduce by (%d) \"%s\"\n",
  578.                 yy_n, yyreds[ yy_n ] );
  579. #endif
  580.         yytmp = yy_n;            /* value to switch over */
  581.         yypvt = yy_pv;            /* $vars top of value stack */
  582.         /*
  583.         ** Look in goto table for next state
  584.         ** Sorry about using yy_state here as temporary
  585.         ** register variable, but why not, if it works...
  586.         ** If yyr2[ yy_n ] doesn't have the low order bit
  587.         ** set, then there is no action to be done for
  588.         ** this reduction.  So, no saving & unsaving of
  589.         ** registers done.  The only difference between the
  590.         ** code just after the if and the body of the if is
  591.         ** the goto yy_stack in the body.  This way the test
  592.         ** can be made before the choice of what to do is needed.
  593.         */
  594.         {
  595.             /* length of production doubled with extra bit */
  596.             register int yy_len = yyr2[ yy_n ];
  597.  
  598.             if ( !( yy_len & 01 ) )
  599.             {
  600.                 yy_len >>= 1;
  601.                 yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  602.                 yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  603.                     *( yy_ps -= yy_len ) + 1;
  604.                 if ( yy_state >= YYLAST ||
  605.                     yychk[ yy_state =
  606.                     yyact[ yy_state ] ] != -yy_n )
  607.                 {
  608.                     yy_state = yyact[ yypgo[ yy_n ] ];
  609.                 }
  610.                 goto yy_stack;
  611.             }
  612.             yy_len >>= 1;
  613.             yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  614.             yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  615.                 *( yy_ps -= yy_len ) + 1;
  616.             if ( yy_state >= YYLAST ||
  617.                 yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
  618.             {
  619.                 yy_state = yyact[ yypgo[ yy_n ] ];
  620.             }
  621.         }
  622.                     /* save until reenter driver code */
  623.         yystate = yy_state;
  624.         yyps = yy_ps;
  625.         yypv = yy_pv;
  626.     }
  627.     /*
  628.     ** code supplied by user is placed in this switch
  629.     */
  630.     switch( yytmp )
  631.     {
  632.         
  633. case 7:
  634. # line 59 "gram.y"
  635. {
  636.             fprintf(outf,"\\rail@p {");
  637.             copy=1;
  638.             optchar = '-'; } break;
  639. case 8:
  640. # line 64 "gram.y"
  641. {
  642.             fprintf(outf,"\n");
  643.             copy=0;
  644.         } break;
  645. case 10:
  646. # line 72 "gram.y"
  647. { optchar = '-'; } break;
  648. case 11:
  649. # line 74 "gram.y"
  650. { optchar = '+'; } break;
  651. case 12:
  652. # line 76 "gram.y"
  653. {
  654.             if(setopt(optchar,yypvt[-0].id->name)==0)
  655.                 error("unknown option",(char *)NULL);
  656.  
  657.             if(yypvt[-0].id->kind==UNKNOWN)
  658.                 delete(yypvt[-0].id);
  659.         } break;
  660. case 13:
  661. # line 86 "gram.y"
  662. {
  663.             if(yypvt[-1].id->kind==UNKNOWN || yypvt[-1].id->kind==TOKEN)
  664.                 yypvt[-1].id->kind=TERM;
  665.             else
  666.                 redef(yypvt[-1].id);
  667.  
  668.             fprintf(outf,"\\rail@t {%s}\n",yypvt[-1].id->name);
  669.         } break;
  670. case 14:
  671. # line 97 "gram.y"
  672. {
  673.             fprintf(outf,"\\rail@i {%d}",yypvt[-1].num);
  674.             copy=1;
  675.         } break;
  676. case 15:
  677. # line 102 "gram.y"
  678. {    copy=0;
  679.             fprintf(outf,"\n");
  680.             fprintf(outf,"\\rail@o {%d}{\n",yypvt[-5].num);
  681.             outrule(yypvt[-1].rule);    /* embedded action is $4 */
  682.             freerule(yypvt[-1].rule);
  683.             fprintf(outf,"}\n");
  684.         } break;
  685. case 16:
  686. # line 112 "gram.y"
  687. { yyval.rule=addrule(yypvt[-2].rule,yypvt[-0].rule); } break;
  688. case 17:
  689. # line 114 "gram.y"
  690. { yyval.rule=yypvt[-1].rule; } break;
  691. case 19:
  692. # line 117 "gram.y"
  693. { yyval.rule=NULL; } break;
  694. case 20:
  695. # line 121 "gram.y"
  696. { errorid=yypvt[-1].id; } break;
  697. case 21:
  698. # line 123 "gram.y"
  699. {
  700.             if(yypvt[-3].id->kind==UNKNOWN || yypvt[-3].id->kind==TOKEN)
  701.                 yypvt[-3].id->kind=NTERM;
  702.             else
  703.                 redef(yypvt[-3].id);
  704.  
  705.              yyval.rule=newrule(yypvt[-3].id,yypvt[-0].body);    /* embedded action is $3 */
  706.  
  707.             errorid=NULL;
  708.         } break;
  709. case 22:
  710. # line 134 "gram.y"
  711. {
  712.             anonymous++;
  713.  
  714.             yyval.rule=newrule((IDTYPE *)NULL,yypvt[-0].body);
  715.         } break;
  716. case 23:
  717. # line 142 "gram.y"
  718. { yyval.body=yypvt[-0].body; yyval.body->done=1; } break;
  719. case 24:
  720. # line 146 "gram.y"
  721. {
  722.             yyval.body=newbody(ANNOTE,NULLBODY,NULLBODY);
  723.             yyval.body->text=yypvt[-1].text;
  724.             yyval.body=addbody(CAT,yyval.body,yypvt[-0].body);
  725.             yyval.body=addbody(BAR,yypvt[-3].body,yyval.body);
  726.         } break;
  727. case 25:
  728. # line 153 "gram.y"
  729. { yyval.body=addbody(BAR,yypvt[-2].body,yypvt[-0].body); } break;
  730. case 26:
  731. # line 155 "gram.y"
  732. {
  733.             yyval.body=newbody(ANNOTE,NULLBODY,NULLBODY);
  734.             yyval.body->text=yypvt[-1].text;
  735.             yyval.body=addbody(CAT,yyval.body,yypvt[-0].body);
  736.         } break;
  737. case 28:
  738. # line 164 "gram.y"
  739. {
  740.             if(altstar && isemptybody(yypvt[-0].body)) {
  741.                 yyval.body=newbody(EMPTY,NULLBODY,NULLBODY);
  742.                 yyval.body=addbody(PLUS,yyval.body,revbody(yypvt[-2].body));
  743.             } else {
  744.                 yyval.body=newbody(EMPTY,NULLBODY,NULLBODY);
  745.                 yyval.body=addbody(BAR,yyval.body,addbody(PLUS,yypvt[-2].body,revbody(yypvt[-0].body)));
  746.             }
  747.         } break;
  748. case 29:
  749. # line 174 "gram.y"
  750. { yyval.body=newbody(PLUS,yypvt[-2].body,revbody(yypvt[-0].body)); } break;
  751. case 33:
  752. # line 181 "gram.y"
  753. { yyval.body=addbody(CAT,yypvt[-1].body,yypvt[-0].body); } break;
  754. case 35:
  755. # line 186 "gram.y"
  756. { yyval.body=addbody(BAR,newbody(EMPTY,NULLBODY,NULLBODY),yypvt[-1].body); } break;
  757. case 39:
  758. # line 193 "gram.y"
  759. { yyval.body=yypvt[-1].body; yyval.body->done=1; } break;
  760. case 40:
  761. # line 195 "gram.y"
  762. {
  763.             yyval.body=newbody(STRNG,NULLBODY,NULLBODY);
  764.             yyval.body->annot=yypvt[-0].text;
  765.             yyval.body->text=yypvt[-1].text;
  766.         } break;
  767. case 41:
  768. # line 201 "gram.y"
  769. {
  770.             if(yypvt[-1].id->kind==UNKNOWN)
  771.                 yypvt[-1].id->kind=TOKEN;
  772.  
  773.             yyval.body=newbody(IDENT,NULLBODY,NULLBODY);
  774.             yyval.body->annot=yypvt[-0].text;
  775.             yyval.body->id=yypvt[-1].id;
  776.         } break;
  777. case 42:
  778. # line 210 "gram.y"
  779. { yyval.body=newbody(CR,NULLBODY,NULLBODY); } break;
  780. case 43:
  781. # line 214 "gram.y"
  782. { yyval.body=newbody(EMPTY,NULLBODY,NULLBODY); } break;
  783. case 44:
  784. # line 218 "gram.y"
  785. { yyval.text=yypvt[-0].text; } break;
  786. case 45:
  787. # line 220 "gram.y"
  788. { yyval.text=NULL; } break;
  789.     }
  790.     goto yystack;        /* reset registers in driver code */
  791. }
  792.