xref: /freebsd/contrib/byacc/btyaccpar.skel (revision 4d3fc8b0)
1/* $Id: btyaccpar.skel,v 1.13 2021/08/08 19:56:28 tom Exp $ */
2
3#include "defs.h"
4
5/*  If the skeleton is changed, the banner should be changed so that	*/
6/*  the altered version can be easily distinguished from the original.	*/
7/*									*/
8/*  The #defines included with the banner are there because they are	*/
9/*  useful in subsequent code.  The macros #defined in the header or	*/
10/*  the body either are not useful outside of semantic actions or	*/
11/*  are conditional.							*/
12
13%% banner
14/* original parser id follows */
15/* yysccsid[] = "@(#)yaccpar	1.9 (Berkeley) 02/21/93" */
16/* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */
17
18#define YYBYACC 1
19%% insert VERSION here
20
21#define YYEMPTY        (-1)
22#define yyclearin      (yychar = YYEMPTY)
23#define yyerrok        (yyerrflag = 0)
24#define YYRECOVERING() (yyerrflag != 0)
25#define YYENOMEM       (-2)
26#define YYEOF          0
27%% xdecls
28
29extern int YYPARSE_DECL();
30%% tables
31extern const YYINT yylhs[];
32extern const YYINT yylen[];
33extern const YYINT yydefred[];
34extern const YYINT yystos[];
35extern const YYINT yydgoto[];
36extern const YYINT yysindex[];
37extern const YYINT yyrindex[];
38%%ifdef YYBTYACC
39extern const YYINT yycindex[];
40%%endif
41extern const YYINT yygindex[];
42extern const YYINT yytable[];
43extern const YYINT yycheck[];
44%%ifdef YYBTYACC
45extern const YYINT yyctable[];
46%%endif
47
48#if YYDEBUG || defined(yytname)
49extern const char *const yyname[];
50#endif
51#if YYDEBUG
52extern const char *const yyrule[];
53#endif
54%% global_vars
55
56#if YYDEBUG
57int      yydebug;
58#endif
59%% impure_vars
60
61int      yyerrflag;
62int      yychar;
63YYSTYPE  yyval;
64YYSTYPE  yylval;
65int      yynerrs;
66
67#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
68YYLTYPE  yyloc; /* position returned by actions */
69YYLTYPE  yylloc; /* position from the lexer */
70#endif
71%% hdr_defs
72
73#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
74#ifndef YYLLOC_DEFAULT
75#define YYLLOC_DEFAULT(loc, rhs, n) \
76do \
77{ \
78    if (n == 0) \
79    { \
80        (loc).first_line   = YYRHSLOC(rhs, 0).last_line; \
81        (loc).first_column = YYRHSLOC(rhs, 0).last_column; \
82        (loc).last_line    = YYRHSLOC(rhs, 0).last_line; \
83        (loc).last_column  = YYRHSLOC(rhs, 0).last_column; \
84    } \
85    else \
86    { \
87        (loc).first_line   = YYRHSLOC(rhs, 1).first_line; \
88        (loc).first_column = YYRHSLOC(rhs, 1).first_column; \
89        (loc).last_line    = YYRHSLOC(rhs, n).last_line; \
90        (loc).last_column  = YYRHSLOC(rhs, n).last_column; \
91    } \
92} while (0)
93#endif /* YYLLOC_DEFAULT */
94#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
95%%ifdef YYBTYACC
96
97#ifndef YYLVQUEUEGROWTH
98#define YYLVQUEUEGROWTH 32
99#endif
100%%endif
101
102/* define the initial stack-sizes */
103#ifdef YYSTACKSIZE
104#undef YYMAXDEPTH
105#define YYMAXDEPTH  YYSTACKSIZE
106#else
107#ifdef YYMAXDEPTH
108#define YYSTACKSIZE YYMAXDEPTH
109#else
110#define YYSTACKSIZE 10000
111#define YYMAXDEPTH  10000
112#endif
113#endif
114
115#ifndef YYINITSTACKSIZE
116#define YYINITSTACKSIZE 200
117#endif
118
119typedef struct {
120    unsigned stacksize;
121    YYINT    *s_base;
122    YYINT    *s_mark;
123    YYINT    *s_last;
124    YYSTYPE  *l_base;
125    YYSTYPE  *l_mark;
126#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
127    YYLTYPE  *p_base;
128    YYLTYPE  *p_mark;
129#endif
130} YYSTACKDATA;
131%%ifdef YYBTYACC
132
133struct YYParseState_s
134{
135    struct YYParseState_s *save;    /* Previously saved parser state */
136    YYSTACKDATA            yystack; /* saved parser stack */
137    int                    state;   /* saved parser state */
138    int                    errflag; /* saved error recovery status */
139    int                    lexeme;  /* saved index of the conflict lexeme in the lexical queue */
140    YYINT                  ctry;    /* saved index in yyctable[] for this conflict */
141};
142typedef struct YYParseState_s YYParseState;
143%%endif YYBTYACC
144%% hdr_vars
145/* variables for the parser stack */
146static YYSTACKDATA yystack;
147%%ifdef YYBTYACC
148
149/* Current parser state */
150static YYParseState *yyps = 0;
151
152/* yypath != NULL: do the full parse, starting at *yypath parser state. */
153static YYParseState *yypath = 0;
154
155/* Base of the lexical value queue */
156static YYSTYPE *yylvals = 0;
157
158/* Current position at lexical value queue */
159static YYSTYPE *yylvp = 0;
160
161/* End position of lexical value queue */
162static YYSTYPE *yylve = 0;
163
164/* The last allocated position at the lexical value queue */
165static YYSTYPE *yylvlim = 0;
166
167#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
168/* Base of the lexical position queue */
169static YYLTYPE *yylpsns = 0;
170
171/* Current position at lexical position queue */
172static YYLTYPE *yylpp = 0;
173
174/* End position of lexical position queue */
175static YYLTYPE *yylpe = 0;
176
177/* The last allocated position at the lexical position queue */
178static YYLTYPE *yylplim = 0;
179#endif
180
181/* Current position at lexical token queue */
182static YYINT  *yylexp = 0;
183
184static YYINT  *yylexemes = 0;
185%%endif YYBTYACC
186%% body_vars
187    int      yyerrflag;
188    int      yychar;
189    YYSTYPE  yyval;
190    YYSTYPE  yylval;
191    int      yynerrs;
192
193#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
194    YYLTYPE  yyloc; /* position returned by actions */
195    YYLTYPE  yylloc; /* position from the lexer */
196#endif
197
198    /* variables for the parser stack */
199    YYSTACKDATA yystack;
200%%ifdef YYBTYACC
201
202    /* Current parser state */
203    static YYParseState *yyps = 0;
204
205    /* yypath != NULL: do the full parse, starting at *yypath parser state. */
206    static YYParseState *yypath = 0;
207
208    /* Base of the lexical value queue */
209    static YYSTYPE *yylvals = 0;
210
211    /* Current position at lexical value queue */
212    static YYSTYPE *yylvp = 0;
213
214    /* End position of lexical value queue */
215    static YYSTYPE *yylve = 0;
216
217    /* The last allocated position at the lexical value queue */
218    static YYSTYPE *yylvlim = 0;
219
220#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
221    /* Base of the lexical position queue */
222    static YYLTYPE *yylpsns = 0;
223
224    /* Current position at lexical position queue */
225    static YYLTYPE *yylpp = 0;
226
227    /* End position of lexical position queue */
228    static YYLTYPE *yylpe = 0;
229
230    /* The last allocated position at the lexical position queue */
231    static YYLTYPE *yylplim = 0;
232#endif
233
234    /* Current position at lexical token queue */
235    static YYINT  *yylexp = 0;
236
237    static YYINT  *yylexemes = 0;
238%%endif YYBTYACC
239%% body_1
240
241/* For use in generated program */
242#define yydepth (int)(yystack.s_mark - yystack.s_base)
243%%ifdef YYBTYACC
244#define yytrial (yyps->save)
245%%endif
246
247#if YYDEBUG
248#include <stdio.h>	/* needed for printf */
249#endif
250
251#include <stdlib.h>	/* needed for malloc, etc */
252#include <string.h>	/* needed for memset */
253
254/* allocate initial stack or double stack size, up to YYMAXDEPTH */
255static int yygrowstack(YYSTACKDATA *data)
256{
257    int i;
258    unsigned newsize;
259    YYINT *newss;
260    YYSTYPE *newvs;
261#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
262    YYLTYPE *newps;
263#endif
264
265    if ((newsize = data->stacksize) == 0)
266        newsize = YYINITSTACKSIZE;
267    else if (newsize >= YYMAXDEPTH)
268        return YYENOMEM;
269    else if ((newsize *= 2) > YYMAXDEPTH)
270        newsize = YYMAXDEPTH;
271
272    i = (int) (data->s_mark - data->s_base);
273    newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss));
274    if (newss == NULL)
275        return YYENOMEM;
276
277    data->s_base = newss;
278    data->s_mark = newss + i;
279
280    newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
281    if (newvs == NULL)
282        return YYENOMEM;
283
284    data->l_base = newvs;
285    data->l_mark = newvs + i;
286
287#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
288    newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
289    if (newps == NULL)
290        return YYENOMEM;
291
292    data->p_base = newps;
293    data->p_mark = newps + i;
294#endif
295
296    data->stacksize = newsize;
297    data->s_last = data->s_base + newsize - 1;
298
299#if YYDEBUG
300    if (yydebug)
301        fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
302#endif
303    return 0;
304}
305
306#if YYPURE || defined(YY_NO_LEAKS)
307static void yyfreestack(YYSTACKDATA *data)
308{
309    free(data->s_base);
310    free(data->l_base);
311#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
312    free(data->p_base);
313#endif
314    memset(data, 0, sizeof(*data));
315}
316#else
317#define yyfreestack(data) /* nothing */
318#endif /* YYPURE || defined(YY_NO_LEAKS) */
319%%ifdef YYBTYACC
320
321static YYParseState *
322yyNewState(unsigned size)
323{
324    YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
325    if (p == NULL) return NULL;
326
327    p->yystack.stacksize = size;
328    if (size == 0)
329    {
330        p->yystack.s_base = NULL;
331        p->yystack.l_base = NULL;
332#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
333        p->yystack.p_base = NULL;
334#endif
335        return p;
336    }
337    p->yystack.s_base    = (YYINT *) malloc(size * sizeof(YYINT));
338    if (p->yystack.s_base == NULL) return NULL;
339    p->yystack.l_base    = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
340    if (p->yystack.l_base == NULL) return NULL;
341    memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
342#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
343    p->yystack.p_base    = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
344    if (p->yystack.p_base == NULL) return NULL;
345    memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
346#endif
347
348    return p;
349}
350
351static void
352yyFreeState(YYParseState *p)
353{
354    yyfreestack(&p->yystack);
355    free(p);
356}
357%%endif YYBTYACC
358
359#define YYABORT  goto yyabort
360#define YYREJECT goto yyabort
361#define YYACCEPT goto yyaccept
362#define YYERROR  goto yyerrlab
363%%ifdef YYBTYACC
364#define YYVALID        do { if (yyps->save)            goto yyvalid; } while(0)
365#define YYVALID_NESTED do { if (yyps->save && \
366                                yyps->save->save == 0) goto yyvalid; } while(0)
367%%endif
368
369int
370YYPARSE_DECL()
371{
372%% body_2
373    int yym, yyn, yystate, yyresult;
374%%ifdef YYBTYACC
375    int yynewerrflag;
376    YYParseState *yyerrctx = NULL;
377%%endif
378#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
379    YYLTYPE  yyerror_loc_range[3]; /* position of error start/end (0 unused) */
380#endif
381#if YYDEBUG
382    const char *yys;
383
384    if ((yys = getenv("YYDEBUG")) != NULL)
385    {
386        yyn = *yys;
387        if (yyn >= '0' && yyn <= '9')
388            yydebug = yyn - '0';
389    }
390    if (yydebug)
391        fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
392#endif
393#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
394    memset(yyerror_loc_range, 0, sizeof(yyerror_loc_range));
395#endif
396
397%% init_vars
398    yyerrflag = 0;
399    yychar = 0;
400    memset(&yyval,  0, sizeof(yyval));
401    memset(&yylval, 0, sizeof(yylval));
402#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
403    memset(&yyloc,  0, sizeof(yyloc));
404    memset(&yylloc, 0, sizeof(yylloc));
405#endif
406
407%% body_3
408%%ifdef YYBTYACC
409    yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
410    yyps->save = 0;
411%%endif
412    yym = 0;
413    /* yyn is set below */
414    yynerrs = 0;
415    yyerrflag = 0;
416    yychar = YYEMPTY;
417    yystate = 0;
418
419#if YYPURE
420    memset(&yystack, 0, sizeof(yystack));
421#endif
422
423    if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
424    yystack.s_mark = yystack.s_base;
425    yystack.l_mark = yystack.l_base;
426#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
427    yystack.p_mark = yystack.p_base;
428#endif
429    yystate = 0;
430    *yystack.s_mark = 0;
431
432yyloop:
433    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
434    if (yychar < 0)
435    {
436%%ifdef YYBTYACC
437        do {
438        if (yylvp < yylve)
439        {
440            /* we're currently re-reading tokens */
441            yylval = *yylvp++;
442#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
443            yylloc = *yylpp++;
444#endif
445            yychar = *yylexp++;
446            break;
447        }
448        if (yyps->save)
449        {
450            /* in trial mode; save scanner results for future parse attempts */
451            if (yylvp == yylvlim)
452            {   /* Enlarge lexical value queue */
453                size_t p = (size_t) (yylvp - yylvals);
454                size_t s = (size_t) (yylvlim - yylvals);
455
456                s += YYLVQUEUEGROWTH;
457                if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL) goto yyenomem;
458                if ((yylvals   = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
459#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
460                if ((yylpsns   = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
461#endif
462                yylvp   = yylve = yylvals + p;
463                yylvlim = yylvals + s;
464#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
465                yylpp   = yylpe = yylpsns + p;
466                yylplim = yylpsns + s;
467#endif
468                yylexp  = yylexemes + p;
469            }
470            *yylexp = (YYINT) YYLEX;
471            *yylvp++ = yylval;
472            yylve++;
473#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
474            *yylpp++ = yylloc;
475            yylpe++;
476#endif
477            yychar = *yylexp++;
478            break;
479        }
480        /* normal operation, no conflict encountered */
481%%endif YYBTYACC
482        yychar = YYLEX;
483%%ifdef YYBTYACC
484        } while (0);
485%%endif
486        if (yychar < 0) yychar = YYEOF;
487#if YYDEBUG
488        if (yydebug)
489        {
490            if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
491            fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
492                            YYDEBUGSTR, yydepth, yystate, yychar, yys);
493#ifdef YYSTYPE_TOSTRING
494%%ifdef YYBTYACC
495            if (!yytrial)
496%%endif
497                fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
498#endif
499            fputc('\n', stderr);
500        }
501#endif
502    }
503%%ifdef YYBTYACC
504
505    /* Do we have a conflict? */
506    if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
507        yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
508    {
509        YYINT ctry;
510
511        if (yypath)
512        {
513            YYParseState *save;
514#if YYDEBUG
515            if (yydebug)
516                fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
517                                YYDEBUGSTR, yydepth, yystate);
518#endif
519            /* Switch to the next conflict context */
520            save = yypath;
521            yypath = save->save;
522            save->save = NULL;
523            ctry = save->ctry;
524            if (save->state != yystate) YYABORT;
525            yyFreeState(save);
526
527        }
528        else
529        {
530
531            /* Unresolved conflict - start/continue trial parse */
532            YYParseState *save;
533#if YYDEBUG
534            if (yydebug)
535            {
536                fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
537                if (yyps->save)
538                    fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
539                else
540                    fputs("Starting trial parse.\n", stderr);
541            }
542#endif
543            save                  = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
544            if (save == NULL) goto yyenomem;
545            save->save            = yyps->save;
546            save->state           = yystate;
547            save->errflag         = yyerrflag;
548            save->yystack.s_mark  = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
549            memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
550            save->yystack.l_mark  = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
551            memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
552#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
553            save->yystack.p_mark  = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
554            memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
555#endif
556            ctry                  = yytable[yyn];
557            if (yyctable[ctry] == -1)
558            {
559#if YYDEBUG
560                if (yydebug && yychar >= YYEOF)
561                    fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
562#endif
563                ctry++;
564            }
565            save->ctry = ctry;
566            if (yyps->save == NULL)
567            {
568                /* If this is a first conflict in the stack, start saving lexemes */
569                if (!yylexemes)
570                {
571                    yylexemes = (YYINT *) malloc((YYLVQUEUEGROWTH) * sizeof(YYINT));
572                    if (yylexemes == NULL) goto yyenomem;
573                    yylvals   = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
574                    if (yylvals == NULL) goto yyenomem;
575                    yylvlim   = yylvals + YYLVQUEUEGROWTH;
576#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
577                    yylpsns   = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
578                    if (yylpsns == NULL) goto yyenomem;
579                    yylplim   = yylpsns + YYLVQUEUEGROWTH;
580#endif
581                }
582                if (yylvp == yylve)
583                {
584                    yylvp  = yylve = yylvals;
585#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
586                    yylpp  = yylpe = yylpsns;
587#endif
588                    yylexp = yylexemes;
589                    if (yychar >= YYEOF)
590                    {
591                        *yylve++ = yylval;
592#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
593                        *yylpe++ = yylloc;
594#endif
595                        *yylexp  = (YYINT) yychar;
596                        yychar   = YYEMPTY;
597                    }
598                }
599            }
600            if (yychar >= YYEOF)
601            {
602                yylvp--;
603#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
604                yylpp--;
605#endif
606                yylexp--;
607                yychar = YYEMPTY;
608            }
609            save->lexeme = (int) (yylvp - yylvals);
610            yyps->save   = save;
611        }
612        if (yytable[yyn] == ctry)
613        {
614#if YYDEBUG
615            if (yydebug)
616                fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
617                                YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
618#endif
619            if (yychar < 0)
620            {
621                yylvp++;
622#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
623                yylpp++;
624#endif
625                yylexp++;
626            }
627            if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
628                goto yyoverflow;
629            yystate = yyctable[ctry];
630            *++yystack.s_mark = (YYINT) yystate;
631            *++yystack.l_mark = yylval;
632#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
633            *++yystack.p_mark = yylloc;
634#endif
635            yychar  = YYEMPTY;
636            if (yyerrflag > 0) --yyerrflag;
637            goto yyloop;
638        }
639        else
640        {
641            yyn = yyctable[ctry];
642            goto yyreduce;
643        }
644    } /* End of code dealing with conflicts */
645%%endif YYBTYACC
646    if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
647            yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
648    {
649#if YYDEBUG
650        if (yydebug)
651            fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
652                            YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
653#endif
654        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
655        yystate = yytable[yyn];
656        *++yystack.s_mark = yytable[yyn];
657        *++yystack.l_mark = yylval;
658#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
659        *++yystack.p_mark = yylloc;
660#endif
661        yychar = YYEMPTY;
662        if (yyerrflag > 0)  --yyerrflag;
663        goto yyloop;
664    }
665    if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
666            yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
667    {
668        yyn = yytable[yyn];
669        goto yyreduce;
670    }
671    if (yyerrflag != 0) goto yyinrecovery;
672%%ifdef YYBTYACC
673
674    yynewerrflag = 1;
675    goto yyerrhandler;
676    goto yyerrlab; /* redundant goto avoids 'unused label' warning */
677
678yyerrlab:
679    /* explicit YYERROR from an action -- pop the rhs of the rule reduced
680     * before looking for error recovery */
681    yystack.s_mark -= yym;
682    yystate = *yystack.s_mark;
683    yystack.l_mark -= yym;
684#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
685    yystack.p_mark -= yym;
686#endif
687
688    yynewerrflag = 0;
689yyerrhandler:
690    while (yyps->save)
691    {
692        int ctry;
693        YYParseState *save = yyps->save;
694#if YYDEBUG
695        if (yydebug)
696            fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
697                            YYDEBUGSTR, yydepth, yystate, yyps->save->state,
698                    (int)(yylvp - yylvals - yyps->save->lexeme));
699#endif
700        /* Memorize most forward-looking error state in case it's really an error. */
701        if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
702        {
703            /* Free old saved error context state */
704            if (yyerrctx) yyFreeState(yyerrctx);
705            /* Create and fill out new saved error context state */
706            yyerrctx                 = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
707            if (yyerrctx == NULL) goto yyenomem;
708            yyerrctx->save           = yyps->save;
709            yyerrctx->state          = yystate;
710            yyerrctx->errflag        = yyerrflag;
711            yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
712            memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
713            yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
714            memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
715#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
716            yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
717            memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
718#endif
719            yyerrctx->lexeme         = (int) (yylvp - yylvals);
720        }
721        yylvp          = yylvals   + save->lexeme;
722#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
723        yylpp          = yylpsns   + save->lexeme;
724#endif
725        yylexp         = yylexemes + save->lexeme;
726        yychar         = YYEMPTY;
727        yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
728        memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
729        yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
730        memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
731#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
732        yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
733        memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
734#endif
735        ctry           = ++save->ctry;
736        yystate        = save->state;
737        /* We tried shift, try reduce now */
738        if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
739        yyps->save     = save->save;
740        save->save     = NULL;
741        yyFreeState(save);
742
743        /* Nothing left on the stack -- error */
744        if (!yyps->save)
745        {
746#if YYDEBUG
747            if (yydebug)
748                fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
749                                YYPREFIX, yydepth);
750#endif
751            /* Restore state as it was in the most forward-advanced error */
752            yylvp          = yylvals   + yyerrctx->lexeme;
753#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
754            yylpp          = yylpsns   + yyerrctx->lexeme;
755#endif
756            yylexp         = yylexemes + yyerrctx->lexeme;
757            yychar         = yylexp[-1];
758            yylval         = yylvp[-1];
759#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
760            yylloc         = yylpp[-1];
761#endif
762            yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
763            memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
764            yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
765            memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
766#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
767            yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
768            memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
769#endif
770            yystate        = yyerrctx->state;
771            yyFreeState(yyerrctx);
772            yyerrctx       = NULL;
773        }
774        yynewerrflag = 1;
775    }
776    if (yynewerrflag == 0) goto yyinrecovery;
777%%endif YYBTYACC
778
779    YYERROR_CALL("syntax error");
780#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
781    yyerror_loc_range[1] = yylloc; /* lookahead position is error start position */
782#endif
783
784#if !YYBTYACC
785    goto yyerrlab; /* redundant goto avoids 'unused label' warning */
786yyerrlab:
787#endif
788    ++yynerrs;
789
790yyinrecovery:
791    if (yyerrflag < 3)
792    {
793        yyerrflag = 3;
794        for (;;)
795        {
796            if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
797                    yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
798            {
799#if YYDEBUG
800                if (yydebug)
801                    fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
802                                    YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
803#endif
804                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
805                yystate = yytable[yyn];
806                *++yystack.s_mark = yytable[yyn];
807                *++yystack.l_mark = yylval;
808#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
809                /* lookahead position is error end position */
810                yyerror_loc_range[2] = yylloc;
811                YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
812                *++yystack.p_mark = yyloc;
813#endif
814                goto yyloop;
815            }
816            else
817            {
818#if YYDEBUG
819                if (yydebug)
820                    fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
821                                    YYDEBUGSTR, yydepth, *yystack.s_mark);
822#endif
823                if (yystack.s_mark <= yystack.s_base) goto yyabort;
824#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
825                /* the current TOS position is the error start position */
826                yyerror_loc_range[1] = *yystack.p_mark;
827#endif
828#if defined(YYDESTRUCT_CALL)
829%%ifdef YYBTYACC
830                if (!yytrial)
831%%endif
832#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
833                    YYDESTRUCT_CALL("error: discarding state",
834                                    yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
835#else
836                    YYDESTRUCT_CALL("error: discarding state",
837                                    yystos[*yystack.s_mark], yystack.l_mark);
838#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
839#endif /* defined(YYDESTRUCT_CALL) */
840                --yystack.s_mark;
841                --yystack.l_mark;
842#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
843                --yystack.p_mark;
844#endif
845            }
846        }
847    }
848    else
849    {
850        if (yychar == YYEOF) goto yyabort;
851#if YYDEBUG
852        if (yydebug)
853        {
854            if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
855            fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
856                            YYDEBUGSTR, yydepth, yystate, yychar, yys);
857        }
858#endif
859#if defined(YYDESTRUCT_CALL)
860%%ifdef YYBTYACC
861        if (!yytrial)
862%%endif
863#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
864            YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
865#else
866            YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
867#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
868#endif /* defined(YYDESTRUCT_CALL) */
869        yychar = YYEMPTY;
870        goto yyloop;
871    }
872
873yyreduce:
874    yym = yylen[yyn];
875#if YYDEBUG
876    if (yydebug)
877    {
878        fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
879                        YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
880#ifdef YYSTYPE_TOSTRING
881%%ifdef YYBTYACC
882        if (!yytrial)
883%%endif
884            if (yym > 0)
885            {
886                int i;
887                fputc('<', stderr);
888                for (i = yym; i > 0; i--)
889                {
890                    if (i != yym) fputs(", ", stderr);
891                    fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
892                                           yystack.l_mark[1-i]), stderr);
893                }
894                fputc('>', stderr);
895            }
896#endif
897        fputc('\n', stderr);
898    }
899#endif
900    if (yym > 0)
901        yyval = yystack.l_mark[1-yym];
902    else
903        memset(&yyval, 0, sizeof yyval);
904#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
905
906    /* Perform position reduction */
907    memset(&yyloc, 0, sizeof(yyloc));
908%%ifdef YYBTYACC
909    if (!yytrial)
910%%endif
911    {
912        YYLLOC_DEFAULT(yyloc, &yystack.p_mark[-yym], yym);
913        /* just in case YYERROR is invoked within the action, save
914           the start of the rhs as the error start position */
915        yyerror_loc_range[1] = yystack.p_mark[1-yym];
916    }
917#endif
918
919    switch (yyn)
920    {
921%% trailer
922    default:
923        break;
924    }
925    yystack.s_mark -= yym;
926    yystate = *yystack.s_mark;
927    yystack.l_mark -= yym;
928#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
929    yystack.p_mark -= yym;
930#endif
931    yym = yylhs[yyn];
932    if (yystate == 0 && yym == 0)
933    {
934#if YYDEBUG
935        if (yydebug)
936        {
937            fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
938#ifdef YYSTYPE_TOSTRING
939%%ifdef YYBTYACC
940            if (!yytrial)
941%%endif
942                fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
943#endif
944            fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
945        }
946#endif
947        yystate = YYFINAL;
948        *++yystack.s_mark = YYFINAL;
949        *++yystack.l_mark = yyval;
950#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
951        *++yystack.p_mark = yyloc;
952#endif
953        if (yychar < 0)
954        {
955%%ifdef YYBTYACC
956            do {
957            if (yylvp < yylve)
958            {
959                /* we're currently re-reading tokens */
960                yylval = *yylvp++;
961#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
962                yylloc = *yylpp++;
963#endif
964                yychar = *yylexp++;
965                break;
966            }
967            if (yyps->save)
968            {
969                /* in trial mode; save scanner results for future parse attempts */
970                if (yylvp == yylvlim)
971                {   /* Enlarge lexical value queue */
972                    size_t p = (size_t) (yylvp - yylvals);
973                    size_t s = (size_t) (yylvlim - yylvals);
974
975                    s += YYLVQUEUEGROWTH;
976                    if ((yylexemes = (YYINT *)realloc(yylexemes, s * sizeof(YYINT))) == NULL)
977                        goto yyenomem;
978                    if ((yylvals   = (YYSTYPE *)realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
979                        goto yyenomem;
980#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
981                    if ((yylpsns   = (YYLTYPE *)realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
982                        goto yyenomem;
983#endif
984                    yylvp   = yylve = yylvals + p;
985                    yylvlim = yylvals + s;
986#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
987                    yylpp   = yylpe = yylpsns + p;
988                    yylplim = yylpsns + s;
989#endif
990                    yylexp  = yylexemes + p;
991                }
992                *yylexp = (YYINT) YYLEX;
993                *yylvp++ = yylval;
994                yylve++;
995#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
996                *yylpp++ = yylloc;
997                yylpe++;
998#endif
999                yychar = *yylexp++;
1000                break;
1001            }
1002            /* normal operation, no conflict encountered */
1003%%endif YYBTYACC
1004            yychar = YYLEX;
1005%%ifdef YYBTYACC
1006            } while (0);
1007%%endif
1008            if (yychar < 0) yychar = YYEOF;
1009#if YYDEBUG
1010            if (yydebug)
1011            {
1012                if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
1013                fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n",
1014                                YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
1015            }
1016#endif
1017        }
1018        if (yychar == YYEOF) goto yyaccept;
1019        goto yyloop;
1020    }
1021    if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1022            yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1023        yystate = yytable[yyn];
1024    else
1025        yystate = yydgoto[yym];
1026#if YYDEBUG
1027    if (yydebug)
1028    {
1029        fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1030#ifdef YYSTYPE_TOSTRING
1031%%ifdef YYBTYACC
1032        if (!yytrial)
1033%%endif
1034            fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1035#endif
1036        fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1037    }
1038#endif
1039    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1040    *++yystack.s_mark = (YYINT) yystate;
1041    *++yystack.l_mark = yyval;
1042#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1043    *++yystack.p_mark = yyloc;
1044#endif
1045    goto yyloop;
1046%%ifdef YYBTYACC
1047
1048    /* Reduction declares that this path is valid. Set yypath and do a full parse */
1049yyvalid:
1050    if (yypath) YYABORT;
1051    while (yyps->save)
1052    {
1053        YYParseState *save = yyps->save;
1054        yyps->save = save->save;
1055        save->save = yypath;
1056        yypath = save;
1057    }
1058#if YYDEBUG
1059    if (yydebug)
1060        fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1061                        YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1062#endif
1063    if (yyerrctx)
1064    {
1065        yyFreeState(yyerrctx);
1066        yyerrctx = NULL;
1067    }
1068    yylvp          = yylvals + yypath->lexeme;
1069#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1070    yylpp          = yylpsns + yypath->lexeme;
1071#endif
1072    yylexp         = yylexemes + yypath->lexeme;
1073    yychar         = YYEMPTY;
1074    yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1075    memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1076    yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1077    memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1078#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1079    yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1080    memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1081#endif
1082    yystate        = yypath->state;
1083    goto yyloop;
1084%%endif YYBTYACC
1085
1086yyoverflow:
1087    YYERROR_CALL("yacc stack overflow");
1088%%ifdef YYBTYACC
1089    goto yyabort_nomem;
1090yyenomem:
1091    YYERROR_CALL("memory exhausted");
1092yyabort_nomem:
1093%%endif
1094    yyresult = 2;
1095    goto yyreturn;
1096
1097yyabort:
1098    yyresult = 1;
1099    goto yyreturn;
1100
1101yyaccept:
1102%%ifdef YYBTYACC
1103    if (yyps->save) goto yyvalid;
1104%%endif
1105    yyresult = 0;
1106
1107yyreturn:
1108#if defined(YYDESTRUCT_CALL)
1109    if (yychar != YYEOF && yychar != YYEMPTY)
1110#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1111        YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1112#else
1113        YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1114#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1115
1116    {
1117        YYSTYPE *pv;
1118#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1119        YYLTYPE *pp;
1120
1121        for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1122             YYDESTRUCT_CALL("cleanup: discarding state",
1123                             yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1124#else
1125        for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1126             YYDESTRUCT_CALL("cleanup: discarding state",
1127                             yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1128#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1129    }
1130#endif /* defined(YYDESTRUCT_CALL) */
1131
1132%%ifdef YYBTYACC
1133    if (yyerrctx)
1134    {
1135        yyFreeState(yyerrctx);
1136        yyerrctx = NULL;
1137    }
1138    while (yyps)
1139    {
1140        YYParseState *save = yyps;
1141        yyps = save->save;
1142        save->save = NULL;
1143        yyFreeState(save);
1144    }
1145    while (yypath)
1146    {
1147        YYParseState *save = yypath;
1148        yypath = save->save;
1149        save->save = NULL;
1150        yyFreeState(save);
1151    }
1152%%endif YYBTYACC
1153    yyfreestack(&yystack);
1154    return (yyresult);
1155}
1156