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