home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / develope / mpwflexp.sit / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  28.3 KB  |  1,137 lines

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