xref: /freebsd/contrib/byacc/btyaccpar.skel (revision 5dae51da3da0cc94d17bd67b308fad304ebec7e0)
1/* $Id: btyaccpar.skel,v 1.3 2016/06/06 23:35:55 Tom.Shields 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 short  *yylexp = 0;
180
181static short  *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 short  *yylexp = 0;
231
232    static short  *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%%ifdef YYBTYACC
390    yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
391    yyps->save = 0;
392%%endif
393    yym = 0;
394    yyn = 0;
395    yynerrs = 0;
396    yyerrflag = 0;
397    yychar = YYEMPTY;
398    yystate = 0;
399
400#if YYPURE
401    memset(&yystack, 0, sizeof(yystack));
402#endif
403
404    if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
405    yystack.s_mark = yystack.s_base;
406    yystack.l_mark = yystack.l_base;
407#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
408    yystack.p_mark = yystack.p_base;
409#endif
410    yystate = 0;
411    *yystack.s_mark = 0;
412
413yyloop:
414    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
415    if (yychar < 0)
416    {
417%%ifdef YYBTYACC
418        do {
419        if (yylvp < yylve)
420        {
421            /* we're currently re-reading tokens */
422            yylval = *yylvp++;
423#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
424            yylloc = *yylpp++;
425#endif
426            yychar = *yylexp++;
427            break;
428        }
429        if (yyps->save)
430        {
431            /* in trial mode; save scanner results for future parse attempts */
432            if (yylvp == yylvlim)
433            {   /* Enlarge lexical value queue */
434                size_t p = (size_t) (yylvp - yylvals);
435                size_t s = (size_t) (yylvlim - yylvals);
436
437                s += YYLVQUEUEGROWTH;
438                if ((yylexemes = (short *)   realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem;
439                if ((yylvals   = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
440#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
441                if ((yylpsns   = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
442#endif
443                yylvp   = yylve = yylvals + p;
444                yylvlim = yylvals + s;
445#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
446                yylpp   = yylpe = yylpsns + p;
447                yylplim = yylpsns + s;
448#endif
449                yylexp  = yylexemes + p;
450            }
451            *yylexp = (short) YYLEX;
452            *yylvp++ = yylval;
453            yylve++;
454#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
455            *yylpp++ = yylloc;
456            yylpe++;
457#endif
458            yychar = *yylexp++;
459            break;
460        }
461        /* normal operation, no conflict encountered */
462%%endif YYBTYACC
463        yychar = YYLEX;
464%%ifdef YYBTYACC
465        } while (0);
466%%endif
467        if (yychar < 0) yychar = YYEOF;
468#if YYDEBUG
469        if (yydebug)
470        {
471            if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
472            fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
473                            YYDEBUGSTR, yydepth, yystate, yychar, yys);
474#ifdef YYSTYPE_TOSTRING
475%%ifdef YYBTYACC
476            if (!yytrial)
477%%endif
478                fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
479#endif
480            fputc('\n', stderr);
481        }
482#endif
483    }
484%%ifdef YYBTYACC
485
486    /* Do we have a conflict? */
487    if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
488        yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
489    {
490        YYINT ctry;
491
492        if (yypath)
493        {
494            YYParseState *save;
495#if YYDEBUG
496            if (yydebug)
497                fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
498                                YYDEBUGSTR, yydepth, yystate);
499#endif
500            /* Switch to the next conflict context */
501            save = yypath;
502            yypath = save->save;
503            save->save = NULL;
504            ctry = save->ctry;
505            if (save->state != yystate) YYABORT;
506            yyFreeState(save);
507
508        }
509        else
510        {
511
512            /* Unresolved conflict - start/continue trial parse */
513            YYParseState *save;
514#if YYDEBUG
515            if (yydebug)
516            {
517                fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
518                if (yyps->save)
519                    fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
520                else
521                    fputs("Starting trial parse.\n", stderr);
522            }
523#endif
524            save                  = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
525            if (save == NULL) goto yyenomem;
526            save->save            = yyps->save;
527            save->state           = yystate;
528            save->errflag         = yyerrflag;
529            save->yystack.s_mark  = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
530            memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
531            save->yystack.l_mark  = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
532            memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
533#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
534            save->yystack.p_mark  = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
535            memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
536#endif
537            ctry                  = yytable[yyn];
538            if (yyctable[ctry] == -1)
539            {
540#if YYDEBUG
541                if (yydebug && yychar >= YYEOF)
542                    fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
543#endif
544                ctry++;
545            }
546            save->ctry = ctry;
547            if (yyps->save == NULL)
548            {
549                /* If this is a first conflict in the stack, start saving lexemes */
550                if (!yylexemes)
551                {
552                    yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short));
553                    if (yylexemes == NULL) goto yyenomem;
554                    yylvals   = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
555                    if (yylvals == NULL) goto yyenomem;
556                    yylvlim   = yylvals + YYLVQUEUEGROWTH;
557#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
558                    yylpsns   = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
559                    if (yylpsns == NULL) goto yyenomem;
560                    yylplim   = yylpsns + YYLVQUEUEGROWTH;
561#endif
562                }
563                if (yylvp == yylve)
564                {
565                    yylvp  = yylve = yylvals;
566#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
567                    yylpp  = yylpe = yylpsns;
568#endif
569                    yylexp = yylexemes;
570                    if (yychar >= YYEOF)
571                    {
572                        *yylve++ = yylval;
573#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
574                        *yylpe++ = yylloc;
575#endif
576                        *yylexp  = (short) yychar;
577                        yychar   = YYEMPTY;
578                    }
579                }
580            }
581            if (yychar >= YYEOF)
582            {
583                yylvp--;
584#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
585                yylpp--;
586#endif
587                yylexp--;
588                yychar = YYEMPTY;
589            }
590            save->lexeme = (int) (yylvp - yylvals);
591            yyps->save   = save;
592        }
593        if (yytable[yyn] == ctry)
594        {
595#if YYDEBUG
596            if (yydebug)
597                fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
598                                YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
599#endif
600            if (yychar < 0)
601            {
602                yylvp++;
603#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
604                yylpp++;
605#endif
606                yylexp++;
607            }
608            if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
609                goto yyoverflow;
610            yystate = yyctable[ctry];
611            *++yystack.s_mark = (YYINT) yystate;
612            *++yystack.l_mark = yylval;
613#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
614            *++yystack.p_mark = yylloc;
615#endif
616            yychar  = YYEMPTY;
617            if (yyerrflag > 0) --yyerrflag;
618            goto yyloop;
619        }
620        else
621        {
622            yyn = yyctable[ctry];
623            goto yyreduce;
624        }
625    } /* End of code dealing with conflicts */
626%%endif YYBTYACC
627    if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
628            yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
629    {
630#if YYDEBUG
631        if (yydebug)
632            fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
633                            YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
634#endif
635        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
636        yystate = yytable[yyn];
637        *++yystack.s_mark = yytable[yyn];
638        *++yystack.l_mark = yylval;
639#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
640        *++yystack.p_mark = yylloc;
641#endif
642        yychar = YYEMPTY;
643        if (yyerrflag > 0)  --yyerrflag;
644        goto yyloop;
645    }
646    if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
647            yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
648    {
649        yyn = yytable[yyn];
650        goto yyreduce;
651    }
652    if (yyerrflag != 0) goto yyinrecovery;
653%%ifdef YYBTYACC
654
655    yynewerrflag = 1;
656    goto yyerrhandler;
657    goto yyerrlab; /* redundant goto avoids 'unused label' warning */
658
659yyerrlab:
660    /* explicit YYERROR from an action -- pop the rhs of the rule reduced
661     * before looking for error recovery */
662    yystack.s_mark -= yym;
663    yystate = *yystack.s_mark;
664    yystack.l_mark -= yym;
665#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
666    yystack.p_mark -= yym;
667#endif
668
669    yynewerrflag = 0;
670yyerrhandler:
671    while (yyps->save)
672    {
673        int ctry;
674        YYParseState *save = yyps->save;
675#if YYDEBUG
676        if (yydebug)
677            fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
678                            YYDEBUGSTR, yydepth, yystate, yyps->save->state,
679                    (int)(yylvp - yylvals - yyps->save->lexeme));
680#endif
681        /* Memorize most forward-looking error state in case it's really an error. */
682        if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
683        {
684            /* Free old saved error context state */
685            if (yyerrctx) yyFreeState(yyerrctx);
686            /* Create and fill out new saved error context state */
687            yyerrctx                 = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
688            if (yyerrctx == NULL) goto yyenomem;
689            yyerrctx->save           = yyps->save;
690            yyerrctx->state          = yystate;
691            yyerrctx->errflag        = yyerrflag;
692            yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
693            memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
694            yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
695            memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
696#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
697            yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
698            memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
699#endif
700            yyerrctx->lexeme         = (int) (yylvp - yylvals);
701        }
702        yylvp          = yylvals   + save->lexeme;
703#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
704        yylpp          = yylpsns   + save->lexeme;
705#endif
706        yylexp         = yylexemes + save->lexeme;
707        yychar         = YYEMPTY;
708        yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
709        memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
710        yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
711        memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
712#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
713        yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
714        memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
715#endif
716        ctry           = ++save->ctry;
717        yystate        = save->state;
718        /* We tried shift, try reduce now */
719        if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
720        yyps->save     = save->save;
721        save->save     = NULL;
722        yyFreeState(save);
723
724        /* Nothing left on the stack -- error */
725        if (!yyps->save)
726        {
727#if YYDEBUG
728            if (yydebug)
729                fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
730                                YYPREFIX, yydepth);
731#endif
732            /* Restore state as it was in the most forward-advanced error */
733            yylvp          = yylvals   + yyerrctx->lexeme;
734#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
735            yylpp          = yylpsns   + yyerrctx->lexeme;
736#endif
737            yylexp         = yylexemes + yyerrctx->lexeme;
738            yychar         = yylexp[-1];
739            yylval         = yylvp[-1];
740#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
741            yylloc         = yylpp[-1];
742#endif
743            yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
744            memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
745            yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
746            memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
747#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
748            yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
749            memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
750#endif
751            yystate        = yyerrctx->state;
752            yyFreeState(yyerrctx);
753            yyerrctx       = NULL;
754        }
755        yynewerrflag = 1;
756    }
757    if (yynewerrflag == 0) goto yyinrecovery;
758%%endif YYBTYACC
759
760    YYERROR_CALL("syntax error");
761#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
762    yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */
763#endif
764
765#if !YYBTYACC
766    goto yyerrlab; /* redundant goto avoids 'unused label' warning */
767yyerrlab:
768#endif
769    ++yynerrs;
770
771yyinrecovery:
772    if (yyerrflag < 3)
773    {
774        yyerrflag = 3;
775        for (;;)
776        {
777            if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
778                    yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
779            {
780#if YYDEBUG
781                if (yydebug)
782                    fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
783                                    YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
784#endif
785                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
786                yystate = yytable[yyn];
787                *++yystack.s_mark = yytable[yyn];
788                *++yystack.l_mark = yylval;
789#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
790                /* lookahead position is error end position */
791                yyerror_loc_range[1] = yylloc;
792                YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
793                *++yystack.p_mark = yyloc;
794#endif
795                goto yyloop;
796            }
797            else
798            {
799#if YYDEBUG
800                if (yydebug)
801                    fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
802                                    YYDEBUGSTR, yydepth, *yystack.s_mark);
803#endif
804                if (yystack.s_mark <= yystack.s_base) goto yyabort;
805#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
806                /* the current TOS position is the error start position */
807                yyerror_loc_range[0] = *yystack.p_mark;
808#endif
809#if defined(YYDESTRUCT_CALL)
810%%ifdef YYBTYACC
811                if (!yytrial)
812%%endif
813#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
814                    YYDESTRUCT_CALL("error: discarding state",
815                                    yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
816#else
817                    YYDESTRUCT_CALL("error: discarding state",
818                                    yystos[*yystack.s_mark], yystack.l_mark);
819#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
820#endif /* defined(YYDESTRUCT_CALL) */
821                --yystack.s_mark;
822                --yystack.l_mark;
823#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
824                --yystack.p_mark;
825#endif
826            }
827        }
828    }
829    else
830    {
831        if (yychar == YYEOF) goto yyabort;
832#if YYDEBUG
833        if (yydebug)
834        {
835            if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
836            fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
837                            YYDEBUGSTR, yydepth, yystate, yychar, yys);
838        }
839#endif
840#if defined(YYDESTRUCT_CALL)
841%%ifdef YYBTYACC
842        if (!yytrial)
843%%endif
844#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
845            YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
846#else
847            YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
848#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
849#endif /* defined(YYDESTRUCT_CALL) */
850        yychar = YYEMPTY;
851        goto yyloop;
852    }
853
854yyreduce:
855    yym = yylen[yyn];
856#if YYDEBUG
857    if (yydebug)
858    {
859        fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
860                        YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
861#ifdef YYSTYPE_TOSTRING
862%%ifdef YYBTYACC
863        if (!yytrial)
864%%endif
865            if (yym > 0)
866            {
867                int i;
868                fputc('<', stderr);
869                for (i = yym; i > 0; i--)
870                {
871                    if (i != yym) fputs(", ", stderr);
872                    fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
873                                           yystack.l_mark[1-i]), stderr);
874                }
875                fputc('>', stderr);
876            }
877#endif
878        fputc('\n', stderr);
879    }
880#endif
881    if (yym > 0)
882        yyval = yystack.l_mark[1-yym];
883    else
884        memset(&yyval, 0, sizeof yyval);
885#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
886
887    /* Perform position reduction */
888    memset(&yyloc, 0, sizeof(yyloc));
889%%ifdef YYBTYACC
890    if (!yytrial)
891%%endif
892    {
893        YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym);
894        /* just in case YYERROR is invoked within the action, save
895           the start of the rhs as the error start position */
896        yyerror_loc_range[0] = yystack.p_mark[1-yym];
897    }
898#endif
899
900    switch (yyn)
901    {
902%% trailer
903    default:
904        break;
905    }
906    yystack.s_mark -= yym;
907    yystate = *yystack.s_mark;
908    yystack.l_mark -= yym;
909#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
910    yystack.p_mark -= yym;
911#endif
912    yym = yylhs[yyn];
913    if (yystate == 0 && yym == 0)
914    {
915#if YYDEBUG
916        if (yydebug)
917        {
918            fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
919#ifdef YYSTYPE_TOSTRING
920%%ifdef YYBTYACC
921            if (!yytrial)
922%%endif
923                fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
924#endif
925            fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
926        }
927#endif
928        yystate = YYFINAL;
929        *++yystack.s_mark = YYFINAL;
930        *++yystack.l_mark = yyval;
931#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
932        *++yystack.p_mark = yyloc;
933#endif
934        if (yychar < 0)
935        {
936%%ifdef YYBTYACC
937            do {
938            if (yylvp < yylve)
939            {
940                /* we're currently re-reading tokens */
941                yylval = *yylvp++;
942#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
943                yylloc = *yylpp++;
944#endif
945                yychar = *yylexp++;
946                break;
947            }
948            if (yyps->save)
949            {
950                /* in trial mode; save scanner results for future parse attempts */
951                if (yylvp == yylvlim)
952                {   /* Enlarge lexical value queue */
953                    size_t p = (size_t) (yylvp - yylvals);
954                    size_t s = (size_t) (yylvlim - yylvals);
955
956                    s += YYLVQUEUEGROWTH;
957                    if ((yylexemes = (short *)   realloc(yylexemes, s * sizeof(short))) == NULL)
958                        goto yyenomem;
959                    if ((yylvals   = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
960                        goto yyenomem;
961#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
962                    if ((yylpsns   = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
963                        goto yyenomem;
964#endif
965                    yylvp   = yylve = yylvals + p;
966                    yylvlim = yylvals + s;
967#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
968                    yylpp   = yylpe = yylpsns + p;
969                    yylplim = yylpsns + s;
970#endif
971                    yylexp  = yylexemes + p;
972                }
973                *yylexp = (short) YYLEX;
974                *yylvp++ = yylval;
975                yylve++;
976#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
977                *yylpp++ = yylloc;
978                yylpe++;
979#endif
980                yychar = *yylexp++;
981                break;
982            }
983            /* normal operation, no conflict encountered */
984%%endif YYBTYACC
985            yychar = YYLEX;
986%%ifdef YYBTYACC
987            } while (0);
988%%endif
989            if (yychar < 0) yychar = YYEOF;
990#if YYDEBUG
991            if (yydebug)
992            {
993                if ((yys = yyname[YYTRANSLATE(yychar)]) == NULL) yys = yyname[YYUNDFTOKEN];
994                fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)\n",
995                                YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
996            }
997#endif
998        }
999        if (yychar == YYEOF) goto yyaccept;
1000        goto yyloop;
1001    }
1002    if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
1003            yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
1004        yystate = yytable[yyn];
1005    else
1006        yystate = yydgoto[yym];
1007#if YYDEBUG
1008    if (yydebug)
1009    {
1010        fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
1011#ifdef YYSTYPE_TOSTRING
1012%%ifdef YYBTYACC
1013        if (!yytrial)
1014%%endif
1015            fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
1016#endif
1017        fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
1018    }
1019#endif
1020    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
1021    *++yystack.s_mark = (YYINT) yystate;
1022    *++yystack.l_mark = yyval;
1023#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1024    *++yystack.p_mark = yyloc;
1025#endif
1026    goto yyloop;
1027%%ifdef YYBTYACC
1028
1029    /* Reduction declares that this path is valid. Set yypath and do a full parse */
1030yyvalid:
1031    if (yypath) YYABORT;
1032    while (yyps->save)
1033    {
1034        YYParseState *save = yyps->save;
1035        yyps->save = save->save;
1036        save->save = yypath;
1037        yypath = save;
1038    }
1039#if YYDEBUG
1040    if (yydebug)
1041        fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
1042                        YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
1043#endif
1044    if (yyerrctx)
1045    {
1046        yyFreeState(yyerrctx);
1047        yyerrctx = NULL;
1048    }
1049    yylvp          = yylvals + yypath->lexeme;
1050#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1051    yylpp          = yylpsns + yypath->lexeme;
1052#endif
1053    yylexp         = yylexemes + yypath->lexeme;
1054    yychar         = YYEMPTY;
1055    yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
1056    memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(YYINT));
1057    yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
1058    memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
1059#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1060    yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
1061    memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
1062#endif
1063    yystate        = yypath->state;
1064    goto yyloop;
1065%%endif YYBTYACC
1066
1067yyoverflow:
1068    YYERROR_CALL("yacc stack overflow");
1069%%ifdef YYBTYACC
1070    goto yyabort_nomem;
1071yyenomem:
1072    YYERROR_CALL("memory exhausted");
1073yyabort_nomem:
1074%%endif
1075    yyresult = 2;
1076    goto yyreturn;
1077
1078yyabort:
1079    yyresult = 1;
1080    goto yyreturn;
1081
1082yyaccept:
1083%%ifdef YYBTYACC
1084    if (yyps->save) goto yyvalid;
1085%%endif
1086    yyresult = 0;
1087
1088yyreturn:
1089#if defined(YYDESTRUCT_CALL)
1090    if (yychar != YYEOF && yychar != YYEMPTY)
1091#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1092        YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
1093#else
1094        YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
1095#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1096
1097    {
1098        YYSTYPE *pv;
1099#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
1100        YYLTYPE *pp;
1101
1102        for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
1103             YYDESTRUCT_CALL("cleanup: discarding state",
1104                             yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
1105#else
1106        for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
1107             YYDESTRUCT_CALL("cleanup: discarding state",
1108                             yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
1109#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
1110    }
1111#endif /* defined(YYDESTRUCT_CALL) */
1112
1113%%ifdef YYBTYACC
1114    if (yyerrctx)
1115    {
1116        yyFreeState(yyerrctx);
1117        yyerrctx = NULL;
1118    }
1119    while (yyps)
1120    {
1121        YYParseState *save = yyps;
1122        yyps = save->save;
1123        save->save = NULL;
1124        yyFreeState(save);
1125    }
1126    while (yypath)
1127    {
1128        YYParseState *save = yypath;
1129        yypath = save->save;
1130        save->save = NULL;
1131        yyFreeState(save);
1132    }
1133%%endif YYBTYACC
1134    yyfreestack(&yystack);
1135    return (yyresult);
1136}
1137