home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / TEXT / UTILITY / FLEX237.ZIP / PARSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-03  |  29.3 KB  |  1,131 lines

  1. #ifndef lint
  2. static char yysccsid[] = "@(#)yaccpar    1.6 (Berkeley) 07/15/90";
  3. #endif
  4. #line 7 "parse.y"
  5. /*-
  6.  * Copyright (c) 1990 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * This code is derived from software contributed to Berkeley by
  10.  * Vern Paxson.
  11.  * 
  12.  * The United States Government has rights in this work pursuant
  13.  * to contract no. DE-AC03-76SF00098 between the United States
  14.  * Department of Energy and the University of California.
  15.  *
  16.  * Redistribution and use in source and binary forms are permitted provided
  17.  * that: (1) source distributions retain this entire copyright notice and
  18.  * comment, and (2) distributions including binaries display the following
  19.  * acknowledgement:  ``This product includes software developed by the
  20.  * University of California, Berkeley and its contributors'' in the
  21.  * documentation or other materials provided with the distribution and in
  22.  * all advertising materials mentioning features or use of this software.
  23.  * Neither the name of the University nor the names of its contributors may
  24.  * be used to endorse or promote products derived from this software without
  25.  * specific prior written permission.
  26.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  27.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  28.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  29.  */
  30.  
  31. #ifndef lint
  32. static char rcsid[] =
  33.     "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/parse.y,v 2.7 90/06/27 23:48:31 vern Exp $ (LBL)";
  34. #endif
  35.  
  36. #include "flexdef.h"
  37.  
  38. int pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, actvp, rulelen;
  39. int trlcontxt, xcluflg, cclsorted, varlength, variable_trail_rule;
  40. Char clower();
  41.  
  42. static int madeany = false;  /* whether we've made the '.' character class */
  43. int previous_continued_action;    /* whether the previous rule's action was '|' */
  44.  
  45. #line 46 "y_tab.c"
  46. #define CHAR 257
  47. #define NUMBER 258
  48. #define SECTEND 259
  49. #define SCDECL 260
  50. #define XSCDECL 261
  51. #define WHITESPACE 262
  52. #define NAME 263
  53. #define PREVCCL 264
  54. #define EOF_OP 265
  55. #define YYERRCODE 256
  56. short yylhs[] = {                                        -1,
  57.     0,    1,    2,    2,    2,    3,    6,    6,    7,    7,
  58.     7,    4,    4,    5,    8,    8,    8,    8,    8,    8,
  59.     8,    9,   11,   11,   11,   10,   10,   10,   10,   13,
  60.    13,   12,   14,   14,   15,   15,   15,   15,   15,   15,
  61.    15,   15,   15,   15,   15,   15,   16,   16,   18,   18,
  62.    18,   17,   17,
  63. };
  64. short yylen[] = {                                         2,
  65.     5,    0,    5,    0,    2,    1,    1,    1,    3,    1,
  66.     1,    4,    0,    0,    3,    2,    2,    1,    2,    1,
  67.     1,    3,    3,    1,    1,    2,    3,    2,    1,    3,
  68.     1,    2,    2,    1,    2,    2,    2,    6,    5,    4,
  69.     1,    1,    1,    3,    3,    1,    3,    4,    4,    2,
  70.     0,    2,    0,
  71. };
  72. short yydefred[] = {                                      2,
  73.     0,    0,    0,    0,    5,    6,    7,    8,   13,    0,
  74.    14,    0,    0,   11,   10,    0,   21,   46,   43,   20,
  75.     0,    0,   41,   53,    0,    0,    0,    0,   18,    0,
  76.     0,    0,    0,   42,    0,    3,   17,   25,   24,    0,
  77.     0,    0,   51,    0,   12,   19,    0,   16,    0,   28,
  78.     0,   32,    0,   35,   36,   37,    0,    9,   22,    0,
  79.    52,   44,   45,    0,    0,   47,   15,   27,    0,    0,
  80.    23,   48,    0,    0,   40,   49,    0,   39,   38,
  81. };
  82. short yydgoto[] = {                                       1,
  83.     2,    4,    9,   11,   13,   10,   16,   27,   28,   29,
  84.    40,   30,   31,   32,   33,   34,   41,   44,
  85. };
  86. short yysindex[] = {                                      0,
  87.     0, -231,   28, -186,    0,    0,    0,    0,    0, -221,
  88.     0, -212,  -32,    0,    0,   -9,    0,    0,    0,    0,
  89.   -28, -203,    0,    0,  -28,  -39,   47,  -30,    0,  -28,
  90.   -15,  -28,    4,    0, -205,    0,    0,    0,    0,    8,
  91.   -29,  -19,    0,  -86,    0,    0,  -28,    0,  -16,    0,
  92.   -28,    0,    4,    0,    0,    0, -193,    0,    0, -194,
  93.     0,    0,    0,  -84,   34,    0,    0,    0,  -28,  -21,
  94.     0,    0, -177, -110,    0,    0,  -43,    0,    0,
  95. };
  96. short yyrindex[] = {                                      0,
  97.     0, -183,    0,    0,    0,    0,    0,    0,    0,    0,
  98.     0,    0,   83,    0,    0,    0,    0,    0,    0,    0,
  99.     0,    0,    0,    0,    0,  -82,    0,    0,    0,    0,
  100.    75,    7,  -10,    0,    0,    0,    0,    0,    0,    0,
  101.     0,    0,    0,    0,    0,    0,    0,    0,   76,    0,
  102.     0,    0,   -7,    0,    0,    0,    0,    0,    0,    0,
  103.     0,    0,    0,    0,  -80,    0,    0,    0,    9,    0,
  104.     0,    0,    0,    0,    0,    0,    0,    0,    0,
  105. };
  106. short yygindex[] = {                                      0,
  107.     0,    0,    0,    0,    0,    0,    0,    0,    0,   21,
  108.     0,    0,   41,   36,    3,    0,    0,   45,
  109. };
  110. #define YYTABLESIZE 257
  111. short yytable[] = {                                      34,
  112.    36,   24,   33,   24,   62,   24,   66,   25,   72,   25,
  113.    51,   25,   50,   23,   78,   23,   31,   23,   30,   68,
  114.    50,   63,   74,   34,    3,   34,   33,   22,   33,   34,
  115.    34,   52,   33,   33,   53,   34,   34,    5,   33,   33,
  116.    12,   37,   31,   14,   30,   54,   55,   31,   48,   30,
  117.    15,   60,   38,   31,   43,   30,   45,   58,   26,   39,
  118.    26,   21,   26,   47,   70,   42,   56,   67,   71,   59,
  119.    49,   53,    6,    7,    8,    4,    4,    4,   73,   76,
  120.    34,   79,    1,   33,   29,   26,   69,   64,    0,    0,
  121.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  122.     0,    0,    0,   75,   51,    0,    0,   51,   51,    0,
  123.     0,    0,    0,   34,    0,    0,   33,    0,    0,    0,
  124.     0,    0,    0,    0,    0,    0,   57,    0,    0,    0,
  125.    31,    0,   30,    0,    0,    0,    0,    0,    0,    0,
  126.     0,    0,    0,    0,    0,    0,    0,   77,    0,    0,
  127.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  128.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  129.    65,    0,   65,    0,   51,    0,   50,    0,    0,    0,
  130.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  131.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  132.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  133.     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  134.     0,    0,    0,   17,   18,    0,   18,   61,   18,    0,
  135.     0,   19,   20,   19,   46,   19,    0,    0,    0,    0,
  136.     0,    0,    0,    0,    0,    0,   34,    0,    0,   33,
  137.     0,    0,   35,   34,    0,    0,   33,
  138. };
  139. short yycheck[] = {                                      10,
  140.    10,   34,   10,   34,   34,   34,   93,   40,   93,   40,
  141.    93,   40,   93,   46,  125,   46,   10,   46,   10,   36,
  142.    36,   41,   44,   34,  256,   36,   34,   60,   36,   40,
  143.    41,   47,   40,   41,   32,   46,   47,   10,   46,   47,
  144.   262,   21,   36,  256,   36,   42,   43,   41,   28,   41,
  145.   263,   44,  256,   47,   94,   47,   10,  263,   91,  263,
  146.    91,   94,   91,   94,  258,   25,   63,   47,  263,   62,
  147.    30,   69,  259,  260,  261,  259,  260,  261,   45,  257,
  148.    91,  125,    0,   91,   10,   10,   51,   43,   -1,   -1,
  149.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  150.    -1,   -1,   -1,  125,  124,   -1,   -1,  124,  124,   -1,
  151.    -1,   -1,   -1,  124,   -1,   -1,  124,   -1,   -1,   -1,
  152.    -1,   -1,   -1,   -1,   -1,   -1,  123,   -1,   -1,   -1,
  153.   124,   -1,  124,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  154.    -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,   -1,   -1,
  155.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  156.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  157.   257,   -1,  257,   -1,  257,   -1,  257,   -1,   -1,   -1,
  158.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  159.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  160.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  161.    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  162.    -1,   -1,   -1,  256,  257,   -1,  257,  257,  257,   -1,
  163.    -1,  264,  265,  264,  265,  264,   -1,   -1,   -1,   -1,
  164.    -1,   -1,   -1,   -1,   -1,   -1,  257,   -1,   -1,  257,
  165.    -1,   -1,  262,  264,   -1,   -1,  264,
  166. };
  167. #define YYFINAL 1
  168. #ifndef YYDEBUG
  169. #define YYDEBUG 0
  170. #endif
  171. #define YYMAXTOKEN 265
  172. #if YYDEBUG
  173. char *yyname[] = {
  174. "end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  175. 0,0,0,"'\"'",0,"'$'",0,0,0,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",0,0,
  176. 0,0,0,0,0,0,0,0,0,0,"'<'",0,"'>'","'?'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  177. 0,0,0,0,0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  178. 0,0,0,0,0,"'{'","'|'","'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  179. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  180. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  181. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"CHAR","NUMBER","SECTEND",
  182. "SCDECL","XSCDECL","WHITESPACE","NAME","PREVCCL","EOF_OP",
  183. };
  184. char *yyrule[] = {
  185. "$accept : goal",
  186. "goal : initlex sect1 sect1end sect2 initforrule",
  187. "initlex :",
  188. "sect1 : sect1 startconddecl WHITESPACE namelist1 '\\n'",
  189. "sect1 :",
  190. "sect1 : error '\\n'",
  191. "sect1end : SECTEND",
  192. "startconddecl : SCDECL",
  193. "startconddecl : XSCDECL",
  194. "namelist1 : namelist1 WHITESPACE NAME",
  195. "namelist1 : NAME",
  196. "namelist1 : error",
  197. "sect2 : sect2 initforrule flexrule '\\n'",
  198. "sect2 :",
  199. "initforrule :",
  200. "flexrule : scon '^' rule",
  201. "flexrule : scon rule",
  202. "flexrule : '^' rule",
  203. "flexrule : rule",
  204. "flexrule : scon EOF_OP",
  205. "flexrule : EOF_OP",
  206. "flexrule : error",
  207. "scon : '<' namelist2 '>'",
  208. "namelist2 : namelist2 ',' NAME",
  209. "namelist2 : NAME",
  210. "namelist2 : error",
  211. "rule : re2 re",
  212. "rule : re2 re '$'",
  213. "rule : re '$'",
  214. "rule : re",
  215. "re : re '|' series",
  216. "re : series",
  217. "re2 : re '/'",
  218. "series : series singleton",
  219. "series : singleton",
  220. "singleton : singleton '*'",
  221. "singleton : singleton '+'",
  222. "singleton : singleton '?'",
  223. "singleton : singleton '{' NUMBER ',' NUMBER '}'",
  224. "singleton : singleton '{' NUMBER ',' '}'",
  225. "singleton : singleton '{' NUMBER '}'",
  226. "singleton : '.'",
  227. "singleton : fullccl",
  228. "singleton : PREVCCL",
  229. "singleton : '\"' string '\"'",
  230. "singleton : '(' re ')'",
  231. "singleton : CHAR",
  232. "fullccl : '[' ccl ']'",
  233. "fullccl : '[' '^' ccl ']'",
  234. "ccl : ccl CHAR '-' CHAR",
  235. "ccl : ccl CHAR",
  236. "ccl :",
  237. "string : string CHAR",
  238. "string :",
  239. };
  240. #endif
  241. #ifndef YYSTYPE
  242. typedef int YYSTYPE;
  243. #endif
  244. #define yyclearin (yychar=(-1))
  245. #define yyerrok (yyerrflag=0)
  246. #ifndef YYSTACKSIZE
  247. #ifdef YYMAXDEPTH
  248. #define YYSTACKSIZE YYMAXDEPTH
  249. #else
  250. #define YYSTACKSIZE 600
  251. #endif
  252. #endif
  253. int yydebug;
  254. int yynerrs;
  255. int yyerrflag;
  256. int yychar;
  257. short *yyssp;
  258. YYSTYPE *yyvsp;
  259. YYSTYPE yyval;
  260. YYSTYPE yylval;
  261. #define yystacksize YYSTACKSIZE
  262. short yyss[YYSTACKSIZE];
  263. YYSTYPE yyvs[YYSTACKSIZE];
  264. #line 628 "parse.y"
  265.  
  266.  
  267. /* build_eof_action - build the "<<EOF>>" action for the active start
  268.  *                    conditions
  269.  */
  270.  
  271. void build_eof_action()
  272.  
  273.     {
  274.     register int i;
  275.  
  276.     for ( i = 1; i <= actvp; ++i )
  277.     {
  278.     if ( sceof[actvsc[i]] )
  279.         format_pinpoint_message(
  280.         "multiple <<EOF>> rules for start condition %s",
  281.             scname[actvsc[i]] );
  282.  
  283.     else
  284.         {
  285.         sceof[actvsc[i]] = true;
  286.         fprintf( temp_action_file, "case YY_STATE_EOF(%s):\n",
  287.              scname[actvsc[i]] );
  288.         }
  289.     }
  290.  
  291.     line_directive_out( temp_action_file );
  292.     }
  293.  
  294.  
  295. /* synerr - report a syntax error */
  296.  
  297. void synerr( str )
  298. char str[];
  299.  
  300.     {
  301.     syntaxerror = true;
  302.     pinpoint_message( str );
  303.     }
  304.  
  305.  
  306. /* format_pinpoint_message - write out a message formatted with one string,
  307.  *                 pinpointing its location
  308.  */
  309.  
  310. void format_pinpoint_message( msg, arg )
  311. char msg[], arg[];
  312.  
  313.     {
  314.     char errmsg[MAXLINE];
  315.  
  316.     (void) sprintf( errmsg, msg, arg );
  317.     pinpoint_message( errmsg );
  318.     }
  319.  
  320.  
  321. /* pinpoint_message - write out a message, pinpointing its location */
  322.  
  323. void pinpoint_message( str )
  324. char str[];
  325.  
  326.     {
  327.     fprintf( stderr, "\"%s\", line %d: %s\n", infilename, linenum, str );
  328.     }
  329.  
  330.  
  331. /* yyerror - eat up an error message from the parser;
  332.  *         currently, messages are ignore
  333.  */
  334.  
  335. void yyerror( msg )
  336. char msg[];
  337.  
  338.     {
  339.     }
  340. #line 341 "y_tab.c"
  341. #define YYABORT goto yyabort
  342. #define YYACCEPT goto yyaccept
  343. #define YYERROR goto yyerrlab
  344. int
  345. yyparse()
  346. {
  347.     register int yym, yyn, yystate;
  348. #if YYDEBUG
  349.     register char *yys;
  350.     extern char *getenv();
  351.  
  352.     if (yys = getenv("YYDEBUG"))
  353.     {
  354.         yyn = *yys;
  355.         if (yyn >= '0' && yyn <= '9')
  356.             yydebug = yyn - '0';
  357.     }
  358. #endif
  359.  
  360.     yynerrs = 0;
  361.     yyerrflag = 0;
  362.     yychar = (-1);
  363.  
  364.     yyssp = yyss;
  365.     yyvsp = yyvs;
  366.     *yyssp = yystate = 0;
  367.  
  368. yyloop:
  369.     if (yyn = yydefred[yystate]) goto yyreduce;
  370.     if (yychar < 0)
  371.     {
  372.         if ((yychar = yylex()) < 0) yychar = 0;
  373. #if YYDEBUG
  374.         if (yydebug)
  375.         {
  376.             yys = 0;
  377.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  378.             if (!yys) yys = "illegal-symbol";
  379.             printf("yydebug: state %d, reading %d (%s)\n", yystate,
  380.                     yychar, yys);
  381.         }
  382. #endif
  383.     }
  384.     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
  385.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  386.     {
  387. #if YYDEBUG
  388.         if (yydebug)
  389.             printf("yydebug: state %d, shifting to state %d\n",
  390.                     yystate, yytable[yyn]);
  391. #endif
  392.         if (yyssp >= yyss + yystacksize - 1)
  393.         {
  394.             goto yyoverflow;
  395.         }
  396.         *++yyssp = yystate = yytable[yyn];
  397.         *++yyvsp = yylval;
  398.         yychar = (-1);
  399.         if (yyerrflag > 0)  --yyerrflag;
  400.         goto yyloop;
  401.     }
  402.     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
  403.             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
  404.     {
  405.         yyn = yytable[yyn];
  406.         goto yyreduce;
  407.     }
  408.     if (yyerrflag) goto yyinrecovery;
  409. #ifdef lint
  410.     goto yynewerror;
  411. #endif
  412. yynewerror:
  413.     yyerror("syntax error");
  414. #ifdef lint
  415.     goto yyerrlab;
  416. #endif
  417. yyerrlab:
  418.     ++yynerrs;
  419. yyinrecovery:
  420.     if (yyerrflag < 3)
  421.     {
  422.         yyerrflag = 3;
  423.         for (;;)
  424.         {
  425.             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
  426.                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
  427.             {
  428. #if YYDEBUG
  429.                 if (yydebug)
  430.                     printf("yydebug: state %d, error recovery shifting\
  431.  to state %d\n", *yyssp, yytable[yyn]);
  432. #endif
  433.                 if (yyssp >= yyss + yystacksize - 1)
  434.                 {
  435.                     goto yyoverflow;
  436.                 }
  437.                 *++yyssp = yystate = yytable[yyn];
  438.                 *++yyvsp = yylval;
  439.                 goto yyloop;
  440.             }
  441.             else
  442.             {
  443. #if YYDEBUG
  444.                 if (yydebug)
  445.                     printf("yydebug: error recovery discarding state %d\n",
  446.                             *yyssp);
  447. #endif
  448.                 if (yyssp <= yyss) goto yyabort;
  449.                 --yyssp;
  450.                 --yyvsp;
  451.             }
  452.         }
  453.     }
  454.     else
  455.     {
  456.         if (yychar == 0) goto yyabort;
  457. #if YYDEBUG
  458.         if (yydebug)
  459.         {
  460.             yys = 0;
  461.             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  462.             if (!yys) yys = "illegal-symbol";
  463.             printf("yydebug: state %d, error recovery discards token %d (%s)\n",
  464.                     yystate, yychar, yys);
  465.         }
  466. #endif
  467.         yychar = (-1);
  468.         goto yyloop;
  469.     }
  470. yyreduce:
  471. #if YYDEBUG
  472.     if (yydebug)
  473.         printf("yydebug: state %d, reducing by rule %d (%s)\n",
  474.                 yystate, yyn, yyrule[yyn]);
  475. #endif
  476.     yym = yylen[yyn];
  477.     yyval = yyvsp[1-yym];
  478.     switch (yyn)
  479.     {
  480. case 1:
  481. #line 51 "parse.y"
  482. { /* add default rule */
  483.             int def_rule;
  484.  
  485.             pat = cclinit();
  486.             cclnegate( pat );
  487.  
  488.             def_rule = mkstate( -pat );
  489.  
  490.             finish_rule( def_rule, false, 0, 0 );
  491.  
  492.             for ( i = 1; i <= lastsc; ++i )
  493.                 scset[i] = mkbranch( scset[i], def_rule );
  494.  
  495.             if ( spprdflt )
  496.                 fputs( "YY_FATAL_ERROR( \"flex scanner jammed\" )",
  497.                    temp_action_file );
  498.             else
  499.                 fputs( "ECHO", temp_action_file );
  500.  
  501.             fputs( ";\n\tYY_BREAK\n", temp_action_file );
  502.             }
  503. break;
  504. case 2:
  505. #line 75 "parse.y"
  506. {
  507.             /* initialize for processing rules */
  508.  
  509.             /* create default DFA start condition */
  510.             scinstal( "INITIAL", false );
  511.             }
  512. break;
  513. case 5:
  514. #line 86 "parse.y"
  515. { synerr( "unknown error processing section 1" ); }
  516. break;
  517. case 7:
  518. #line 93 "parse.y"
  519. {
  520.             /* these productions are separate from the s1object
  521.              * rule because the semantics must be done before
  522.              * we parse the remainder of an s1object
  523.              */
  524.  
  525.             xcluflg = false;
  526.             }
  527. break;
  528. case 8:
  529. #line 103 "parse.y"
  530. { xcluflg = true; }
  531. break;
  532. case 9:
  533. #line 107 "parse.y"
  534. { scinstal( nmstr, xcluflg ); }
  535. break;
  536. case 10:
  537. #line 110 "parse.y"
  538. { scinstal( nmstr, xcluflg ); }
  539. break;
  540. case 11:
  541. #line 113 "parse.y"
  542. { synerr( "bad start condition list" ); }
  543. break;
  544. case 14:
  545. #line 121 "parse.y"
  546. {
  547.             /* initialize for a parse of one rule */
  548.             trlcontxt = variable_trail_rule = varlength = false;
  549.             trailcnt = headcnt = rulelen = 0;
  550.             current_state_type = STATE_NORMAL;
  551.             previous_continued_action = continued_action;
  552.             new_rule();
  553.             }
  554. break;
  555. case 15:
  556. #line 132 "parse.y"
  557. {
  558.             pat = yyvsp[0];
  559.             finish_rule( pat, variable_trail_rule,
  560.                      headcnt, trailcnt );
  561.  
  562.             for ( i = 1; i <= actvp; ++i )
  563.                 scbol[actvsc[i]] =
  564.                 mkbranch( scbol[actvsc[i]], pat );
  565.  
  566.             if ( ! bol_needed )
  567.                 {
  568.                 bol_needed = true;
  569.  
  570.                 if ( performance_report )
  571.                 pinpoint_message( 
  572.                 "'^' operator results in sub-optimal performance" );
  573.                 }
  574.             }
  575. break;
  576. case 16:
  577. #line 152 "parse.y"
  578. {
  579.             pat = yyvsp[0];
  580.             finish_rule( pat, variable_trail_rule,
  581.                      headcnt, trailcnt );
  582.  
  583.             for ( i = 1; i <= actvp; ++i )
  584.                 scset[actvsc[i]] =
  585.                 mkbranch( scset[actvsc[i]], pat );
  586.             }
  587. break;
  588. case 17:
  589. #line 163 "parse.y"
  590. {
  591.             pat = yyvsp[0];
  592.             finish_rule( pat, variable_trail_rule,
  593.                      headcnt, trailcnt );
  594.  
  595.             /* add to all non-exclusive start conditions,
  596.              * including the default (0) start condition
  597.              */
  598.  
  599.             for ( i = 1; i <= lastsc; ++i )
  600.                 if ( ! scxclu[i] )
  601.                 scbol[i] = mkbranch( scbol[i], pat );
  602.  
  603.             if ( ! bol_needed )
  604.                 {
  605.                 bol_needed = true;
  606.  
  607.                 if ( performance_report )
  608.                 pinpoint_message(
  609.                 "'^' operator results in sub-optimal performance" );
  610.                 }
  611.             }
  612. break;
  613. case 18:
  614. #line 187 "parse.y"
  615. {
  616.             pat = yyvsp[0];
  617.             finish_rule( pat, variable_trail_rule,
  618.                      headcnt, trailcnt );
  619.  
  620.             for ( i = 1; i <= lastsc; ++i )
  621.                 if ( ! scxclu[i] )
  622.                 scset[i] = mkbranch( scset[i], pat );
  623.             }
  624. break;
  625. case 19:
  626. #line 198 "parse.y"
  627. { build_eof_action(); }
  628. break;
  629. case 20:
  630. #line 201 "parse.y"
  631. {
  632.             /* this EOF applies to all start conditions
  633.              * which don't already have EOF actions
  634.              */
  635.             actvp = 0;
  636.  
  637.             for ( i = 1; i <= lastsc; ++i )
  638.                 if ( ! sceof[i] )
  639.                 actvsc[++actvp] = i;
  640.  
  641.             if ( actvp == 0 )
  642.                 pinpoint_message(
  643.         "warning - all start conditions already have <<EOF>> rules" );
  644.  
  645.             else
  646.                 build_eof_action();
  647.             }
  648. break;
  649. case 21:
  650. #line 220 "parse.y"
  651. { synerr( "unrecognized rule" ); }
  652. break;
  653. case 23:
  654. #line 227 "parse.y"
  655. {
  656.             if ( (scnum = sclookup( nmstr )) == 0 )
  657.                 format_pinpoint_message(
  658.                 "undeclared start condition %s", nmstr );
  659.  
  660.             else
  661.                 actvsc[++actvp] = scnum;
  662.             }
  663. break;
  664. case 24:
  665. #line 237 "parse.y"
  666. {
  667.             if ( (scnum = sclookup( nmstr )) == 0 )
  668.                 format_pinpoint_message(
  669.                 "undeclared start condition %s", nmstr );
  670.             else
  671.                 actvsc[actvp = 1] = scnum;
  672.             }
  673. break;
  674. case 25:
  675. #line 246 "parse.y"
  676. { synerr( "bad start condition list" ); }
  677. break;
  678. case 26:
  679. #line 250 "parse.y"
  680. {
  681.             if ( transchar[lastst[yyvsp[0]]] != SYM_EPSILON )
  682.                 /* provide final transition \now/ so it
  683.                  * will be marked as a trailing context
  684.                  * state
  685.                  */
  686.                 yyvsp[0] = link_machines( yyvsp[0], mkstate( SYM_EPSILON ) );
  687.  
  688.             mark_beginning_as_normal( yyvsp[0] );
  689.             current_state_type = STATE_NORMAL;
  690.  
  691.             if ( previous_continued_action )
  692.                 {
  693.                 /* we need to treat this as variable trailing
  694.                  * context so that the backup does not happen
  695.                  * in the action but before the action switch
  696.                  * statement.  If the backup happens in the
  697.                  * action, then the rules "falling into" this
  698.                  * one's action will *also* do the backup,
  699.                  * erroneously.
  700.                  */
  701.                 if ( ! varlength || headcnt != 0 )
  702.                 {
  703.                 fprintf( stderr,
  704.     "%s: warning - trailing context rule at line %d made variable because\n",
  705.                      program_name, linenum );
  706.                 fprintf( stderr,
  707.                      "      of preceding '|' action\n" );
  708.                 }
  709.  
  710.                 /* mark as variable */
  711.                 varlength = true;
  712.                 headcnt = 0;
  713.                 }
  714.  
  715.             if ( varlength && headcnt == 0 )
  716.                 { /* variable trailing context rule */
  717.                 /* mark the first part of the rule as the accepting
  718.                  * "head" part of a trailing context rule
  719.                  */
  720.                 /* by the way, we didn't do this at the beginning
  721.                  * of this production because back then
  722.                  * current_state_type was set up for a trail
  723.                  * rule, and add_accept() can create a new
  724.                  * state ...
  725.                  */
  726.                 add_accept( yyvsp[-1], num_rules | YY_TRAILING_HEAD_MASK );
  727.                 variable_trail_rule = true;
  728.                 }
  729.             
  730.             else
  731.                 trailcnt = rulelen;
  732.  
  733.             yyval = link_machines( yyvsp[-1], yyvsp[0] );
  734.             }
  735. break;
  736. case 27:
  737. #line 307 "parse.y"
  738. { synerr( "trailing context used twice" ); }
  739. break;
  740. case 28:
  741. #line 310 "parse.y"
  742. {
  743.             if ( trlcontxt )
  744.                 {
  745.                 synerr( "trailing context used twice" );
  746.                 yyval = mkstate( SYM_EPSILON );
  747.                 }
  748.  
  749.             else if ( previous_continued_action )
  750.                 {
  751.                 /* see the comment in the rule for "re2 re"
  752.                  * above
  753.                  */
  754.                 if ( ! varlength || headcnt != 0 )
  755.                 {
  756.                 fprintf( stderr,
  757.     "%s: warning - trailing context rule at line %d made variable because\n",
  758.                      program_name, linenum );
  759.                 fprintf( stderr,
  760.                      "      of preceding '|' action\n" );
  761.                 }
  762.  
  763.                 /* mark as variable */
  764.                 varlength = true;
  765.                 headcnt = 0;
  766.                 }
  767.  
  768.             trlcontxt = true;
  769.  
  770.             if ( ! varlength )
  771.                 headcnt = rulelen;
  772.  
  773.             ++rulelen;
  774.             trailcnt = 1;
  775.  
  776.             eps = mkstate( SYM_EPSILON );
  777.             yyval = link_machines( yyvsp[-1],
  778.                  link_machines( eps, mkstate( '\n' ) ) );
  779.             }
  780. break;
  781. case 29:
  782. #line 350 "parse.y"
  783. {
  784.                 yyval = yyvsp[0];
  785.  
  786.             if ( trlcontxt )
  787.                 {
  788.                 if ( varlength && headcnt == 0 )
  789.                 /* both head and trail are variable-length */
  790.                 variable_trail_rule = true;
  791.                 else
  792.                 trailcnt = rulelen;
  793.                 }
  794.                 }
  795. break;
  796. case 30:
  797. #line 366 "parse.y"
  798. {
  799.             varlength = true;
  800.             yyval = mkor( yyvsp[-2], yyvsp[0] );
  801.             }
  802. break;
  803. case 31:
  804. #line 372 "parse.y"
  805. { yyval = yyvsp[0]; }
  806. break;
  807. case 32:
  808. #line 377 "parse.y"
  809. {
  810.             /* this rule is written separately so
  811.              * the reduction will occur before the trailing
  812.              * series is parsed
  813.              */
  814.  
  815.             if ( trlcontxt )
  816.                 synerr( "trailing context used twice" );
  817.             else
  818.                 trlcontxt = true;
  819.  
  820.             if ( varlength )
  821.                 /* we hope the trailing context is fixed-length */
  822.                 varlength = false;
  823.             else
  824.                 headcnt = rulelen;
  825.  
  826.             rulelen = 0;
  827.  
  828.             current_state_type = STATE_TRAILING_CONTEXT;
  829.             yyval = yyvsp[-1];
  830.             }
  831. break;
  832. case 33:
  833. #line 402 "parse.y"
  834. {
  835.             /* this is where concatenation of adjacent patterns
  836.              * gets done
  837.              */
  838.             yyval = link_machines( yyvsp[-1], yyvsp[0] );
  839.             }
  840. break;
  841. case 34:
  842. #line 410 "parse.y"
  843. { yyval = yyvsp[0]; }
  844. break;
  845. case 35:
  846. #line 414 "parse.y"
  847. {
  848.             varlength = true;
  849.  
  850.             yyval = mkclos( yyvsp[-1] );
  851.             }
  852. break;
  853. case 36:
  854. #line 421 "parse.y"
  855. {
  856.             varlength = true;
  857.  
  858.             yyval = mkposcl( yyvsp[-1] );
  859.             }
  860. break;
  861. case 37:
  862. #line 428 "parse.y"
  863. {
  864.             varlength = true;
  865.  
  866.             yyval = mkopt( yyvsp[-1] );
  867.             }
  868. break;
  869. case 38:
  870. #line 435 "parse.y"
  871. {
  872.             varlength = true;
  873.  
  874.             if ( yyvsp[-3] > yyvsp[-1] || yyvsp[-3] < 0 )
  875.                 {
  876.                 synerr( "bad iteration values" );
  877.                 yyval = yyvsp[-5];
  878.                 }
  879.             else
  880.                 {
  881.                 if ( yyvsp[-3] == 0 )
  882.                 yyval = mkopt( mkrep( yyvsp[-5], yyvsp[-3], yyvsp[-1] ) );
  883.                 else
  884.                 yyval = mkrep( yyvsp[-5], yyvsp[-3], yyvsp[-1] );
  885.                 }
  886.             }
  887. break;
  888. case 39:
  889. #line 453 "parse.y"
  890. {
  891.             varlength = true;
  892.  
  893.             if ( yyvsp[-2] <= 0 )
  894.                 {
  895.                 synerr( "iteration value must be positive" );
  896.                 yyval = yyvsp[-4];
  897.                 }
  898.  
  899.             else
  900.                 yyval = mkrep( yyvsp[-4], yyvsp[-2], INFINITY );
  901.             }
  902. break;
  903. case 40:
  904. #line 467 "parse.y"
  905. {
  906.             /* the singleton could be something like "(foo)",
  907.              * in which case we have no idea what its length
  908.              * is, so we punt here.
  909.              */
  910.             varlength = true;
  911.  
  912.             if ( yyvsp[-1] <= 0 )
  913.                 {
  914.                 synerr( "iteration value must be positive" );
  915.                 yyval = yyvsp[-3];
  916.                 }
  917.  
  918.             else
  919.                 yyval = link_machines( yyvsp[-3], copysingl( yyvsp[-3], yyvsp[-1] - 1 ) );
  920.             }
  921. break;
  922. case 41:
  923. #line 485 "parse.y"
  924. {
  925.             if ( ! madeany )
  926.                 {
  927.                 /* create the '.' character class */
  928.                 anyccl = cclinit();
  929.                 ccladd( anyccl, '\n' );
  930.                 cclnegate( anyccl );
  931.  
  932.                 if ( useecs )
  933.                 mkeccl( ccltbl + cclmap[anyccl],
  934.                     ccllen[anyccl], nextecm,
  935.                     ecgroup, csize, csize );
  936.  
  937.                 madeany = true;
  938.                 }
  939.  
  940.             ++rulelen;
  941.  
  942.             yyval = mkstate( -anyccl );
  943.             }
  944. break;
  945. case 42:
  946. #line 507 "parse.y"
  947. {
  948.             if ( ! cclsorted )
  949.                 /* sort characters for fast searching.  We use a
  950.                  * shell sort since this list could be large.
  951.                  */
  952.                 cshell( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]], true );
  953.  
  954.             if ( useecs )
  955.                 mkeccl( ccltbl + cclmap[yyvsp[0]], ccllen[yyvsp[0]],
  956.                     nextecm, ecgroup, csize, csize );
  957.  
  958.             ++rulelen;
  959.  
  960.             yyval = mkstate( -yyvsp[0] );
  961.             }
  962. break;
  963. case 43:
  964. #line 524 "parse.y"
  965. {
  966.             ++rulelen;
  967.  
  968.             yyval = mkstate( -yyvsp[0] );
  969.             }
  970. break;
  971. case 44:
  972. #line 531 "parse.y"
  973. { yyval = yyvsp[-1]; }
  974. break;
  975. case 45:
  976. #line 534 "parse.y"
  977. { yyval = yyvsp[-1]; }
  978. break;
  979. case 46:
  980. #line 537 "parse.y"
  981. {
  982.             ++rulelen;
  983.  
  984.             if ( caseins && yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  985.                 yyvsp[0] = clower( yyvsp[0] );
  986.  
  987.             yyval = mkstate( yyvsp[0] );
  988.             }
  989. break;
  990. case 47:
  991. #line 548 "parse.y"
  992. { yyval = yyvsp[-1]; }
  993. break;
  994. case 48:
  995. #line 551 "parse.y"
  996. {
  997.             /* *Sigh* - to be compatible Unix lex, negated ccls
  998.              * match newlines
  999.              */
  1000. #ifdef NOTDEF
  1001.             ccladd( yyvsp[-1], '\n' ); /* negated ccls don't match '\n' */
  1002.             cclsorted = false; /* because we added the newline */
  1003. #endif
  1004.             cclnegate( yyvsp[-1] );
  1005.             yyval = yyvsp[-1];
  1006.             }
  1007. break;
  1008. case 49:
  1009. #line 565 "parse.y"
  1010. {
  1011.             if ( yyvsp[-2] > yyvsp[0] )
  1012.                 synerr( "negative range in character class" );
  1013.  
  1014.             else
  1015.                 {
  1016.                 if ( caseins )
  1017.                 {
  1018.                 if ( yyvsp[-2] >= 'A' && yyvsp[-2] <= 'Z' )
  1019.                     yyvsp[-2] = clower( yyvsp[-2] );
  1020.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  1021.                     yyvsp[0] = clower( yyvsp[0] );
  1022.                 }
  1023.  
  1024.                 for ( i = yyvsp[-2]; i <= yyvsp[0]; ++i )
  1025.                     ccladd( yyvsp[-3], i );
  1026.  
  1027.                 /* keep track if this ccl is staying in alphabetical
  1028.                  * order
  1029.                  */
  1030.                 cclsorted = cclsorted && (yyvsp[-2] > lastchar);
  1031.                 lastchar = yyvsp[0];
  1032.                 }
  1033.  
  1034.             yyval = yyvsp[-3];
  1035.             }
  1036. break;
  1037. case 50:
  1038. #line 593 "parse.y"
  1039. {
  1040.             if ( caseins )
  1041.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  1042.                 yyvsp[0] = clower( yyvsp[0] );
  1043.  
  1044.             ccladd( yyvsp[-1], yyvsp[0] );
  1045.             cclsorted = cclsorted && (yyvsp[0] > lastchar);
  1046.             lastchar = yyvsp[0];
  1047.             yyval = yyvsp[-1];
  1048.             }
  1049. break;
  1050. case 51:
  1051. #line 605 "parse.y"
  1052. {
  1053.             cclsorted = true;
  1054.             lastchar = 0;
  1055.             yyval = cclinit();
  1056.             }
  1057. break;
  1058. case 52:
  1059. #line 613 "parse.y"
  1060. {
  1061.             if ( caseins )
  1062.                 if ( yyvsp[0] >= 'A' && yyvsp[0] <= 'Z' )
  1063.                 yyvsp[0] = clower( yyvsp[0] );
  1064.  
  1065.             ++rulelen;
  1066.  
  1067.             yyval = link_machines( yyvsp[-1], mkstate( yyvsp[0] ) );
  1068.             }
  1069. break;
  1070. case 53:
  1071. #line 624 "parse.y"
  1072. { yyval = mkstate( SYM_EPSILON ); }
  1073. break;
  1074. #line 1075 "y_tab.c"
  1075.     }
  1076.     yyssp -= yym;
  1077.     yystate = *yyssp;
  1078.     yyvsp -= yym;
  1079.     yym = yylhs[yyn];
  1080.     if (yystate == 0 && yym == 0)
  1081.     {
  1082. #if YYDEBUG
  1083.         if (yydebug)
  1084.             printf("yydebug: after reduction, shifting from state 0 to\
  1085.  state %d\n", YYFINAL);
  1086. #endif
  1087.         yystate = YYFINAL;
  1088.         *++yyssp = YYFINAL;
  1089.         *++yyvsp = yyval;
  1090.         if (yychar < 0)
  1091.         {
  1092.             if ((yychar = yylex()) < 0) yychar = 0;
  1093. #if YYDEBUG
  1094.             if (yydebug)
  1095.             {
  1096.                 yys = 0;
  1097.                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
  1098.                 if (!yys) yys = "illegal-symbol";
  1099.                 printf("yydebug: state %d, reading %d (%s)\n",
  1100.                         YYFINAL, yychar, yys);
  1101.             }
  1102. #endif
  1103.         }
  1104.         if (yychar == 0) goto yyaccept;
  1105.         goto yyloop;
  1106.     }
  1107.     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
  1108.             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
  1109.         yystate = yytable[yyn];
  1110.     else
  1111.         yystate = yydgoto[yym];
  1112. #if YYDEBUG
  1113.     if (yydebug)
  1114.         printf("yydebug: after reduction, shifting from state %d \
  1115. to state %d\n", *yyssp, yystate);
  1116. #endif
  1117.     if (yyssp >= yyss + yystacksize - 1)
  1118.     {
  1119.         goto yyoverflow;
  1120.     }
  1121.     *++yyssp = yystate;
  1122.     *++yyvsp = yyval;
  1123.     goto yyloop;
  1124. yyoverflow:
  1125.     yyerror("yacc stack overflow");
  1126. yyabort:
  1127.     return (1);
  1128. yyaccept:
  1129.     return (0);
  1130. }
  1131.