Anarres-Mud-Driver
view release on metacpan or search on metacpan
Compiler/parser.c view on Meta::CPAN
#define YYABORT goto amd_yyabortlab
#define YYERROR goto amd_yyerrlab1
/* Like YYERROR except do call amd_yyerror.
This remains here temporarily to ease the
transition to the new meaning of YYERROR, for GCC.
Once GCC version 2 has supplanted version 1, this can go. */
#define YYFAIL goto amd_yyerrlab
#define YYRECOVERING() (!!amd_yyerrstatus)
#define YYBACKUP(token, value) \
do \
if (amd_yychar == YYEMPTY && amd_yylen == 1) \
{ amd_yychar = (token), amd_yylval = (value); \
amd_yychar1 = YYTRANSLATE (amd_yychar); \
YYPOPSTACK; \
goto amd_yybackup; \
} \
else \
{ amd_yyerror ("syntax error: cannot back up"); YYERROR; } \
while (0)
#define YYTERROR 1
#define YYERRCODE 256
#ifndef YYPURE
#define YYLEX amd_yylex()
#endif
#ifdef YYPURE
#ifdef YYLSP_NEEDED
#ifdef YYLEX_PARAM
#define YYLEX amd_yylex(&amd_yylval, &amd_yylloc, YYLEX_PARAM)
#else
#define YYLEX amd_yylex(&amd_yylval, &amd_yylloc)
#endif
#else /* not YYLSP_NEEDED */
#ifdef YYLEX_PARAM
#define YYLEX amd_yylex(&amd_yylval, YYLEX_PARAM)
#else
#define YYLEX amd_yylex(&amd_yylval)
#endif
#endif /* not YYLSP_NEEDED */
#endif
/* If nonreentrant, generate the variables here */
#ifndef YYPURE
int amd_yychar; /* the lookahead symbol */
AMD_YYSTYPE amd_yylval; /* the semantic value of the */
/* lookahead symbol */
#ifdef YYLSP_NEEDED
YYLTYPE amd_yylloc; /* location data for the lookahead */
/* symbol */
#endif
int amd_yynerrs; /* number of parse errors so far */
#endif /* not YYPURE */
#if YYDEBUG != 0
int amd_yydebug; /* nonzero means print parse trace */
/* Since this is uninitialized, it does not stop multiple parsers
from coexisting. */
#endif
/* YYINITDEPTH indicates the initial size of the parser's stacks */
#ifndef YYINITDEPTH
#define YYINITDEPTH 200
#endif
/* YYMAXDEPTH is the maximum size the stacks can grow to
(effective only if the built-in stack extension method is used). */
#if YYMAXDEPTH == 0
#undef YYMAXDEPTH
#endif
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 10000
#endif
/* Define __yy_memcpy. Note that the size argument
should be passed with type unsigned int, because that is what the non-GCC
definitions require. With GCC, __builtin_memcpy takes an arg
of type size_t, but it can handle unsigned int. */
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
#else /* not GNU C or C++ */
#ifndef __cplusplus
/* This is the most reliable way to avoid incompatibilities
in available built-in functions on various systems. */
static void
__yy_memcpy (to, from, count)
char *to;
char *from;
unsigned int count;
{
register char *f = from;
register char *t = to;
register int i = count;
while (i-- > 0)
*t++ = *f++;
}
#else /* __cplusplus */
/* This is the most reliable way to avoid incompatibilities
in available built-in functions on various systems. */
static void
__yy_memcpy (char *to, char *from, unsigned int count)
{
register char *t = to;
register char *f = from;
register int i = count;
while (i-- > 0)
*t++ = *f++;
Compiler/parser.c view on Meta::CPAN
/* Prevent warning if -Wstrict-prototypes. */
#ifdef __GNUC__
#ifdef YYPARSE_PARAM
YYPARSE_RETURN_TYPE
amd_yyparse (void *);
#else
YYPARSE_RETURN_TYPE
amd_yyparse (void);
#endif
#endif
YYPARSE_RETURN_TYPE
amd_yyparse(YYPARSE_PARAM_ARG)
YYPARSE_PARAM_DECL
{
register int amd_yystate;
register int amd_yyn;
register short *amd_yyssp;
register AMD_YYSTYPE *amd_yyvsp;
int amd_yyerrstatus; /* number of tokens to shift before error messages enabled */
int amd_yychar1 = 0; /* lookahead token as an internal (translated) token number */
short amd_yyssa[YYINITDEPTH]; /* the state stack */
AMD_YYSTYPE amd_yyvsa[YYINITDEPTH]; /* the semantic value stack */
short *amd_yyss = amd_yyssa; /* refer to the stacks thru separate pointers */
AMD_YYSTYPE *amd_yyvs = amd_yyvsa; /* to allow amd_yyoverflow to reallocate them elsewhere */
#ifdef YYLSP_NEEDED
YYLTYPE amd_yylsa[YYINITDEPTH]; /* the location stack */
YYLTYPE *amd_yyls = amd_yylsa;
YYLTYPE *amd_yylsp;
#define YYPOPSTACK (amd_yyvsp--, amd_yyssp--, amd_yylsp--)
#else
#define YYPOPSTACK (amd_yyvsp--, amd_yyssp--)
#endif
int amd_yystacksize = YYINITDEPTH;
#ifndef YYSTACK_USE_ALLOCA
int amd_yyfree_stacks = 0;
#endif
#ifdef YYPURE
int amd_yychar;
AMD_YYSTYPE amd_yylval;
int amd_yynerrs;
#ifdef YYLSP_NEEDED
YYLTYPE amd_yylloc;
#endif
#endif
AMD_YYSTYPE amd_yyval; /* the variable used to return */
/* semantic values from the action */
/* routines */
int amd_yylen;
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Starting parse\n");
#endif
amd_yystate = 0;
amd_yyerrstatus = 0;
amd_yynerrs = 0;
amd_yychar = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers.
Waste one element of value and location stack
so that they stay on the same level as the state stack.
The wasted elements are never initialized. */
amd_yyssp = amd_yyss - 1;
amd_yyvsp = amd_yyvs;
#ifdef YYLSP_NEEDED
amd_yylsp = amd_yyls;
#endif
/* Push a new state, which is found in amd_yystate . */
/* In all cases, when you get here, the value and location stacks
have just been pushed. so pushing a state here evens the stacks. */
amd_yynewstate:
*++amd_yyssp = amd_yystate;
if (amd_yyssp >= amd_yyss + amd_yystacksize - 1)
{
/* Give user a chance to reallocate the stack */
/* Use copies of these so that the &'s don't force the real ones into memory. */
AMD_YYSTYPE *amd_yyvs1 = amd_yyvs;
short *amd_yyss1 = amd_yyss;
#ifdef YYLSP_NEEDED
YYLTYPE *amd_yyls1 = amd_yyls;
#endif
/* Get the current used size of the three stacks, in elements. */
int size = amd_yyssp - amd_yyss + 1;
#ifdef amd_yyoverflow
/* Each stack pointer address is followed by the size of
the data in use in that stack, in bytes. */
#ifdef YYLSP_NEEDED
/* This used to be a conditional around just the two extra args,
but that might be undefined if amd_yyoverflow is a macro. */
amd_yyoverflow("parser stack overflow",
&amd_yyss1, size * sizeof (*amd_yyssp),
&amd_yyvs1, size * sizeof (*amd_yyvsp),
&amd_yyls1, size * sizeof (*amd_yylsp),
&amd_yystacksize);
#else
amd_yyoverflow("parser stack overflow",
&amd_yyss1, size * sizeof (*amd_yyssp),
&amd_yyvs1, size * sizeof (*amd_yyvsp),
&amd_yystacksize);
#endif
amd_yyss = amd_yyss1; amd_yyvs = amd_yyvs1;
#ifdef YYLSP_NEEDED
amd_yyls = amd_yyls1;
#endif
#else /* no amd_yyoverflow */
/* Extend the stack our own way. */
if (amd_yystacksize >= YYMAXDEPTH)
{
amd_yyerror("parser stack overflow");
#ifndef YYSTACK_USE_ALLOCA
if (amd_yyfree_stacks)
{
free (amd_yyss);
free (amd_yyvs);
#ifdef YYLSP_NEEDED
free (amd_yyls);
#endif
}
#endif
return 2;
}
amd_yystacksize *= 2;
if (amd_yystacksize > YYMAXDEPTH)
amd_yystacksize = YYMAXDEPTH;
#ifndef YYSTACK_USE_ALLOCA
amd_yyfree_stacks = 1;
#endif
amd_yyss = (short *) YYSTACK_ALLOC (amd_yystacksize * sizeof (*amd_yyssp));
__yy_memcpy ((char *)amd_yyss, (char *)amd_yyss1,
size * (unsigned int) sizeof (*amd_yyssp));
amd_yyvs = (AMD_YYSTYPE *) YYSTACK_ALLOC (amd_yystacksize * sizeof (*amd_yyvsp));
__yy_memcpy ((char *)amd_yyvs, (char *)amd_yyvs1,
size * (unsigned int) sizeof (*amd_yyvsp));
#ifdef YYLSP_NEEDED
amd_yyls = (YYLTYPE *) YYSTACK_ALLOC (amd_yystacksize * sizeof (*amd_yylsp));
__yy_memcpy ((char *)amd_yyls, (char *)amd_yyls1,
size * (unsigned int) sizeof (*amd_yylsp));
#endif
#endif /* no amd_yyoverflow */
amd_yyssp = amd_yyss + size - 1;
amd_yyvsp = amd_yyvs + size - 1;
#ifdef YYLSP_NEEDED
amd_yylsp = amd_yyls + size - 1;
#endif
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Stack size increased to %d\n", amd_yystacksize);
#endif
if (amd_yyssp >= amd_yyss + amd_yystacksize - 1)
YYABORT;
}
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Entering state %d\n", amd_yystate);
#endif
goto amd_yybackup;
amd_yybackup:
/* Do appropriate processing given the current state. */
/* Read a lookahead token if we need one and don't already have one. */
/* amd_yyresume: */
/* First try to decide what to do without reference to lookahead token. */
amd_yyn = amd_yypact[amd_yystate];
if (amd_yyn == YYFLAG)
goto amd_yydefault;
/* Not known => get a lookahead token if don't already have one. */
/* amd_yychar is either YYEMPTY or YYEOF
or a valid token in external form. */
if (amd_yychar == YYEMPTY)
{
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Reading a token: ");
#endif
amd_yychar = YYLEX;
}
/* Convert token to internal form (in amd_yychar1) for indexing tables with */
if (amd_yychar <= 0) /* This means end of input. */
{
amd_yychar1 = 0;
amd_yychar = YYEOF; /* Don't call YYLEX any more */
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Now at end of input.\n");
#endif
}
else
{
amd_yychar1 = YYTRANSLATE(amd_yychar);
#if YYDEBUG != 0
if (amd_yydebug)
{
fprintf (stderr, "Next token is %d (%s", amd_yychar, amd_yytname[amd_yychar1]);
/* Give the individual parser a way to print the precise meaning
of a token, for further debugging info. */
#ifdef YYPRINT
YYPRINT (stderr, amd_yychar, amd_yylval);
#endif
fprintf (stderr, ")\n");
}
#endif
}
amd_yyn += amd_yychar1;
if (amd_yyn < 0 || amd_yyn > YYLAST || amd_yycheck[amd_yyn] != amd_yychar1)
goto amd_yydefault;
amd_yyn = amd_yytable[amd_yyn];
/* amd_yyn is what to do for this token type in this state.
Negative => reduce, -amd_yyn is rule number.
Positive => shift, amd_yyn is new state.
New state is final state => don't bother to shift,
just return success.
0, or most negative number => error. */
if (amd_yyn < 0)
{
if (amd_yyn == YYFLAG)
goto amd_yyerrlab;
amd_yyn = -amd_yyn;
goto amd_yyreduce;
}
else if (amd_yyn == 0)
goto amd_yyerrlab;
if (amd_yyn == YYFINAL)
YYACCEPT;
/* Shift the lookahead token. */
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Shifting token %d (%s), ", amd_yychar, amd_yytname[amd_yychar1]);
#endif
/* Discard the token being shifted unless it is eof. */
if (amd_yychar != YYEOF)
amd_yychar = YYEMPTY;
*++amd_yyvsp = amd_yylval;
#ifdef YYLSP_NEEDED
*++amd_yylsp = amd_yylloc;
#endif
/* count tokens shifted since error; after three, turn off error status. */
if (amd_yyerrstatus) amd_yyerrstatus--;
amd_yystate = amd_yyn;
goto amd_yynewstate;
/* Do the default action for the current state. */
amd_yydefault:
amd_yyn = amd_yydefact[amd_yystate];
if (amd_yyn == 0)
goto amd_yyerrlab;
/* Do a reduction. amd_yyn is the number of a rule to reduce with. */
amd_yyreduce:
amd_yylen = amd_yyr2[amd_yyn];
if (amd_yylen > 0)
amd_yyval = amd_yyvsp[1-amd_yylen]; /* implement default value of the action */
#if YYDEBUG != 0
if (amd_yydebug)
{
int i;
fprintf (stderr, "Reducing via rule %d (line %d), ",
amd_yyn, amd_yyrline[amd_yyn]);
/* Print the symbols being reduced, and their result. */
for (i = amd_yyprhs[amd_yyn]; amd_yyrhs[i] > 0; i++)
fprintf (stderr, "%s ", amd_yytname[amd_yyrhs[i]]);
fprintf (stderr, " -> %s\n", amd_yytname[amd_yyr1[amd_yyn]]);
}
#endif
switch (amd_yyn) {
case 8:
#line 474 "parser.y"
{
/* printf("Inheriting %s\n", SvPVX($2)); */
SvREFCNT_dec(
amd_yyparse_program_apply(amd_yyparse_param,
"inherit", &PL_sv_undef, amd_yyvsp[-1].sv));
;
break;}
case 9:
#line 481 "parser.y"
{
printf("Inheriting %s as %s\n", SvPVX(amd_yyvsp[-1].sv), SvPVX(amd_yyvsp[-2].sv));
SvREFCNT_dec(
amd_yyparse_program_apply(amd_yyparse_param,
"inherit", amd_yyvsp[-2].sv, amd_yyvsp[-1].sv));
;
break;}
case 10:
#line 491 "parser.y"
{
amd_yyval.sv = amd_yyvsp[0].sv;
;
break;}
case 11:
#line 498 "parser.y"
{
amd_yyval.av = newAV();
av_push(amd_yyval.av, amd_yyvsp[-4].sv);
av_push(amd_yyval.av, amd_yyvsp[-3].sv);
av_push(amd_yyval.av, newRV_noinc((SV *)(amd_yyvsp[-1].av)));
;
break;}
case 12:
#line 508 "parser.y"
{
amd_yyval.av = newAV();
av_push(amd_yyval.av, amd_yyvsp[-1].sv);
av_push(amd_yyval.av, amd_yyvsp[0].sv);
;
break;}
case 13:
#line 517 "parser.y"
{
Compiler/parser.c view on Meta::CPAN
sv_catpv(amd_yyvsp[-2].sv, SvPVX(amd_yyvsp[0].sv));
SvREFCNT_dec(amd_yyvsp[0].sv);
amd_yyval.sv = amd_yyvsp[-2].sv;
;
break;}
case 168:
#line 1524 "parser.y"
{
sv_catpv(amd_yyvsp[-2].sv, SvPVX(amd_yyvsp[0].sv));
SvREFCNT_dec(amd_yyvsp[0].sv);
amd_yyval.sv = amd_yyvsp[-2].sv;
;
break;}
case 169:
#line 1530 "parser.y"
{
char buf[64];
snprintf(buf, 64, "%d", amd_yyvsp[0].number);
amd_yyval.sv = newSVpv(buf, 0);
;
break;}
case 171:
#line 1541 "parser.y"
{
sv_catpv(amd_yyvsp[-1].sv, SvPVX(amd_yyvsp[0].sv));
SvREFCNT_dec(amd_yyvsp[0].sv);
amd_yyval.sv = amd_yyvsp[-1].sv;
;
break;}
case 174:
#line 1555 "parser.y"
{
amd_yyval.av = amd_yyvsp[-1].av;
;
break;}
case 175:
#line 1562 "parser.y"
{
/* This doesn't expand the pairs into a single list.
* There is a hack elsewhere. */
amd_yyval.av = amd_yyvsp[-1].av;
;
break;}
case 176:
#line 1572 "parser.y"
{
amd_yyval.obj = amd_yyvsp[-1].obj;
;
break;}
}
/* the action file gets copied in in place of this dollarsign */
#line 554 "/usr/share/bison.simple"
amd_yyvsp -= amd_yylen;
amd_yyssp -= amd_yylen;
#ifdef YYLSP_NEEDED
amd_yylsp -= amd_yylen;
#endif
#if YYDEBUG != 0
if (amd_yydebug)
{
short *ssp1 = amd_yyss - 1;
fprintf (stderr, "state stack now");
while (ssp1 != amd_yyssp)
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
#endif
*++amd_yyvsp = amd_yyval;
#ifdef YYLSP_NEEDED
amd_yylsp++;
if (amd_yylen == 0)
{
amd_yylsp->first_line = amd_yylloc.first_line;
amd_yylsp->first_column = amd_yylloc.first_column;
amd_yylsp->last_line = (amd_yylsp-1)->last_line;
amd_yylsp->last_column = (amd_yylsp-1)->last_column;
amd_yylsp->text = 0;
}
else
{
amd_yylsp->last_line = (amd_yylsp+amd_yylen-1)->last_line;
amd_yylsp->last_column = (amd_yylsp+amd_yylen-1)->last_column;
}
#endif
/* Now "shift" the result of the reduction.
Determine what state that goes to,
based on the state we popped back to
and the rule number reduced by. */
amd_yyn = amd_yyr1[amd_yyn];
amd_yystate = amd_yypgoto[amd_yyn - YYNTBASE] + *amd_yyssp;
if (amd_yystate >= 0 && amd_yystate <= YYLAST && amd_yycheck[amd_yystate] == *amd_yyssp)
amd_yystate = amd_yytable[amd_yystate];
else
amd_yystate = amd_yydefgoto[amd_yyn - YYNTBASE];
goto amd_yynewstate;
amd_yyerrlab: /* here on detecting error */
if (! amd_yyerrstatus)
/* If not already recovering from an error, report this error. */
{
++amd_yynerrs;
#ifdef YYERROR_VERBOSE
amd_yyn = amd_yypact[amd_yystate];
if (amd_yyn > YYFLAG && amd_yyn < YYLAST)
{
int size = 0;
char *msg;
int x, count;
count = 0;
/* Start X at -amd_yyn if nec to avoid negative indexes in amd_yycheck. */
for (x = (amd_yyn < 0 ? -amd_yyn : 0);
x < (sizeof(amd_yytname) / sizeof(char *)); x++)
if (amd_yycheck[x + amd_yyn] == x)
size += strlen(amd_yytname[x]) + 15, count++;
msg = (char *) malloc(size + 15);
if (msg != 0)
{
strcpy(msg, "parse error");
if (count < 5)
{
count = 0;
for (x = (amd_yyn < 0 ? -amd_yyn : 0);
x < (sizeof(amd_yytname) / sizeof(char *)); x++)
if (amd_yycheck[x + amd_yyn] == x)
{
strcat(msg, count == 0 ? ", expecting `" : " or `");
strcat(msg, amd_yytname[x]);
strcat(msg, "'");
count++;
}
}
amd_yyerror(msg);
free(msg);
}
else
amd_yyerror ("parse error; also virtual memory exceeded");
}
else
#endif /* YYERROR_VERBOSE */
amd_yyerror("parse error");
}
goto amd_yyerrlab1;
amd_yyerrlab1: /* here on error raised explicitly by an action */
if (amd_yyerrstatus == 3)
{
/* if just tried and failed to reuse lookahead token after an error, discard it. */
/* return failure if at end of input */
if (amd_yychar == YYEOF)
YYABORT;
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Discarding token %d (%s).\n", amd_yychar, amd_yytname[amd_yychar1]);
#endif
amd_yychar = YYEMPTY;
}
/* Else will try to reuse lookahead token
after shifting the error token. */
amd_yyerrstatus = 3; /* Each real token shifted decrements this */
goto amd_yyerrhandle;
amd_yyerrdefault: /* current state does not do anything special for the error token. */
#if 0
/* This is wrong; only states that explicitly want error tokens
should shift them. */
amd_yyn = amd_yydefact[amd_yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
if (amd_yyn) goto amd_yydefault;
#endif
amd_yyerrpop: /* pop the current state because it cannot handle the error token */
if (amd_yyssp == amd_yyss) YYABORT;
amd_yyvsp--;
amd_yystate = *--amd_yyssp;
#ifdef YYLSP_NEEDED
amd_yylsp--;
#endif
#if YYDEBUG != 0
if (amd_yydebug)
{
short *ssp1 = amd_yyss - 1;
fprintf (stderr, "Error: state stack now");
while (ssp1 != amd_yyssp)
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
#endif
amd_yyerrhandle:
amd_yyn = amd_yypact[amd_yystate];
if (amd_yyn == YYFLAG)
goto amd_yyerrdefault;
amd_yyn += YYTERROR;
if (amd_yyn < 0 || amd_yyn > YYLAST || amd_yycheck[amd_yyn] != YYTERROR)
goto amd_yyerrdefault;
amd_yyn = amd_yytable[amd_yyn];
if (amd_yyn < 0)
{
if (amd_yyn == YYFLAG)
goto amd_yyerrpop;
amd_yyn = -amd_yyn;
goto amd_yyreduce;
}
else if (amd_yyn == 0)
goto amd_yyerrpop;
if (amd_yyn == YYFINAL)
YYACCEPT;
#if YYDEBUG != 0
if (amd_yydebug)
fprintf(stderr, "Shifting error token, ");
#endif
*++amd_yyvsp = amd_yylval;
#ifdef YYLSP_NEEDED
*++amd_yylsp = amd_yylloc;
#endif
amd_yystate = amd_yyn;
goto amd_yynewstate;
amd_yyacceptlab:
/* YYACCEPT comes here. */
#ifndef YYSTACK_USE_ALLOCA
if (amd_yyfree_stacks)
{
free (amd_yyss);
free (amd_yyvs);
#ifdef YYLSP_NEEDED
free (amd_yyls);
#endif
}
#endif
return 0;
amd_yyabortlab:
/* YYABORT comes here. */
#ifndef YYSTACK_USE_ALLOCA
if (amd_yyfree_stacks)
{
free (amd_yyss);
free (amd_yyvs);
#ifdef YYLSP_NEEDED
free (amd_yyls);
#endif
}
#endif
return 1;
}
#line 1577 "parser.y"
const char *
amd_yytokname(int i)
{
return amd_yytname[YYTRANSLATE(i)];
}
int
amd_yyparser_parse(SV *program, const char *str)
{
amd_parse_param_t param;
int ret;
// fprintf(stderr, "Start of amd_yyparser_parse\n");
// fflush(stderr);
memset(¶m, 0, sizeof(param));
param.program = program;
param.symtab = newHV();
amd_yylex_init(str);
#if YYDEBUG != 0
amd_yydebug = 1;
#endif
ret = amd_yyparse((void *)(¶m));
/* Delete the HV but not the contents. */
hv_undef(param.symtab);
return ret;
}
( run in 0.607 second using v1.01-cache-2.11-cpan-39bf76dae61 )