home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d105
/
bison.lha
/
Bison
/
simparser
< prev
next >
Wrap
Text File
|
1987-10-25
|
9KB
|
343 lines
#line 2 "simparser.c"
/* Skeleton output parser for bison,
copyright (C) 1984 Bob Corbett and Richard Stallman
Permission is granted to anyone to make or distribute verbatim copies of this program
provided that the copyright notice and this permission notice are preserved;
and provided that the recipient is not asked to waive or limit his right to
redistribute copies as permitted by this permission notice;
and provided that anyone possessing an executable copy
is granted access to copy the source code, in machine-readable form,
in some reasonable manner.
Permission is granted to distribute derived works or enhanced versions of
this program under the above conditions with the additional condition
that the entire derivative or enhanced work
must be covered by a permission notice identical to this one.
Anything distributed as part of a package containing portions derived
from this program, which cannot in current practice perform its function usefully
in the absense of what was derived directly from this program,
is to be considered as forming, together with the latter,
a single work derived from this program,
which must be entirely covered by a permission notice identical to this one
in order for distribution of the package to be permitted.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
/* This is the parser code that is written into each bison parser
when the %semantic_parser declaration is not specified in the grammar.
It was written by Richard Stallman by simplifying the hairy parser
used when %semantic_parser is specified. */
/* Note: there must be only one dollar sign in this file.
It is changed into a #include that includes the action file. */
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar1 = -2)
#define YYTERROR 1
#ifndef YYIMPURE
#define YYLEX yylex()
#endif
#ifndef YYPURE
#define YYLEX yylex(&yylval, &yylloc)
#endif
/* If nonreentrant, generate the variables here */
#ifndef YYIMPURE
int yychar; /* the lookahead symbol */
YYSTYPE yylval; /* the semantic value of the */
/* lookahead symbol */
YYLTYPE yylloc; /* location data for the lookahead */
/* symbol */
int yydebug = 0; /* nonzero means print parse trace */
#endif /* YYIMPURE */
/* YYMAXDEPTH indicates the size of the parser's state and value */
/* stacks. */
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 250
#endif
int
yyparse()
{
register int yystate;
register int yyn;
register short *yyssp;
register YYSTYPE *yyvsp;
YYLTYPE *yylsp;
int yyerrstatus; /* number of tokens to shift before error messages enabled */
int yychar1; /* lookahead token as an internal (translated) token number */
short yyssa[YYMAXDEPTH]; /* the state stack */
YYSTYPE yyvsa[YYMAXDEPTH]; /* the semantic value stack */
YYLTYPE yylsa[YYMAXDEPTH]; /* the location stack */
short *yyss = yyssa; /* refer to the stacks thru separate pointers */
YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
YYLTYPE *yyls = yylsa;
int yymaxdepth = YYMAXDEPTH;
#ifndef YYPURE
int yychar;
YYSTYPE yylval;
YYLTYPE yylloc;
extern int yydebug;
#endif
YYSTYPE yyval; /* the variable used to return */
/* semantic values from the action */
/* routines */
int yylen;
yystate = 0;
yyerrstatus = 0;
yychar1 = 1; /* just to cause a proper refill */
yyssp = yyss - 1;
yyvsp = yyvs - 1;
yylsp = yyls - 1;
yyrefill:
/* at end of file, yychar is <= 0 and yychar1 is 0.
After shifting error token, if should reuse the lookahead token,
yychar is that token in external form and yychar1 is -1.
After shifting error token, if should discard the lookahead token,
yychar is the token to be discarded and yychar1 is 100000.
After yyclearin has been done, yychar1 is -2.
After normal token processing, yychar1 is positive. */
if (yychar1 > 0) yychar = YYLEX;
if (yychar <= 0)
yychar1 = 0;
else yychar1 = YYTRANSLATE(yychar);
if (yydebug)
fprintf(stderr, "Next token is type %d\n", yychar);
yynewstate:
*++yyssp = yystate;
if (yyssp >= yyss + yymaxdepth - 1)
{
#ifdef yyoverflow
/* Give user a chance to reallocate the stack */
int yyssize = yyssp-yyss, yylsize = yylsp-yyls, yyvsize = yyvsp-yyvs;
/* Use copies of these so that the &'s don't force the real ones into memory. */
YYSTYPE *yyvs1 = yyvs;
YYLTYPE *yyls1 = yyls;
short *yyss1 = yyss;
/* Each stack pointer address is followed by the size of
the data in use in that stack, in bytes. */
yyoverflow("parser stack overflow",
&yyss1, (yyssize+1)*sizeof(*yyssp), &yyvs1, (yyvsize+1)*sizeof(*yyvsp),
&yyls1, (yylsize+1)*sizeof(*yylsp), &yymaxdepth);
yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
yyssp = yyss+yyssize;
yylsp = yyls+yylsize;
yyvsp = yyvs+yyvsize;
if (yyssp >= yyss + yymaxdepth - 1)
YYERROR;
#endif
#ifndef yyoverflow
yyerror("parser stack overflow");
#endif
}
if (yydebug)
fprintf(stderr, "Entering state %d\n", yystate);
yyresume:
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yydefault;
yyn += yychar1;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
goto yydefault;
yyn = yytable[yyn];
if (yyn < 0)
{
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrlab;
if (yyn == YYFINAL)
YYACCEPT;
if (yydebug)
fprintf(stderr, "Shifting token %d, ", yychar);
*++yyvsp = yylval;
*++yylsp = yylloc;
/* count tokens shifted since error; after three, turn off error status. */
if (yyerrstatus) yyerrstatus--;
yystate = yyn;
goto yyrefill;
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
yyreduce:
/* yyn is the number of a rule to reduce with. */
if (yydebug)
fprintf(stderr, "Reducing via rule %d, ", yyn);
yylen = yyr2[yyn];
yyval = yyvsp[1-yylen]; /* implement default value of the action */
$ /* this dollarsign gets turned into a #include of the action file */
yyvsp -= yylen;
yylsp -= yylen;
yyssp -= yylen;
if (yydebug)
fprintf(stderr, "popping to level %d\n", yyssp-yyss);
*++yyvsp = yyval;
yylsp++;
if (yylen == 0)
{
yylsp->first_line = yylloc.first_line;
yylsp->first_column = yylloc.first_column;
yylsp->last_line = (yylsp-1)->last_line;
yylsp->last_column = (yylsp-1)->last_column;
yylsp->text = 0;
}
else
{
yylsp->last_line = (yylsp+yylen-1)->last_line;
yylsp->last_column = (yylsp+yylen-1)->last_column;
}
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTBASE];
if (yychar1 == -2) /* detect use of yyclearin */
{ yychar1 = 1; goto yyrefill; }
/* want to reuse or discard token after error => do so. */
if (yychar1 < 0 || yychar1 == 100000)
goto yyrefill;
goto yynewstate;
yyerrlab: /* here on detecting error */
if (! yyerrstatus)
/* If not already recovering from an error, report this error. */
{
yyerror("parse error");
}
if (yyerrstatus == 3)
{
/* if just tried and failed to reuse lookahead token after an error, discard it. */
if (yydebug)
fprintf(stderr, "Discarding token %d.\n", yychar);
yychar1 = 100000; /* Make sure it really gets discarded. */
/* return failure if at end of input */
if (yychar <= 0)
YYERROR;
}
else
{
/* Else try to reuse it after shifting the error token. */
yychar1 = -1;
}
yyerrstatus = 3;
goto yyerrhandle;
yyerrdefault: /* current state does not do anything special for the error token. */
yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
if (yyn) goto yydefault;
yyerrpop: /* pop the current state because it cannot handle the error token */
if (yyssp == yyss) YYERROR;
yyvsp--;
yylsp--;
yystate = *--yyssp;
if (yydebug)
fprintf(stderr, "Error: Popping to level %d and state %d.\n", yyssp-yyss, yystate);
yyerrhandle:
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yyerrdefault;
yyn += YYTERROR;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
goto yyerrdefault;
yyn = yytable[yyn];
if (yyn < 0)
{
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrpop;
if (yyn == YYFINAL)
YYACCEPT;
if (yydebug)
fprintf(stderr, "Shifting error token, ");
*++yyvsp = yylval;
*++yylsp = yylloc;
yystate = yyn;
goto yyrefill;
}