1 /* A Bison parser, made from gram.y
2    by GNU bison 1.35.  */
3 
4 #define YYBISON 1  /* Identify Bison output.  */
5 
6 # define	CTRL_ASSIGN	257
7 # define	CTRL_IGNORE	258
8 # define	OPEN	259
9 # define	CLOSE	260
10 # define	REVERSE	261
11 # define	STARTCLASS	262
12 # define	LET	263
13 # define	TAG	264
14 # define	SYMBOL	265
15 # define	REMARK	266
16 # define	NL	267
17 
18 #line 1 "gram.y"
19 
20 #include "mkfa.h"
21 #define YYSTYPE char *
22 #define CLASS_NUM 100
23 
24 void appendNonTerm( char *name, int modeAssign );
25 BODY *setNonTerm( void );
26 CLASS *entryNonTerm( char *name, BODY *body, int modeAccpt, int start, int member, int tmp );
27 void pushBody( CLASS *class, BODY *newbody );
28 int unifyBody( char *name, BODY *body, BODY *newbody );
29 char *getNewClassName( char *keyname );
30 void outputHeader( char *name );
31 char *chkNoInstantClass( void );
32 
33 extern CLASS *ClassList;
34 extern CLASS *ClassListTail;
35 extern CLASS *StartSymbol;
36 extern int NoNewLine;
37 extern char GramFile[ 1024 ];
38 extern char HeaderFile[ 1024 ];
39 extern int SW_Compati;
40 extern int SW_Quiet;
41 extern int SW_SemiQuiet;
42 extern char VerNo[];
43 static char HeadName[ SYMBOL_LEN ];
44 static char BodyName[ CLASS_NUM ][ SYMBOL_LEN ];
45 static int BodyNo = 0;
46 static int ClassNo = 0;
47 static int ModeAssignAccptFlag = 1;
48 static int BlockReverseSw;
49 static int ModeBlock = 0;
50 static int CurClassNo = 0;
51 static int StartFlag = 0;
52 static FILE *FPheader;
53 static int ErrParse = 0;
54 static int GramModifyNum = 0;
55 #ifndef YYSTYPE
56 # define YYSTYPE int
57 # define YYSTYPE_IS_TRIVIAL 1
58 #endif
59 #ifndef YYDEBUG
60 # define YYDEBUG 0
61 #endif
62 
63 
64 
65 #define	YYFINAL		43
66 #define	YYFLAG		-32768
67 #define	YYNTBASE	14
68 
69 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
70 #define YYTRANSLATE(x) ((unsigned)(x) <= 267 ? yytranslate[x] : 27)
71 
72 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
73 static const char yytranslate[] =
74 {
75        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
76        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
77        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
78        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
79        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
80        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
81        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
82        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
83        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
84        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
85        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
86        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
87        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
88        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
89        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
90        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
91        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
92        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
93        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
94        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
95        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
96        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
97        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
98        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
99        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
100        2,     2,     2,     2,     2,     2,     1,     3,     4,     5,
101        6,     7,     8,     9,    10,    11,    12,    13
102 };
103 
104 #if YYDEBUG
105 static const short yyprhs[] =
106 {
107        0,     0,     2,     5,     7,     9,    11,    13,    16,    23,
108       25,    28,    30,    33,    35,    38,    40,    42,    45,    50,
109       52,    55,    57,    60,    62,    65,    67,    69
110 };
111 static const short yyrhs[] =
112 {
113       15,     0,    15,    14,     0,    16,     0,    20,     0,    25,
114        0,    26,     0,     1,    13,     0,    17,     5,    26,    18,
115        6,    26,     0,    10,     0,     7,    10,     0,    19,     0,
116       19,    18,     0,    21,     0,    23,    26,     0,    26,     0,
117       21,     0,     7,    21,     0,    23,     9,    22,    26,     0,
118       24,     0,    24,    22,     0,    11,     0,     8,    11,     0,
119       11,     0,     3,    26,     0,     4,     0,    12,     0,    13,
120        0
121 };
122 
123 #endif
124 
125 #if YYDEBUG
126 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
127 static const short yyrline[] =
128 {
129        0,    55,    55,    57,    57,    57,    57,    58,    63,    65,
130       70,    76,    76,    78,    82,    86,    88,    92,    97,    99,
131       99,   101,   105,   111,   116,   120,   125,   125
132 };
133 #endif
134 
135 
136 #if (YYDEBUG) || defined YYERROR_VERBOSE
137 
138 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
139 static const char *const yytname[] =
140 {
141   "$", "error", "$undefined.", "CTRL_ASSIGN", "CTRL_IGNORE", "OPEN",
142   "CLOSE", "REVERSE", "STARTCLASS", "LET", "TAG", "SYMBOL", "REMARK",
143   "NL", "src", "statement", "block", "tag", "members", "member", "single",
144   "define", "bodies", "head", "body", "contol", "remark", 0
145 };
146 #endif
147 
148 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
149 static const short yyr1[] =
150 {
151        0,    14,    14,    15,    15,    15,    15,    15,    16,    17,
152       17,    18,    18,    19,    19,    19,    20,    20,    21,    22,
153       22,    23,    23,    24,    25,    25,    26,    26
154 };
155 
156 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
157 static const short yyr2[] =
158 {
159        0,     1,     2,     1,     1,     1,     1,     2,     6,     1,
160        2,     1,     2,     1,     2,     1,     1,     2,     4,     1,
161        2,     1,     2,     1,     2,     1,     1,     1
162 };
163 
164 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
165    doesn't specify something else to do.  Zero means the default is an
166    error. */
167 static const short yydefact[] =
168 {
169        0,     0,     0,    25,     0,     0,     9,    21,    26,    27,
170        0,     3,     0,     4,    16,     0,     5,     6,     7,    24,
171       10,    17,    22,     2,     0,     0,     0,    23,     0,    19,
172        0,    11,    13,     0,    15,    18,    20,     0,    12,    14,
173        8,     0,     0,     0
174 };
175 
176 static const short yydefgoto[] =
177 {
178       23,    10,    11,    12,    30,    31,    13,    14,    28,    15,
179       29,    16,    17
180 };
181 
182 static const short yypact[] =
183 {
184       29,    14,     5,-32768,    36,     0,-32768,-32768,-32768,-32768,
185        2,-32768,    20,-32768,-32768,    25,-32768,-32768,-32768,-32768,
186   -32768,-32768,-32768,-32768,     5,    34,     8,-32768,     5,    34,
187       42,     8,-32768,    -5,-32768,-32768,-32768,     5,-32768,-32768,
188   -32768,    49,    50,-32768
189 };
190 
191 static const short yypgoto[] =
192 {
193       51,-32768,-32768,-32768,    21,-32768,-32768,    -3,    24,    12,
194   -32768,-32768,    -2
195 };
196 
197 
198 #define	YYLAST		53
199 
200 
201 static const short yytable[] =
202 {
203       19,    21,    -1,     1,    25,     2,     3,     8,     9,     4,
204        5,    22,     6,     7,     8,     9,     5,     8,     9,     7,
205        8,     9,    26,    32,    34,    24,    35,    18,    32,    34,
206        1,    39,     2,     3,    25,    40,     4,     5,    33,     6,
207        7,     8,     9,    33,     5,    27,    20,     7,    37,    42,
208       43,    41,    38,    36
209 };
210 
211 static const short yycheck[] =
212 {
213        2,     4,     0,     1,     9,     3,     4,    12,    13,     7,
214        8,    11,    10,    11,    12,    13,     8,    12,    13,    11,
215       12,    13,    24,    26,    26,     5,    28,    13,    31,    31,
216        1,    33,     3,     4,     9,    37,     7,     8,    26,    10,
217       11,    12,    13,    31,     8,    11,    10,    11,     6,     0,
218        0,     0,    31,    29
219 };
220 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
221 #line 3 "/usr/share/bison/bison.simple"
222 
223 /* Skeleton output parser for bison,
224 
225    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
226    Foundation, Inc.
227 
228    This program is free software; you can redistribute it and/or modify
229    it under the terms of the GNU General Public License as published by
230    the Free Software Foundation; either version 2, or (at your option)
231    any later version.
232 
233    This program is distributed in the hope that it will be useful,
234    but WITHOUT ANY WARRANTY; without even the implied warranty of
235    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
236    GNU General Public License for more details.
237 
238    You should have received a copy of the GNU General Public License
239    along with this program; if not, write to the Free Software
240    Foundation, Inc., 59 Temple Place - Suite 330,
241    Boston, MA 02111-1307, USA.  */
242 
243 /* As a special exception, when this file is copied by Bison into a
244    Bison output file, you may use that output file without restriction.
245    This special exception was added by the Free Software Foundation
246    in version 1.24 of Bison.  */
247 
248 /* This is the parser code that is written into each bison parser when
249    the %semantic_parser declaration is not specified in the grammar.
250    It was written by Richard Stallman by simplifying the hairy parser
251    used when %semantic_parser is specified.  */
252 
253 /* All symbols defined below should begin with yy or YY, to avoid
254    infringing on user name space.  This should be done even for local
255    variables, as they might otherwise be expanded by user macros.
256    There are some unavoidable exceptions within include files to
257    define necessary library symbols; they are noted "INFRINGES ON
258    USER NAME SPACE" below.  */
259 
260 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
261 
262 /* The parser invokes alloca or malloc; define the necessary symbols.  */
263 
264 # if YYSTACK_USE_ALLOCA
265 #  define YYSTACK_ALLOC alloca
266 # else
267 #  ifndef YYSTACK_USE_ALLOCA
268 #   if defined (alloca) || defined (_ALLOCA_H)
269 #    define YYSTACK_ALLOC alloca
270 #   else
271 #    ifdef __GNUC__
272 #     define YYSTACK_ALLOC __builtin_alloca
273 #    endif
274 #   endif
275 #  endif
276 # endif
277 
278 # ifdef YYSTACK_ALLOC
279    /* Pacify GCC's `empty if-body' warning. */
280 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
281 # else
282 #  if defined (__STDC__) || defined (__cplusplus)
283 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
284 #   define YYSIZE_T size_t
285 #  endif
286 #  define YYSTACK_ALLOC malloc
287 #  define YYSTACK_FREE free
288 # endif
289 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
290 
291 
292 #if (! defined (yyoverflow) \
293      && (! defined (__cplusplus) \
294 	 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
295 
296 /* A type that is properly aligned for any stack member.  */
297 union yyalloc
298 {
299   short yyss;
300   YYSTYPE yyvs;
301 # if YYLSP_NEEDED
302   YYLTYPE yyls;
303 # endif
304 };
305 
306 /* The size of the maximum gap between one aligned stack and the next.  */
307 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
308 
309 /* The size of an array large to enough to hold all stacks, each with
310    N elements.  */
311 # if YYLSP_NEEDED
312 #  define YYSTACK_BYTES(N) \
313      ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))	\
314       + 2 * YYSTACK_GAP_MAX)
315 # else
316 #  define YYSTACK_BYTES(N) \
317      ((N) * (sizeof (short) + sizeof (YYSTYPE))				\
318       + YYSTACK_GAP_MAX)
319 # endif
320 
321 /* Copy COUNT objects from FROM to TO.  The source and destination do
322    not overlap.  */
323 # ifndef YYCOPY
324 #  if 1 < __GNUC__
325 #   define YYCOPY(To, From, Count) \
326       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
327 #  else
328 #   define YYCOPY(To, From, Count)		\
329       do					\
330 	{					\
331 	  register YYSIZE_T yyi;		\
332 	  for (yyi = 0; yyi < (Count); yyi++)	\
333 	    (To)[yyi] = (From)[yyi];		\
334 	}					\
335       while (0)
336 #  endif
337 # endif
338 
339 /* Relocate STACK from its old location to the new one.  The
340    local variables YYSIZE and YYSTACKSIZE give the old and new number of
341    elements in the stack, and YYPTR gives the new location of the
342    stack.  Advance YYPTR to a properly aligned location for the next
343    stack.  */
344 # define YYSTACK_RELOCATE(Stack)					\
345     do									\
346       {									\
347 	YYSIZE_T yynewbytes;						\
348 	YYCOPY (&yyptr->Stack, Stack, yysize);				\
349 	Stack = &yyptr->Stack;						\
350 	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX;	\
351 	yyptr += yynewbytes / sizeof (*yyptr);				\
352       }									\
353     while (0)
354 
355 #endif
356 
357 
358 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
359 # define YYSIZE_T __SIZE_TYPE__
360 #endif
361 #if ! defined (YYSIZE_T) && defined (size_t)
362 # define YYSIZE_T size_t
363 #endif
364 #if ! defined (YYSIZE_T)
365 # if defined (__STDC__) || defined (__cplusplus)
366 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
367 #  define YYSIZE_T size_t
368 # endif
369 #endif
370 #if ! defined (YYSIZE_T)
371 # define YYSIZE_T unsigned int
372 #endif
373 
374 #define yyerrok		(yyerrstatus = 0)
375 #define yyclearin	(yychar = YYEMPTY)
376 #define YYEMPTY		-2
377 #define YYEOF		0
378 #define YYACCEPT	goto yyacceptlab
379 #define YYABORT 	goto yyabortlab
380 #define YYERROR		goto yyerrlab1
381 /* Like YYERROR except do call yyerror.  This remains here temporarily
382    to ease the transition to the new meaning of YYERROR, for GCC.
383    Once GCC version 2 has supplanted version 1, this can go.  */
384 #define YYFAIL		goto yyerrlab
385 #define YYRECOVERING()  (!!yyerrstatus)
386 #define YYBACKUP(Token, Value)					\
387 do								\
388   if (yychar == YYEMPTY && yylen == 1)				\
389     {								\
390       yychar = (Token);						\
391       yylval = (Value);						\
392       yychar1 = YYTRANSLATE (yychar);				\
393       YYPOPSTACK;						\
394       goto yybackup;						\
395     }								\
396   else								\
397     { 								\
398       yyerror ("syntax error: cannot back up");			\
399       YYERROR;							\
400     }								\
401 while (0)
402 
403 #define YYTERROR	1
404 #define YYERRCODE	256
405 
406 
407 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
408    are run).
409 
410    When YYLLOC_DEFAULT is run, CURRENT is set the location of the
411    first token.  By default, to implement support for ranges, extend
412    its range to the last symbol.  */
413 
414 #ifndef YYLLOC_DEFAULT
415 # define YYLLOC_DEFAULT(Current, Rhs, N)       	\
416    Current.last_line   = Rhs[N].last_line;	\
417    Current.last_column = Rhs[N].last_column;
418 #endif
419 
420 
421 /* YYLEX -- calling `yylex' with the right arguments.  */
422 
423 #if YYPURE
424 # if YYLSP_NEEDED
425 #  ifdef YYLEX_PARAM
426 #   define YYLEX		yylex (&yylval, &yylloc, YYLEX_PARAM)
427 #  else
428 #   define YYLEX		yylex (&yylval, &yylloc)
429 #  endif
430 # else /* !YYLSP_NEEDED */
431 #  ifdef YYLEX_PARAM
432 #   define YYLEX		yylex (&yylval, YYLEX_PARAM)
433 #  else
434 #   define YYLEX		yylex (&yylval)
435 #  endif
436 # endif /* !YYLSP_NEEDED */
437 #else /* !YYPURE */
438 # define YYLEX			yylex ()
439 #endif /* !YYPURE */
440 
441 
442 /* Enable debugging if requested.  */
443 #if YYDEBUG
444 
445 # ifndef YYFPRINTF
446 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
447 #  define YYFPRINTF fprintf
448 # endif
449 
450 # define YYDPRINTF(Args)			\
451 do {						\
452   if (yydebug)					\
453     YYFPRINTF Args;				\
454 } while (0)
455 /* Nonzero means print parse trace.  It is left uninitialized so that
456    multiple parsers can coexist.  */
457 int yydebug;
458 #else /* !YYDEBUG */
459 # define YYDPRINTF(Args)
460 #endif /* !YYDEBUG */
461 
462 /* YYINITDEPTH -- initial size of the parser's stacks.  */
463 #ifndef	YYINITDEPTH
464 # define YYINITDEPTH 200
465 #endif
466 
467 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
468    if the built-in stack extension method is used).
469 
470    Do not make this value too large; the results are undefined if
471    SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
472    evaluated with infinite-precision integer arithmetic.  */
473 
474 #if YYMAXDEPTH == 0
475 # undef YYMAXDEPTH
476 #endif
477 
478 #ifndef YYMAXDEPTH
479 # define YYMAXDEPTH 10000
480 #endif
481 
482 #ifdef YYERROR_VERBOSE
483 
484 # ifndef yystrlen
485 #  if defined (__GLIBC__) && defined (_STRING_H)
486 #   define yystrlen strlen
487 #  else
488 /* Return the length of YYSTR.  */
489 static YYSIZE_T
490 #   if defined (__STDC__) || defined (__cplusplus)
yystrlen(const char * yystr)491 yystrlen (const char *yystr)
492 #   else
493 yystrlen (yystr)
494      const char *yystr;
495 #   endif
496 {
497   register const char *yys = yystr;
498 
499   while (*yys++ != '\0')
500     continue;
501 
502   return yys - yystr - 1;
503 }
504 #  endif
505 # endif
506 
507 # ifndef yystpcpy
508 #  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
509 #   define yystpcpy stpcpy
510 #  else
511 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
512    YYDEST.  */
513 static char *
514 #   if defined (__STDC__) || defined (__cplusplus)
yystpcpy(char * yydest,const char * yysrc)515 yystpcpy (char *yydest, const char *yysrc)
516 #   else
517 yystpcpy (yydest, yysrc)
518      char *yydest;
519      const char *yysrc;
520 #   endif
521 {
522   register char *yyd = yydest;
523   register const char *yys = yysrc;
524 
525   while ((*yyd++ = *yys++) != '\0')
526     continue;
527 
528   return yyd - 1;
529 }
530 #  endif
531 # endif
532 #endif
533 
534 #line 315 "/usr/share/bison/bison.simple"
535 
536 
537 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
538    into yyparse.  The argument should have type void *.
539    It should actually point to an object.
540    Grammar actions can access the variable by casting it
541    to the proper pointer type.  */
542 
543 #ifdef YYPARSE_PARAM
544 # if defined (__STDC__) || defined (__cplusplus)
545 #  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
546 #  define YYPARSE_PARAM_DECL
547 # else
548 #  define YYPARSE_PARAM_ARG YYPARSE_PARAM
549 #  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
550 # endif
551 #else /* !YYPARSE_PARAM */
552 # define YYPARSE_PARAM_ARG
553 # define YYPARSE_PARAM_DECL
554 #endif /* !YYPARSE_PARAM */
555 
556 /* Prevent warning if -Wstrict-prototypes.  */
557 #ifdef __GNUC__
558 # ifdef YYPARSE_PARAM
559 int yyparse (void *);
560 # else
561 int yyparse (void);
562 # endif
563 #endif
564 
565 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
566    variables are global, or local to YYPARSE.  */
567 
568 #define YY_DECL_NON_LSP_VARIABLES			\
569 /* The lookahead symbol.  */				\
570 int yychar;						\
571 							\
572 /* The semantic value of the lookahead symbol. */	\
573 YYSTYPE yylval;						\
574 							\
575 /* Number of parse errors so far.  */			\
576 int yynerrs;
577 
578 #if YYLSP_NEEDED
579 # define YY_DECL_VARIABLES			\
580 YY_DECL_NON_LSP_VARIABLES			\
581 						\
582 /* Location data for the lookahead symbol.  */	\
583 YYLTYPE yylloc;
584 #else
585 # define YY_DECL_VARIABLES			\
586 YY_DECL_NON_LSP_VARIABLES
587 #endif
588 
589 
590 /* If nonreentrant, generate the variables here. */
591 
592 #if !YYPURE
593 YY_DECL_VARIABLES
594 #endif  /* !YYPURE */
595 
596 int
yyparse(YYPARSE_PARAM_ARG)597 yyparse (YYPARSE_PARAM_ARG)
598      YYPARSE_PARAM_DECL
599 {
600   /* If reentrant, generate the variables here. */
601 #if YYPURE
602   YY_DECL_VARIABLES
603 #endif  /* !YYPURE */
604 
605   register int yystate;
606   register int yyn;
607   int yyresult;
608   /* Number of tokens to shift before error messages enabled.  */
609   int yyerrstatus;
610   /* Lookahead token as an internal (translated) token number.  */
611   int yychar1 = 0;
612 
613   /* Three stacks and their tools:
614      `yyss': related to states,
615      `yyvs': related to semantic values,
616      `yyls': related to locations.
617 
618      Refer to the stacks thru separate pointers, to allow yyoverflow
619      to reallocate them elsewhere.  */
620 
621   /* The state stack. */
622   short	yyssa[YYINITDEPTH];
623   short *yyss = yyssa;
624   register short *yyssp;
625 
626   /* The semantic value stack.  */
627   YYSTYPE yyvsa[YYINITDEPTH];
628   YYSTYPE *yyvs = yyvsa;
629   register YYSTYPE *yyvsp;
630 
631 #if YYLSP_NEEDED
632   /* The location stack.  */
633   YYLTYPE yylsa[YYINITDEPTH];
634   YYLTYPE *yyls = yylsa;
635   YYLTYPE *yylsp;
636 #endif
637 
638 #if YYLSP_NEEDED
639 # define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
640 #else
641 # define YYPOPSTACK   (yyvsp--, yyssp--)
642 #endif
643 
644   YYSIZE_T yystacksize = YYINITDEPTH;
645 
646 
647   /* The variables used to return semantic value and location from the
648      action routines.  */
649   YYSTYPE yyval;
650 #if YYLSP_NEEDED
651   YYLTYPE yyloc;
652 #endif
653 
654   /* When reducing, the number of symbols on the RHS of the reduced
655      rule. */
656   int yylen;
657 
658   YYDPRINTF ((stderr, "Starting parse\n"));
659 
660   yystate = 0;
661   yyerrstatus = 0;
662   yynerrs = 0;
663   yychar = YYEMPTY;		/* Cause a token to be read.  */
664 
665   /* Initialize stack pointers.
666      Waste one element of value and location stack
667      so that they stay on the same level as the state stack.
668      The wasted elements are never initialized.  */
669 
670   yyssp = yyss;
671   yyvsp = yyvs;
672 #if YYLSP_NEEDED
673   yylsp = yyls;
674 #endif
675   goto yysetstate;
676 
677 /*------------------------------------------------------------.
678 | yynewstate -- Push a new state, which is found in yystate.  |
679 `------------------------------------------------------------*/
680  yynewstate:
681   /* In all cases, when you get here, the value and location stacks
682      have just been pushed. so pushing a state here evens the stacks.
683      */
684   yyssp++;
685 
686  yysetstate:
687   *yyssp = yystate;
688 
689   if (yyssp >= yyss + yystacksize - 1)
690     {
691       /* Get the current used size of the three stacks, in elements.  */
692       YYSIZE_T yysize = yyssp - yyss + 1;
693 
694 #ifdef yyoverflow
695       {
696 	/* Give user a chance to reallocate the stack. Use copies of
697 	   these so that the &'s don't force the real ones into
698 	   memory.  */
699 	YYSTYPE *yyvs1 = yyvs;
700 	short *yyss1 = yyss;
701 
702 	/* Each stack pointer address is followed by the size of the
703 	   data in use in that stack, in bytes.  */
704 # if YYLSP_NEEDED
705 	YYLTYPE *yyls1 = yyls;
706 	/* This used to be a conditional around just the two extra args,
707 	   but that might be undefined if yyoverflow is a macro.  */
708 	yyoverflow ("parser stack overflow",
709 		    &yyss1, yysize * sizeof (*yyssp),
710 		    &yyvs1, yysize * sizeof (*yyvsp),
711 		    &yyls1, yysize * sizeof (*yylsp),
712 		    &yystacksize);
713 	yyls = yyls1;
714 # else
715 	yyoverflow ("parser stack overflow",
716 		    &yyss1, yysize * sizeof (*yyssp),
717 		    &yyvs1, yysize * sizeof (*yyvsp),
718 		    &yystacksize);
719 # endif
720 	yyss = yyss1;
721 	yyvs = yyvs1;
722       }
723 #else /* no yyoverflow */
724 # ifndef YYSTACK_RELOCATE
725       goto yyoverflowlab;
726 # else
727       /* Extend the stack our own way.  */
728       if (yystacksize >= YYMAXDEPTH)
729 	goto yyoverflowlab;
730       yystacksize *= 2;
731       if (yystacksize > YYMAXDEPTH)
732 	yystacksize = YYMAXDEPTH;
733 
734       {
735 	short *yyss1 = yyss;
736 	union yyalloc *yyptr =
737 	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
738 	if (! yyptr)
739 	  goto yyoverflowlab;
740 	YYSTACK_RELOCATE (yyss);
741 	YYSTACK_RELOCATE (yyvs);
742 # if YYLSP_NEEDED
743 	YYSTACK_RELOCATE (yyls);
744 # endif
745 # undef YYSTACK_RELOCATE
746 	if (yyss1 != yyssa)
747 	  YYSTACK_FREE (yyss1);
748       }
749 # endif
750 #endif /* no yyoverflow */
751 
752       yyssp = yyss + yysize - 1;
753       yyvsp = yyvs + yysize - 1;
754 #if YYLSP_NEEDED
755       yylsp = yyls + yysize - 1;
756 #endif
757 
758       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
759 		  (unsigned long int) yystacksize));
760 
761       if (yyssp >= yyss + yystacksize - 1)
762 	YYABORT;
763     }
764 
765   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
766 
767   goto yybackup;
768 
769 
770 /*-----------.
771 | yybackup.  |
772 `-----------*/
773 yybackup:
774 
775 /* Do appropriate processing given the current state.  */
776 /* Read a lookahead token if we need one and don't already have one.  */
777 /* yyresume: */
778 
779   /* First try to decide what to do without reference to lookahead token.  */
780 
781   yyn = yypact[yystate];
782   if (yyn == YYFLAG)
783     goto yydefault;
784 
785   /* Not known => get a lookahead token if don't already have one.  */
786 
787   /* yychar is either YYEMPTY or YYEOF
788      or a valid token in external form.  */
789 
790   if (yychar == YYEMPTY)
791     {
792       YYDPRINTF ((stderr, "Reading a token: "));
793       yychar = YYLEX;
794     }
795 
796   /* Convert token to internal form (in yychar1) for indexing tables with */
797 
798   if (yychar <= 0)		/* This means end of input. */
799     {
800       yychar1 = 0;
801       yychar = YYEOF;		/* Don't call YYLEX any more */
802 
803       YYDPRINTF ((stderr, "Now at end of input.\n"));
804     }
805   else
806     {
807       yychar1 = YYTRANSLATE (yychar);
808 
809 #if YYDEBUG
810      /* We have to keep this `#if YYDEBUG', since we use variables
811 	which are defined only if `YYDEBUG' is set.  */
812       if (yydebug)
813 	{
814 	  YYFPRINTF (stderr, "Next token is %d (%s",
815 		     yychar, yytname[yychar1]);
816 	  /* Give the individual parser a way to print the precise
817 	     meaning of a token, for further debugging info.  */
818 # ifdef YYPRINT
819 	  YYPRINT (stderr, yychar, yylval);
820 # endif
821 	  YYFPRINTF (stderr, ")\n");
822 	}
823 #endif
824     }
825 
826   yyn += yychar1;
827   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
828     goto yydefault;
829 
830   yyn = yytable[yyn];
831 
832   /* yyn is what to do for this token type in this state.
833      Negative => reduce, -yyn is rule number.
834      Positive => shift, yyn is new state.
835        New state is final state => don't bother to shift,
836        just return success.
837      0, or most negative number => error.  */
838 
839   if (yyn < 0)
840     {
841       if (yyn == YYFLAG)
842 	goto yyerrlab;
843       yyn = -yyn;
844       goto yyreduce;
845     }
846   else if (yyn == 0)
847     goto yyerrlab;
848 
849   if (yyn == YYFINAL)
850     YYACCEPT;
851 
852   /* Shift the lookahead token.  */
853   YYDPRINTF ((stderr, "Shifting token %d (%s), ",
854 	      yychar, yytname[yychar1]));
855 
856   /* Discard the token being shifted unless it is eof.  */
857   if (yychar != YYEOF)
858     yychar = YYEMPTY;
859 
860   *++yyvsp = yylval;
861 #if YYLSP_NEEDED
862   *++yylsp = yylloc;
863 #endif
864 
865   /* Count tokens shifted since error; after three, turn off error
866      status.  */
867   if (yyerrstatus)
868     yyerrstatus--;
869 
870   yystate = yyn;
871   goto yynewstate;
872 
873 
874 /*-----------------------------------------------------------.
875 | yydefault -- do the default action for the current state.  |
876 `-----------------------------------------------------------*/
877 yydefault:
878   yyn = yydefact[yystate];
879   if (yyn == 0)
880     goto yyerrlab;
881   goto yyreduce;
882 
883 
884 /*-----------------------------.
885 | yyreduce -- Do a reduction.  |
886 `-----------------------------*/
887 yyreduce:
888   /* yyn is the number of a rule to reduce with.  */
889   yylen = yyr2[yyn];
890 
891   /* If YYLEN is nonzero, implement the default value of the action:
892      `$$ = $1'.
893 
894      Otherwise, the following line sets YYVAL to the semantic value of
895      the lookahead token.  This behavior is undocumented and Bison
896      users should not rely upon it.  Assigning to YYVAL
897      unconditionally makes the parser a bit smaller, and it avoids a
898      GCC warning that YYVAL may be used uninitialized.  */
899   yyval = yyvsp[1-yylen];
900 
901 #if YYLSP_NEEDED
902   /* Similarly for the default location.  Let the user run additional
903      commands if for instance locations are ranges.  */
904   yyloc = yylsp[1-yylen];
905   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
906 #endif
907 
908 #if YYDEBUG
909   /* We have to keep this `#if YYDEBUG', since we use variables which
910      are defined only if `YYDEBUG' is set.  */
911   if (yydebug)
912     {
913       int yyi;
914 
915       YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
916 		 yyn, yyrline[yyn]);
917 
918       /* Print the symbols being reduced, and their result.  */
919       for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
920 	YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
921       YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
922     }
923 #endif
924 
925   switch (yyn) {
926 
927 case 7:
928 #line 59 "gram.y"
929 {
930     yyerrok;
931 ;
932     break;}
933 case 9:
934 #line 66 "gram.y"
935 {
936     BlockReverseSw = 0;
937     if( ModeAssignAccptFlag ) outputHeader( yyvsp[0] );
938 ;
939     break;}
940 case 10:
941 #line 71 "gram.y"
942 {
943     BlockReverseSw = 1;
944     if( !ModeAssignAccptFlag ) outputHeader( yyvsp[0] );
945 ;
946     break;}
947 case 13:
948 #line 79 "gram.y"
949 {
950     appendNonTerm( HeadName, ModeAssignAccptFlag ^ BlockReverseSw );
951 ;
952     break;}
953 case 14:
954 #line 83 "gram.y"
955 {
956     entryNonTerm( HeadName, NULL, ModeAssignAccptFlag ^ BlockReverseSw, 0, 1, 0 ); /*$B6uEPO?(B*/
957 ;
958     break;}
959 case 16:
960 #line 89 "gram.y"
961 {
962     appendNonTerm( HeadName, ModeAssignAccptFlag );
963 ;
964     break;}
965 case 17:
966 #line 93 "gram.y"
967 {
968     appendNonTerm( HeadName, !ModeAssignAccptFlag );
969 ;
970     break;}
971 case 21:
972 #line 102 "gram.y"
973 {
974     strcpy( HeadName, yyvsp[0] );
975 ;
976     break;}
977 case 22:
978 #line 106 "gram.y"
979 {
980     StartFlag = 1;
981     strcpy( HeadName, yyvsp[0] );
982 ;
983     break;}
984 case 23:
985 #line 112 "gram.y"
986 {
987     strcpy( BodyName[ BodyNo++ ], yyvsp[0] );
988 ;
989     break;}
990 case 24:
991 #line 117 "gram.y"
992 {
993     ModeAssignAccptFlag = 1;
994 ;
995     break;}
996 case 25:
997 #line 121 "gram.y"
998 {
999     ModeAssignAccptFlag = 0;
1000 ;
1001     break;}
1002 }
1003 
1004 #line 705 "/usr/share/bison/bison.simple"
1005 
1006 
1007   yyvsp -= yylen;
1008   yyssp -= yylen;
1009 #if YYLSP_NEEDED
1010   yylsp -= yylen;
1011 #endif
1012 
1013 #if YYDEBUG
1014   if (yydebug)
1015     {
1016       short *yyssp1 = yyss - 1;
1017       YYFPRINTF (stderr, "state stack now");
1018       while (yyssp1 != yyssp)
1019 	YYFPRINTF (stderr, " %d", *++yyssp1);
1020       YYFPRINTF (stderr, "\n");
1021     }
1022 #endif
1023 
1024   *++yyvsp = yyval;
1025 #if YYLSP_NEEDED
1026   *++yylsp = yyloc;
1027 #endif
1028 
1029   /* Now `shift' the result of the reduction.  Determine what state
1030      that goes to, based on the state we popped back to and the rule
1031      number reduced by.  */
1032 
1033   yyn = yyr1[yyn];
1034 
1035   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1036   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1037     yystate = yytable[yystate];
1038   else
1039     yystate = yydefgoto[yyn - YYNTBASE];
1040 
1041   goto yynewstate;
1042 
1043 
1044 /*------------------------------------.
1045 | yyerrlab -- here on detecting error |
1046 `------------------------------------*/
1047 yyerrlab:
1048   /* If not already recovering from an error, report this error.  */
1049   if (!yyerrstatus)
1050     {
1051       ++yynerrs;
1052 
1053 #ifdef YYERROR_VERBOSE
1054       yyn = yypact[yystate];
1055 
1056       if (yyn > YYFLAG && yyn < YYLAST)
1057 	{
1058 	  YYSIZE_T yysize = 0;
1059 	  char *yymsg;
1060 	  int yyx, yycount;
1061 
1062 	  yycount = 0;
1063 	  /* Start YYX at -YYN if negative to avoid negative indexes in
1064 	     YYCHECK.  */
1065 	  for (yyx = yyn < 0 ? -yyn : 0;
1066 	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1067 	    if (yycheck[yyx + yyn] == yyx)
1068 	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1069 	  yysize += yystrlen ("parse error, unexpected ") + 1;
1070 	  yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
1071 	  yymsg = (char *) YYSTACK_ALLOC (yysize);
1072 	  if (yymsg != 0)
1073 	    {
1074 	      char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
1075 	      yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
1076 
1077 	      if (yycount < 5)
1078 		{
1079 		  yycount = 0;
1080 		  for (yyx = yyn < 0 ? -yyn : 0;
1081 		       yyx < (int) (sizeof (yytname) / sizeof (char *));
1082 		       yyx++)
1083 		    if (yycheck[yyx + yyn] == yyx)
1084 		      {
1085 			const char *yyq = ! yycount ? ", expecting " : " or ";
1086 			yyp = yystpcpy (yyp, yyq);
1087 			yyp = yystpcpy (yyp, yytname[yyx]);
1088 			yycount++;
1089 		      }
1090 		}
1091 	      yyerror (yymsg);
1092 	      YYSTACK_FREE (yymsg);
1093 	    }
1094 	  else
1095 	    yyerror ("parse error; also virtual memory exhausted");
1096 	}
1097       else
1098 #endif /* defined (YYERROR_VERBOSE) */
1099 	yyerror ("parse error");
1100     }
1101   goto yyerrlab1;
1102 
1103 
1104 /*--------------------------------------------------.
1105 | yyerrlab1 -- error raised explicitly by an action |
1106 `--------------------------------------------------*/
1107 yyerrlab1:
1108   if (yyerrstatus == 3)
1109     {
1110       /* If just tried and failed to reuse lookahead token after an
1111 	 error, discard it.  */
1112 
1113       /* return failure if at end of input */
1114       if (yychar == YYEOF)
1115 	YYABORT;
1116       YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
1117 		  yychar, yytname[yychar1]));
1118       yychar = YYEMPTY;
1119     }
1120 
1121   /* Else will try to reuse lookahead token after shifting the error
1122      token.  */
1123 
1124   yyerrstatus = 3;		/* Each real token shifted decrements this */
1125 
1126   goto yyerrhandle;
1127 
1128 
1129 /*-------------------------------------------------------------------.
1130 | yyerrdefault -- current state does not do anything special for the |
1131 | error token.                                                       |
1132 `-------------------------------------------------------------------*/
1133 yyerrdefault:
1134 #if 0
1135   /* This is wrong; only states that explicitly want error tokens
1136      should shift them.  */
1137 
1138   /* If its default is to accept any token, ok.  Otherwise pop it.  */
1139   yyn = yydefact[yystate];
1140   if (yyn)
1141     goto yydefault;
1142 #endif
1143 
1144 
1145 /*---------------------------------------------------------------.
1146 | yyerrpop -- pop the current state because it cannot handle the |
1147 | error token                                                    |
1148 `---------------------------------------------------------------*/
1149 yyerrpop:
1150   if (yyssp == yyss)
1151     YYABORT;
1152   yyvsp--;
1153   yystate = *--yyssp;
1154 #if YYLSP_NEEDED
1155   yylsp--;
1156 #endif
1157 
1158 #if YYDEBUG
1159   if (yydebug)
1160     {
1161       short *yyssp1 = yyss - 1;
1162       YYFPRINTF (stderr, "Error: state stack now");
1163       while (yyssp1 != yyssp)
1164 	YYFPRINTF (stderr, " %d", *++yyssp1);
1165       YYFPRINTF (stderr, "\n");
1166     }
1167 #endif
1168 
1169 /*--------------.
1170 | yyerrhandle.  |
1171 `--------------*/
1172 yyerrhandle:
1173   yyn = yypact[yystate];
1174   if (yyn == YYFLAG)
1175     goto yyerrdefault;
1176 
1177   yyn += YYTERROR;
1178   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1179     goto yyerrdefault;
1180 
1181   yyn = yytable[yyn];
1182   if (yyn < 0)
1183     {
1184       if (yyn == YYFLAG)
1185 	goto yyerrpop;
1186       yyn = -yyn;
1187       goto yyreduce;
1188     }
1189   else if (yyn == 0)
1190     goto yyerrpop;
1191 
1192   if (yyn == YYFINAL)
1193     YYACCEPT;
1194 
1195   YYDPRINTF ((stderr, "Shifting error token, "));
1196 
1197   *++yyvsp = yylval;
1198 #if YYLSP_NEEDED
1199   *++yylsp = yylloc;
1200 #endif
1201 
1202   yystate = yyn;
1203   goto yynewstate;
1204 
1205 
1206 /*-------------------------------------.
1207 | yyacceptlab -- YYACCEPT comes here.  |
1208 `-------------------------------------*/
1209 yyacceptlab:
1210   yyresult = 0;
1211   goto yyreturn;
1212 
1213 /*-----------------------------------.
1214 | yyabortlab -- YYABORT comes here.  |
1215 `-----------------------------------*/
1216 yyabortlab:
1217   yyresult = 1;
1218   goto yyreturn;
1219 
1220 /*---------------------------------------------.
1221 | yyoverflowab -- parser overflow comes here.  |
1222 `---------------------------------------------*/
1223 yyoverflowlab:
1224   yyerror ("parser stack overflow");
1225   yyresult = 2;
1226   /* Fall through.  */
1227 
1228 yyreturn:
1229 #ifndef yyoverflow
1230   if (yyss != yyssa)
1231     YYSTACK_FREE (yyss);
1232 #endif
1233   return yyresult;
1234 }
1235 #line 127 "gram.y"
1236 
1237 #include "lex.yy.c"
appendNonTerm(char * name,int modeAssign)1238 void appendNonTerm( char *name, int modeAssign )
1239 {
1240     BODY *body;
1241 
1242     body = setNonTerm();
1243     entryNonTerm( name, body, modeAssign, StartFlag, ModeBlock, 0 );
1244     BodyNo = 0;
1245 }
1246 
setNonTerm(void)1247 BODY *setNonTerm( void )
1248 {
1249     int i;
1250     BODY *body;
1251     BODY *top = NULL, *prev = NULL;
1252 
1253     for( i = 0; i < BodyNo; i++ ){
1254 	if( (body = malloc( sizeof(BODY) )) == NULL ){
1255 	    errMes( "Can't alloc nonterminal list buffer" );
1256 	}
1257 	strcpy( body->name, BodyName[ i ] );
1258 	body->abort = 0;
1259 	if( prev != NULL ){
1260 	    prev->next = body;
1261 	} else {
1262 	    top = body;
1263 	}
1264 	prev = body;
1265     }
1266     body->next = NULL;
1267     return( top );
1268 }
1269 
entryNonTerm(char * name,BODY * body,int modeAccpt,int start,int member,int tmp)1270 CLASS *entryNonTerm( char *name, BODY *body, int modeAccpt, int start, int member, int tmp )
1271 {
1272     CLASS *class;
1273 
1274     class = getClass( name );
1275     if( class != NULL ){
1276 	if( member ){
1277 	    errMes("Accepted flag of class \"%s\" is re-assigned", HeadName );
1278 	    ErrParse++;
1279 	}
1280     } else {
1281 	if( (class = malloc( sizeof(CLASS) )) == NULL ){
1282 	    errMes( "Can't alloc memory for Class Finite Automaton." );
1283 	}
1284 	strcpy( class->name, name );
1285 	if( modeAccpt ){
1286 	    if( member ){
1287 		class->no = CurClassNo;
1288 	    } else {
1289 		if( !tmp ){
1290 		    outputHeader( name );
1291 		    class->no = CurClassNo;
1292 		}
1293 	    }
1294 	} else {
1295 	    class->no = -1;
1296 	}
1297 	class->branch = 0;
1298 	class->usedFA = 0;
1299 	class->used = 1;	/* non-terminal does not appear in voca */
1300 	class->bodyList = NULL;
1301 	class->tmp = tmp;
1302 	class->next = NULL;
1303 	if( ClassListTail == NULL ){
1304 	    ClassList = class;
1305 	} else {
1306 	    ClassListTail->next = class;
1307 	}
1308 	ClassListTail = class;
1309     }
1310     if( body != NULL ) pushBody( class, body );
1311     if( start ){
1312 	StartFlag = 0;
1313 	if( StartSymbol == NULL ){
1314 	    StartSymbol = class;
1315 	} else {
1316 	    errMes("Start symbol is redifined as \"%s\"", class->name );
1317 	    ErrParse++;
1318 	}
1319     }
1320     return( class );
1321 }
1322 
pushBody(CLASS * class,BODY * newbody)1323 void pushBody( CLASS *class, BODY *newbody )
1324 {
1325     BODYLIST *bodyList = class->bodyList;
1326     BODYLIST *preBodyList = NULL;
1327     BODYLIST *newBodyList;
1328     BODY *body;
1329     int cmp;
1330     int defineNo = 1;
1331 
1332     while( bodyList != NULL ){
1333 	body = bodyList->body;
1334 	cmp = strcmp( body->name, newbody->name );
1335 	if( cmp > 0 ) break;
1336 	if( cmp == 0 ){
1337 	    if( unifyBody( class->name, body, newbody ) ){
1338 		warnMes( "Class \"%s\" is defined as \"%s..\" again.", class->name, body->name );
1339 	    }
1340 	    return;
1341 	}
1342 	preBodyList = bodyList;
1343 	bodyList = bodyList->next;
1344 	defineNo++;
1345     }
1346     if( (newBodyList = malloc( sizeof(BODYLIST) )) == NULL ){
1347 	errMes( "Can't alloc class body buffer." );
1348     }
1349     newBodyList->body = newbody;
1350 
1351     if( preBodyList != NULL ){
1352 	preBodyList->next = newBodyList;
1353     } else {
1354 	class->bodyList = newBodyList;
1355     }
1356     newBodyList->next = bodyList;
1357     class->branch++;
1358 }
1359 
unifyBody(char * className,BODY * body,BODY * newbody)1360 int unifyBody( char *className, BODY *body, BODY *newbody )
1361 {
1362     BODY *bodyNext, *newbodyNext;
1363     char *newClassName;
1364     BODY *newBody;
1365     CLASS *class;
1366 
1367     bodyNext = body->next;
1368     newbodyNext = newbody->next;
1369     while( 1 ){
1370 	if( bodyNext == NULL && newbodyNext == NULL ){
1371 	    return( -1 );
1372 	}
1373 	if( newbodyNext == NULL ){
1374 	    if( body->abort ){
1375 		return( -1 );
1376 	    } else {
1377 		body->abort = 1;
1378 		return( 0 );
1379 	    }
1380 	}
1381 	if( bodyNext == NULL ){
1382 	    body->abort = 1;
1383 	    body->next = newbodyNext;
1384 	    return( 0 );
1385 	}
1386 	if( strcmp( bodyNext->name, newbodyNext->name ) ) break;
1387 	body = bodyNext;
1388 	newbody = newbodyNext;
1389 	bodyNext = body->next;
1390 	newbodyNext = newbody->next;
1391     }
1392     class = getClass( body->name );
1393     if( class != NULL && class->tmp ){
1394 	entryNonTerm( body->name, newbodyNext, 0, 0, 0, 1 );
1395     } else {
1396 	newClassName = getNewClassName( className );
1397 	entryNonTerm( newClassName, bodyNext, 0, 0, 0, 1 );
1398 	entryNonTerm( newClassName, newbodyNext, 0, 0, 0, 1 );
1399 	if( (newBody = malloc( sizeof(BODY) )) == NULL ){
1400 	    errMes( "Can't alloc body buffer of tmp class, \"%s\".", newClassName );
1401 	}
1402 	strcpy( newBody->name, newClassName );
1403 	newBody->abort = 0;
1404 	newBody->next = NULL;
1405 	body->next = newBody;
1406 	newbody->next = newBody;
1407     }
1408     return( 0 );
1409 }
1410 
getNewClassName(char * keyname)1411 char *getNewClassName( char *keyname )
1412 {
1413     static char classname[ SYMBOL_LEN ];
1414     static int tmpClassNo = 0;
1415 
1416     sprintf( classname, "%s#%d", keyname , tmpClassNo++ );
1417     if( !SW_SemiQuiet ){
1418 	fprintf( stderr, "\rNow modifying grammar to minimize states[%d]", GramModifyNum );
1419 	NoNewLine = 1;
1420     }
1421     GramModifyNum++;
1422     return( classname );
1423 }
1424 
setGram(void)1425 void setGram( void )
1426 {
1427     char *name;
1428 
1429     if( (yyin = fopen( GramFile, "r" )) == NULL ){
1430 	errMes( "Can't open grammar file \"%s\"", GramFile );
1431     }
1432     if( SW_Compati ){
1433 	strcpy( HeaderFile, "/dev/null" );
1434     }
1435     if( (FPheader = fopen( HeaderFile, "w" )) == NULL ){
1436 	errMes( "Can't open Header File for writting\"%s\"", HeaderFile );
1437     }
1438     fprintf( FPheader,
1439 	    "/* Header of class reduction flag for finite automaton parser\n"
1440 	    "                    made with mkfa %s\n\n"
1441 	    "        Do logicalAND between label and FA's field #4,#5.\n"
1442 	    "*/\n\n", VerNo
1443 	    );
1444     if( !SW_Quiet ) fputs( "Now parsing grammar file\n", stderr );
1445     yyparse();
1446     if( !SW_Quiet ){
1447 	fprintf( stderr, "\rNow modifying grammar to minimize states[%d]\n", GramModifyNum - 1 );
1448 	NoNewLine = 0;
1449     }
1450     if( StartSymbol == NULL ) StartSymbol = ClassList;
1451     fprintf( FPheader, "/* Start Symbol: %s */\n", StartSymbol->name );
1452     fclose( FPheader );
1453     if( (name = chkNoInstantClass()) != NULL ){
1454 	errMes( "Prototype-declared Class \"%s\" has no instant definitions", name );
1455     }
1456     if( ErrParse ) errMes( "%d fatal errors exist", ErrParse );
1457 }
1458 
outputHeader(char * name)1459 void outputHeader( char *name )
1460 {
1461     if( ClassNo >= CLASSFLAG_MAX ){
1462 	if( !SW_Compati ){
1463 	    warnMes( "Class accepted flag overflow.\"%s\"", name );
1464 	    CurClassNo = -1;
1465 	}
1466     } else {
1467 	if( !SW_Compati ){
1468 	    fprintf( FPheader, "#define ACCEPT_%s 0x%08x\n",
1469 		    name, 1 << ClassNo );
1470 	}
1471 	CurClassNo = ClassNo++;
1472     }
1473 }
1474 
chkNoInstantClass(void)1475 char *chkNoInstantClass( void )
1476 {
1477     CLASS *class = ClassList;
1478 
1479     while( class != NULL ){
1480 	if( !class->branch ) return( class->name );
1481 	class = class->next;
1482     }
1483     return( NULL );
1484 }
1485 
yyerror(char * mes)1486 int yyerror( char *mes )
1487 {
1488     errMes(mes );
1489     ErrParse++;
1490     return( 0 );
1491 }
1492