mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-21 19:51:27 +00:00
Update lempar.c to 2016-10-04 version
- Every update rolled into one, because I'm pretty sure I missed some while
updating lemon.c (not counting today's commits), since it wasn't always
updated at the same time as lemon.c.
- In particular, I think this check-in from 2016-06-06 was very important to
us after commit 3d5867d29e
(For the
Lemon-generated parser, add a new action type SHIFTREDUCE and use it to
further compress the parser tables and improve parser performance.):
* Fix lempar.c so that the shift-reduce optimization works for error
processing.
This commit is contained in:
parent
696beca40f
commit
97107b6b6d
2 changed files with 141 additions and 124 deletions
|
@ -77,7 +77,7 @@ static void SetNodeLine(ZCC_TreeNode *name, int line)
|
||||||
FString unexpected, expecting;
|
FString unexpected, expecting;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int stateno = yypParser->yystack[yypParser->yyidx].stateno;
|
int stateno = yypParser->yytos->stateno;
|
||||||
|
|
||||||
unexpected << "Unexpected " << ZCCTokenName(yymajor);
|
unexpected << "Unexpected " << ZCCTokenName(yymajor);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
***************** Begin makeheaders token definitions *************************/
|
***************** Begin makeheaders token definitions *************************/
|
||||||
%%
|
%%
|
||||||
/**************** End makeheaders token definitions ***************************/
|
/**************** End makeheaders token definitions ***************************/
|
||||||
|
|
||||||
/* The next section is a series of control #defines.
|
/* The next section is a series of control #defines.
|
||||||
** various aspects of the generated parser.
|
** various aspects of the generated parser.
|
||||||
** YYCODETYPE is the data type used to store the integer codes
|
** YYCODETYPE is the data type used to store the integer codes
|
||||||
|
@ -50,8 +51,6 @@
|
||||||
** YYNOCODE is a number of type YYCODETYPE that is not used for
|
** YYNOCODE is a number of type YYCODETYPE that is not used for
|
||||||
** any terminal or nonterminal symbol.
|
** any terminal or nonterminal symbol.
|
||||||
** YYFALLBACK If defined, this indicates that one or more tokens
|
** YYFALLBACK If defined, this indicates that one or more tokens
|
||||||
** have fall-back values which should be used if the
|
|
||||||
** original value of the token will not parse.
|
|
||||||
** (also known as: "terminal symbols") have fall-back
|
** (also known as: "terminal symbols") have fall-back
|
||||||
** values which should be used if the original symbol
|
** values which should be used if the original symbol
|
||||||
** would not parse. This permits keywords to sometimes
|
** would not parse. This permits keywords to sometimes
|
||||||
|
@ -126,7 +125,7 @@
|
||||||
**
|
**
|
||||||
** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
|
** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
|
||||||
** and YY_MAX_REDUCE
|
** and YY_MAX_REDUCE
|
||||||
|
**
|
||||||
** N == YY_ERROR_ACTION A syntax error has occurred.
|
** N == YY_ERROR_ACTION A syntax error has occurred.
|
||||||
**
|
**
|
||||||
** N == YY_ACCEPT_ACTION The parser accepts its input.
|
** N == YY_ACCEPT_ACTION The parser accepts its input.
|
||||||
|
@ -135,16 +134,20 @@
|
||||||
** slots in the yy_action[] table.
|
** slots in the yy_action[] table.
|
||||||
**
|
**
|
||||||
** The action table is constructed as a single large table named yy_action[].
|
** The action table is constructed as a single large table named yy_action[].
|
||||||
** Given state S and lookahead X, the action is computed as
|
** Given state S and lookahead X, the action is computed as either:
|
||||||
**
|
**
|
||||||
** yy_action[ yy_shift_ofst[S] + X ]
|
** (A) N = yy_action[ yy_shift_ofst[S] + X ]
|
||||||
|
** (B) N = yy_default[S]
|
||||||
**
|
**
|
||||||
** If the index value yy_shift_ofst[S]+X is out of range or if the value
|
** The (A) formula is preferred. The B formula is used instead if:
|
||||||
** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
|
** (1) The yy_shift_ofst[S]+X value is out of range, or
|
||||||
** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
|
** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
|
||||||
** and that yy_default[S] should be used instead.
|
** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
|
||||||
|
** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
|
||||||
|
** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
|
||||||
|
** Hence only tests (1) and (2) need to be evaluated.)
|
||||||
**
|
**
|
||||||
** The formula above is for computing the action when the lookahead is
|
** The formulas above are for computing the action when the lookahead is
|
||||||
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
|
** a terminal symbol. If the lookahead is a non-terminal (as occurs after
|
||||||
** a reduce action) then the yy_reduce_ofst[] array is used in place of
|
** a reduce action) then the yy_reduce_ofst[] array is used in place of
|
||||||
** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
|
** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
|
||||||
|
@ -213,9 +216,9 @@ typedef struct yyStackEntry yyStackEntry;
|
||||||
/* The state of the parser is completely contained in an instance of
|
/* The state of the parser is completely contained in an instance of
|
||||||
** the following structure */
|
** the following structure */
|
||||||
struct yyParser {
|
struct yyParser {
|
||||||
int yyidx; /* Index of top element in stack */
|
yyStackEntry *yytos; /* Pointer to top element of the stack */
|
||||||
#ifdef YYTRACKMAXSTACKDEPTH
|
#ifdef YYTRACKMAXSTACKDEPTH
|
||||||
int yyidxMax; /* Maximum value of yyidx */
|
int yyhwm; /* High-water mark of the stack */
|
||||||
#endif
|
#endif
|
||||||
#ifndef YYNOERRORRECOVERY
|
#ifndef YYNOERRORRECOVERY
|
||||||
int yyerrcnt; /* Shifts left before out of the error */
|
int yyerrcnt; /* Shifts left before out of the error */
|
||||||
|
@ -224,6 +227,7 @@ struct yyParser {
|
||||||
#if YYSTACKDEPTH<=0
|
#if YYSTACKDEPTH<=0
|
||||||
int yystksz; /* Current side of the stack */
|
int yystksz; /* Current side of the stack */
|
||||||
yyStackEntry *yystack; /* The parser's stack */
|
yyStackEntry *yystack; /* The parser's stack */
|
||||||
|
yyStackEntry yystk0; /* First stack entry */
|
||||||
#else
|
#else
|
||||||
yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
|
yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
|
||||||
#endif
|
#endif
|
||||||
|
@ -278,26 +282,37 @@ static const char *const yyRuleName[] = {
|
||||||
};
|
};
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
|
|
||||||
#if YYSTACKDEPTH<=0
|
#if YYSTACKDEPTH<=0
|
||||||
/*
|
/*
|
||||||
** Try to increase the size of the parser stack.
|
** Try to increase the size of the parser stack. Return the number
|
||||||
|
** of errors. Return 0 on success.
|
||||||
*/
|
*/
|
||||||
static void yyGrowStack(yyParser *p){
|
static int yyGrowStack(yyParser *p){
|
||||||
int newSize;
|
int newSize;
|
||||||
|
int idx;
|
||||||
yyStackEntry *pNew;
|
yyStackEntry *pNew;
|
||||||
|
|
||||||
newSize = p->yystksz*2 + 100;
|
newSize = p->yystksz*2 + 100;
|
||||||
pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
|
idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
|
||||||
|
if( p->yystack==&p->yystk0 ){
|
||||||
|
pNew = malloc(newSize*sizeof(pNew[0]));
|
||||||
|
if( pNew ) pNew[0] = p->yystk0;
|
||||||
|
}else{
|
||||||
|
pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
|
||||||
|
}
|
||||||
if( pNew ){
|
if( pNew ){
|
||||||
p->yystack = pNew;
|
p->yystack = pNew;
|
||||||
p->yystksz = newSize;
|
p->yytos = &p->yystack[idx];
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE,"%sStack grows to %d entries!\n",
|
fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
|
||||||
yyTracePrompt, p->yystksz);
|
yyTracePrompt, p->yystksz, newSize);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
p->yystksz = newSize;
|
||||||
}
|
}
|
||||||
|
return pNew==0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -326,15 +341,24 @@ void *ParseAlloc(void *(CDECL *mallocProc)(YYMALLOCARGTYPE)){
|
||||||
yyParser *pParser;
|
yyParser *pParser;
|
||||||
pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
|
pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
|
||||||
if( pParser ){
|
if( pParser ){
|
||||||
pParser->yyidx = -1;
|
|
||||||
#ifdef YYTRACKMAXSTACKDEPTH
|
#ifdef YYTRACKMAXSTACKDEPTH
|
||||||
pParser->yyidxMax = 0;
|
pParser->yyhwm = 0;
|
||||||
#endif
|
#endif
|
||||||
#if YYSTACKDEPTH<=0
|
#if YYSTACKDEPTH<=0
|
||||||
|
pParser->yytos = NULL;
|
||||||
pParser->yystack = NULL;
|
pParser->yystack = NULL;
|
||||||
pParser->yystksz = 0;
|
pParser->yystksz = 0;
|
||||||
yyGrowStack(pParser);
|
if( yyGrowStack(pParser) ){
|
||||||
|
pParser->yystack = &pParser->yystk0;
|
||||||
|
pParser->yystksz = 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef YYNOERRORRECOVERY
|
||||||
|
pParser->yyerrcnt = -1;
|
||||||
|
#endif
|
||||||
|
pParser->yytos = pParser->yystack;
|
||||||
|
pParser->yystack[0].stateno = 0;
|
||||||
|
pParser->yystack[0].major = 0;
|
||||||
}
|
}
|
||||||
return pParser;
|
return pParser;
|
||||||
}
|
}
|
||||||
|
@ -378,8 +402,9 @@ static void yy_destructor(
|
||||||
*/
|
*/
|
||||||
static void yy_pop_parser_stack(yyParser *pParser){
|
static void yy_pop_parser_stack(yyParser *pParser){
|
||||||
yyStackEntry *yytos;
|
yyStackEntry *yytos;
|
||||||
assert( pParser->yyidx>=0 );
|
assert( pParser->yytos!=0 );
|
||||||
yytos = &pParser->yystack[pParser->yyidx--];
|
assert( pParser->yytos > pParser->yystack );
|
||||||
|
yytos = pParser->yytos--;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE,"%sPopping %s\n",
|
fprintf(yyTraceFILE,"%sPopping %s\n",
|
||||||
|
@ -390,10 +415,10 @@ static void yy_pop_parser_stack(yyParser *pParser){
|
||||||
yy_destructor(pParser, yytos->major, &yytos->minor);
|
yy_destructor(pParser, yytos->major, &yytos->minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Deallocate and destroy a parser. Destructors are called for
|
** Deallocate and destroy a parser. Destructors are called for
|
||||||
** all stack elements before shutting the parser down.
|
** all stack elements before shutting the parser down.
|
||||||
*
|
**
|
||||||
** If the YYPARSEFREENEVERNULL macro exists (for example because it
|
** If the YYPARSEFREENEVERNULL macro exists (for example because it
|
||||||
** is defined in a %include section of the input grammar) then it is
|
** is defined in a %include section of the input grammar) then it is
|
||||||
** assumed that the input pointer is never NULL.
|
** assumed that the input pointer is never NULL.
|
||||||
|
@ -406,9 +431,9 @@ void ParseFree(
|
||||||
#ifndef YYPARSEFREENEVERNULL
|
#ifndef YYPARSEFREENEVERNULL
|
||||||
if( pParser==0 ) return;
|
if( pParser==0 ) return;
|
||||||
#endif
|
#endif
|
||||||
while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
|
while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
|
||||||
#if YYSTACKDEPTH<=0
|
#if YYSTACKDEPTH<=0
|
||||||
free(pParser->yystack);
|
if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
|
||||||
#endif
|
#endif
|
||||||
(*freeProc)((void*)pParser);
|
(*freeProc)((void*)pParser);
|
||||||
}
|
}
|
||||||
|
@ -419,7 +444,7 @@ void ParseFree(
|
||||||
#ifdef YYTRACKMAXSTACKDEPTH
|
#ifdef YYTRACKMAXSTACKDEPTH
|
||||||
int ParseStackPeak(void *p){
|
int ParseStackPeak(void *p){
|
||||||
yyParser *pParser = (yyParser*)p;
|
yyParser *pParser = (yyParser*)p;
|
||||||
return pParser->yyidxMax;
|
return pParser->yyhwm;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -432,56 +457,53 @@ static unsigned int yy_find_shift_action(
|
||||||
YYCODETYPE iLookAhead /* The look-ahead token */
|
YYCODETYPE iLookAhead /* The look-ahead token */
|
||||||
){
|
){
|
||||||
int i;
|
int i;
|
||||||
int stateno = pParser->yystack[pParser->yyidx].stateno;
|
int stateno = pParser->yytos->stateno;
|
||||||
|
|
||||||
if( stateno>=YY_MIN_REDUCE ) return stateno;
|
if( stateno>=YY_MIN_REDUCE ) return stateno;
|
||||||
assert( stateno <= YY_SHIFT_COUNT );
|
assert( stateno <= YY_SHIFT_COUNT );
|
||||||
do{
|
do{
|
||||||
i = yy_shift_ofst[stateno];
|
i = yy_shift_ofst[stateno];
|
||||||
if( i==YY_SHIFT_USE_DFLT ) return yy_default[stateno];
|
|
||||||
assert( iLookAhead!=YYNOCODE );
|
assert( iLookAhead!=YYNOCODE );
|
||||||
i += iLookAhead;
|
i += iLookAhead;
|
||||||
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
|
if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
|
||||||
if( iLookAhead>0 ){
|
|
||||||
#ifdef YYFALLBACK
|
#ifdef YYFALLBACK
|
||||||
YYCODETYPE iFallback; /* Fallback token */
|
YYCODETYPE iFallback; /* Fallback token */
|
||||||
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
|
if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
|
||||||
&& (iFallback = yyFallback[iLookAhead])!=0 ){
|
&& (iFallback = yyFallback[iLookAhead])!=0 ){
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
|
fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
|
||||||
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
|
yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
|
||||||
}
|
|
||||||
#endif
|
|
||||||
assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
|
|
||||||
iLookAhead = iFallback;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
|
||||||
|
iLookAhead = iFallback;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef YYWILDCARD
|
#ifdef YYWILDCARD
|
||||||
{
|
{
|
||||||
int j = i - iLookAhead + YYWILDCARD;
|
int j = i - iLookAhead + YYWILDCARD;
|
||||||
if(
|
if(
|
||||||
#if YY_SHIFT_MIN+YYWILDCARD<0
|
#if YY_SHIFT_MIN+YYWILDCARD<0
|
||||||
j>=0 &&
|
j>=0 &&
|
||||||
#endif
|
#endif
|
||||||
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
|
#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
|
||||||
j<YY_ACTTAB_COUNT &&
|
j<YY_ACTTAB_COUNT &&
|
||||||
#endif
|
#endif
|
||||||
yy_lookahead[j]==YYWILDCARD
|
yy_lookahead[j]==YYWILDCARD && iLookAhead>0
|
||||||
){
|
){
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
|
fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
|
||||||
yyTracePrompt, yyTokenName[iLookAhead],
|
yyTracePrompt, yyTokenName[iLookAhead],
|
||||||
yyTokenName[YYWILDCARD]);
|
yyTokenName[YYWILDCARD]);
|
||||||
}
|
|
||||||
#endif /* NDEBUG */
|
|
||||||
return yy_action[j];
|
|
||||||
}
|
}
|
||||||
|
#endif /* NDEBUG */
|
||||||
|
return yy_action[j];
|
||||||
}
|
}
|
||||||
#endif /* YYWILDCARD */
|
|
||||||
}
|
}
|
||||||
|
#endif /* YYWILDCARD */
|
||||||
return yy_default[stateno];
|
return yy_default[stateno];
|
||||||
}else{
|
}else{
|
||||||
return yy_action[i];
|
return yy_action[i];
|
||||||
|
@ -500,7 +522,7 @@ static int yy_find_reduce_action(
|
||||||
int i;
|
int i;
|
||||||
#ifdef YYERRORSYMBOL
|
#ifdef YYERRORSYMBOL
|
||||||
if( stateno>YY_REDUCE_COUNT ){
|
if( stateno>YY_REDUCE_COUNT ){
|
||||||
return yy_default[stateno];
|
return yy_default[stateno];
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
assert( stateno<=YY_REDUCE_COUNT );
|
assert( stateno<=YY_REDUCE_COUNT );
|
||||||
|
@ -525,15 +547,15 @@ static int yy_find_reduce_action(
|
||||||
*/
|
*/
|
||||||
static void yyStackOverflow(yyParser *yypParser){
|
static void yyStackOverflow(yyParser *yypParser){
|
||||||
ParseARG_FETCH;
|
ParseARG_FETCH;
|
||||||
yypParser->yyidx--;
|
yypParser->yytos--;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
|
fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
|
||||||
/* Here code is inserted which will execute if the parser
|
/* Here code is inserted which will execute if the parser
|
||||||
** stack ever overflows */
|
** stack every overflows */
|
||||||
/******** Begin %stack_overflow code ******************************************/
|
/******** Begin %stack_overflow code ******************************************/
|
||||||
%%
|
%%
|
||||||
/******** End %stack_overflow code ********************************************/
|
/******** End %stack_overflow code ********************************************/
|
||||||
|
@ -548,11 +570,11 @@ static void yyTraceShift(yyParser *yypParser, int yyNewState){
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
if( yyNewState<YYNSTATE ){
|
if( yyNewState<YYNSTATE ){
|
||||||
fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
|
fprintf(yyTraceFILE,"%sShift '%s', go to state %d\n",
|
||||||
yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major],
|
yyTracePrompt,yyTokenName[yypParser->yytos->major],
|
||||||
yyNewState);
|
yyNewState);
|
||||||
}else{
|
}else{
|
||||||
fprintf(yyTraceFILE,"%sShift '%s'\n",
|
fprintf(yyTraceFILE,"%sShift '%s'\n",
|
||||||
yyTracePrompt,yyTokenName[yypParser->yystack[yypParser->yyidx].major]);
|
yyTracePrompt,yyTokenName[yypParser->yytos->major]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -570,27 +592,30 @@ static void yy_shift(
|
||||||
ParseTOKENTYPE yyMinor /* The minor token to shift in */
|
ParseTOKENTYPE yyMinor /* The minor token to shift in */
|
||||||
){
|
){
|
||||||
yyStackEntry *yytos;
|
yyStackEntry *yytos;
|
||||||
yypParser->yyidx++;
|
yypParser->yytos++;
|
||||||
#ifdef YYTRACKMAXSTACKDEPTH
|
#ifdef YYTRACKMAXSTACKDEPTH
|
||||||
if( yypParser->yyidx>yypParser->yyidxMax ){
|
if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
|
||||||
yypParser->yyidxMax = yypParser->yyidx;
|
yypParser->yyhwm++;
|
||||||
|
assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if YYSTACKDEPTH>0
|
#if YYSTACKDEPTH>0
|
||||||
if( yypParser->yyidx>=YYSTACKDEPTH ){
|
if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
|
||||||
yyStackOverflow(yypParser);
|
yyStackOverflow(yypParser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if( yypParser->yyidx>=yypParser->yystksz ){
|
if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
|
||||||
yyGrowStack(yypParser);
|
if( yyGrowStack(yypParser) ){
|
||||||
if( yypParser->yyidx>=yypParser->yystksz ){
|
|
||||||
yyStackOverflow(yypParser);
|
yyStackOverflow(yypParser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
yytos = &yypParser->yystack[yypParser->yyidx];
|
if( yyNewState > YY_MAX_SHIFT ){
|
||||||
|
yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
||||||
|
}
|
||||||
|
yytos = yypParser->yytos;
|
||||||
yytos->stateno = (YYACTIONTYPE)yyNewState;
|
yytos->stateno = (YYACTIONTYPE)yyNewState;
|
||||||
yytos->major = (YYCODETYPE)yyMajor;
|
yytos->major = (YYCODETYPE)yyMajor;
|
||||||
yytos->minor.yy0 = yyMinor;
|
yytos->minor.yy0 = yyMinor;
|
||||||
|
@ -622,7 +647,7 @@ static void yy_reduce(
|
||||||
yyStackEntry *yymsp; /* The top of the parser's stack */
|
yyStackEntry *yymsp; /* The top of the parser's stack */
|
||||||
int yysize; /* Amount to pop the stack */
|
int yysize; /* Amount to pop the stack */
|
||||||
ParseARG_FETCH;
|
ParseARG_FETCH;
|
||||||
yymsp = &yypParser->yystack[yypParser->yyidx];
|
yymsp = yypParser->yytos;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
|
if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
|
||||||
yysize = yyRuleInfo[yyruleno].nrhs;
|
yysize = yyRuleInfo[yyruleno].nrhs;
|
||||||
|
@ -636,22 +661,23 @@ static void yy_reduce(
|
||||||
** enough on the stack to push the LHS value */
|
** enough on the stack to push the LHS value */
|
||||||
if( yyRuleInfo[yyruleno].nrhs==0 ){
|
if( yyRuleInfo[yyruleno].nrhs==0 ){
|
||||||
#ifdef YYTRACKMAXSTACKDEPTH
|
#ifdef YYTRACKMAXSTACKDEPTH
|
||||||
if( yypParser->yyidx>yypParser->yyidxMax ){
|
if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
|
||||||
yypParser->yyidxMax = yypParser->yyidx;
|
yypParser->yyhwm++;
|
||||||
|
assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if YYSTACKDEPTH>0
|
#if YYSTACKDEPTH>0
|
||||||
if( yypParser->yyidx>=YYSTACKDEPTH-1 ){
|
if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH-1] ){
|
||||||
yyStackOverflow(yypParser);
|
yyStackOverflow(yypParser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if( yypParser->yyidx>=yypParser->yystksz-1 ){
|
if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
|
||||||
yyGrowStack(yypParser);
|
if( yyGrowStack(yypParser) ){
|
||||||
if( yypParser->yyidx>=yypParser->yystksz-1 ){
|
|
||||||
yyStackOverflow(yypParser);
|
yyStackOverflow(yypParser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
yymsp = yypParser->yytos;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -674,15 +700,17 @@ static void yy_reduce(
|
||||||
yysize = yyRuleInfo[yyruleno].nrhs;
|
yysize = yyRuleInfo[yyruleno].nrhs;
|
||||||
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
|
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
|
||||||
if( yyact <= YY_MAX_SHIFTREDUCE ){
|
if( yyact <= YY_MAX_SHIFTREDUCE ){
|
||||||
if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
if( yyact>YY_MAX_SHIFT ){
|
||||||
yypParser->yyidx -= yysize - 1;
|
yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
||||||
|
}
|
||||||
yymsp -= yysize-1;
|
yymsp -= yysize-1;
|
||||||
|
yypParser->yytos = yymsp;
|
||||||
yymsp->stateno = (YYACTIONTYPE)yyact;
|
yymsp->stateno = (YYACTIONTYPE)yyact;
|
||||||
yymsp->major = (YYCODETYPE)yygoto;
|
yymsp->major = (YYCODETYPE)yygoto;
|
||||||
yyTraceShift(yypParser, yyact);
|
yyTraceShift(yypParser, yyact);
|
||||||
}else{
|
}else{
|
||||||
assert( yyact == YY_ACCEPT_ACTION );
|
assert( yyact == YY_ACCEPT_ACTION );
|
||||||
yypParser->yyidx -= yysize;
|
yypParser->yytos -= yysize;
|
||||||
yy_accept(yypParser);
|
yy_accept(yypParser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -700,7 +728,7 @@ static void yy_parse_failed(
|
||||||
fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
|
fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
|
||||||
/* Here code is inserted which will be executed whenever the
|
/* Here code is inserted which will be executed whenever the
|
||||||
** parser fails */
|
** parser fails */
|
||||||
/************ Begin %parse_failure code ***************************************/
|
/************ Begin %parse_failure code ***************************************/
|
||||||
|
@ -738,7 +766,10 @@ static void yy_accept(
|
||||||
fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
|
fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
|
#ifndef YYNOERRORRECOVERY
|
||||||
|
yypParser->yyerrcnt = -1;
|
||||||
|
#endif
|
||||||
|
assert( yypParser->yytos==yypParser->yystack );
|
||||||
/* Here code is inserted which will be executed whenever the
|
/* Here code is inserted which will be executed whenever the
|
||||||
** parser accepts */
|
** parser accepts */
|
||||||
/*********** Begin %parse_accept code *****************************************/
|
/*********** Begin %parse_accept code *****************************************/
|
||||||
|
@ -782,28 +813,8 @@ void Parse(
|
||||||
#endif
|
#endif
|
||||||
yyParser *yypParser; /* The parser */
|
yyParser *yypParser; /* The parser */
|
||||||
|
|
||||||
/* (re)initialize the parser, if necessary */
|
|
||||||
yypParser = (yyParser*)yyp;
|
yypParser = (yyParser*)yyp;
|
||||||
if( yypParser->yyidx<0 ){
|
assert( yypParser->yytos!=0 );
|
||||||
#if YYSTACKDEPTH<=0
|
|
||||||
if( yypParser->yystksz <=0 ){
|
|
||||||
yyStackOverflow(yypParser);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
yypParser->yyidx = 0;
|
|
||||||
#ifndef YYNOERRORRECOVERY
|
|
||||||
yypParser->yyerrcnt = -1;
|
|
||||||
#endif
|
|
||||||
yypParser->yystack[0].stateno = 0;
|
|
||||||
yypParser->yystack[0].major = 0;
|
|
||||||
#ifndef NDEBUG
|
|
||||||
if( yyTraceFILE ){
|
|
||||||
fprintf(yyTraceFILE,"%sInitialize. Empty stack. State 0\n",
|
|
||||||
yyTracePrompt);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
|
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
|
||||||
yyendofinput = (yymajor==0);
|
yyendofinput = (yymajor==0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -818,7 +829,6 @@ void Parse(
|
||||||
do{
|
do{
|
||||||
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
|
yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
|
||||||
if( yyact <= YY_MAX_SHIFTREDUCE ){
|
if( yyact <= YY_MAX_SHIFTREDUCE ){
|
||||||
if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
|
||||||
yy_shift(yypParser,yyact,yymajor,yyminor);
|
yy_shift(yypParser,yyact,yymajor,yyminor);
|
||||||
#ifndef YYNOERRORRECOVERY
|
#ifndef YYNOERRORRECOVERY
|
||||||
yypParser->yyerrcnt--;
|
yypParser->yyerrcnt--;
|
||||||
|
@ -827,11 +837,11 @@ void Parse(
|
||||||
}else if( yyact <= YY_MAX_REDUCE ){
|
}else if( yyact <= YY_MAX_REDUCE ){
|
||||||
yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
|
yy_reduce(yypParser,yyact-YY_MIN_REDUCE);
|
||||||
}else{
|
}else{
|
||||||
|
assert( yyact == YY_ERROR_ACTION );
|
||||||
|
yyminorunion.yy0 = yyminor;
|
||||||
#ifdef YYERRORSYMBOL
|
#ifdef YYERRORSYMBOL
|
||||||
int yymx;
|
int yymx;
|
||||||
#endif
|
#endif
|
||||||
assert( yyact == YY_ERROR_ACTION );
|
|
||||||
yyminorunion.yy0 = yyminor;
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
|
fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
|
||||||
|
@ -840,7 +850,7 @@ void Parse(
|
||||||
#ifdef YYERRORSYMBOL
|
#ifdef YYERRORSYMBOL
|
||||||
/* A syntax error has occurred.
|
/* A syntax error has occurred.
|
||||||
** The response to an error depends upon whether or not the
|
** The response to an error depends upon whether or not the
|
||||||
** grammar defines an error token "ERROR".
|
** grammar defines an error token "ERROR".
|
||||||
**
|
**
|
||||||
** This is what we do if the grammar does define ERROR:
|
** This is what we do if the grammar does define ERROR:
|
||||||
**
|
**
|
||||||
|
@ -860,7 +870,7 @@ void Parse(
|
||||||
if( yypParser->yyerrcnt<0 ){
|
if( yypParser->yyerrcnt<0 ){
|
||||||
yy_syntax_error(yypParser,yymajor,yyminor);
|
yy_syntax_error(yypParser,yymajor,yyminor);
|
||||||
}
|
}
|
||||||
yymx = yypParser->yystack[yypParser->yyidx].major;
|
yymx = yypParser->yytos->major;
|
||||||
if( yymx==YYERRORSYMBOL || yyerrorhit ){
|
if( yymx==YYERRORSYMBOL || yyerrorhit ){
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
|
@ -871,18 +881,20 @@ void Parse(
|
||||||
yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
|
yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
}else{
|
}else{
|
||||||
while(
|
while( yypParser->yytos >= yypParser->yystack
|
||||||
yypParser->yyidx >= 0 &&
|
&& yymx != YYERRORSYMBOL
|
||||||
yymx != YYERRORSYMBOL &&
|
&& (yyact = yy_find_reduce_action(
|
||||||
(yyact = yy_find_reduce_action(
|
yypParser->yytos->stateno,
|
||||||
yypParser->yystack[yypParser->yyidx].stateno,
|
|
||||||
YYERRORSYMBOL)) >= YY_MIN_REDUCE
|
YYERRORSYMBOL)) >= YY_MIN_REDUCE
|
||||||
){
|
){
|
||||||
yy_pop_parser_stack(yypParser);
|
yy_pop_parser_stack(yypParser);
|
||||||
}
|
}
|
||||||
if( yypParser->yyidx < 0 || yymajor==0 ){
|
if( yypParser->yytos < yypParser->yystack || yymajor==0 ){
|
||||||
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
||||||
yy_parse_failed(yypParser);
|
yy_parse_failed(yypParser);
|
||||||
|
#ifndef YYNOERRORRECOVERY
|
||||||
|
yypParser->yyerrcnt = -1;
|
||||||
|
#endif
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
}else if( yymx!=YYERRORSYMBOL ){
|
}else if( yymx!=YYERRORSYMBOL ){
|
||||||
yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
|
yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
|
||||||
|
@ -901,7 +913,7 @@ void Parse(
|
||||||
yy_syntax_error(yypParser,yymajor, yyminor);
|
yy_syntax_error(yypParser,yymajor, yyminor);
|
||||||
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
|
|
||||||
#else /* YYERRORSYMBOL is not defined */
|
#else /* YYERRORSYMBOL is not defined */
|
||||||
/* This is what we do if the grammar does not define ERROR:
|
/* This is what we do if the grammar does not define ERROR:
|
||||||
**
|
**
|
||||||
|
@ -919,18 +931,23 @@ void Parse(
|
||||||
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
||||||
if( yyendofinput ){
|
if( yyendofinput ){
|
||||||
yy_parse_failed(yypParser);
|
yy_parse_failed(yypParser);
|
||||||
|
#ifndef YYNOERRORRECOVERY
|
||||||
|
yypParser->yyerrcnt = -1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
|
}while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack );
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if( yyTraceFILE ){
|
if( yyTraceFILE ){
|
||||||
int i;
|
yyStackEntry *i;
|
||||||
|
char cDiv = '[';
|
||||||
fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
|
fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
|
||||||
for(i=1; i<=yypParser->yyidx; i++)
|
for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
|
||||||
fprintf(yyTraceFILE,"%c%s", i==1 ? '[' : ' ',
|
fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
|
||||||
yyTokenName[yypParser->yystack[i].major]);
|
cDiv = ' ';
|
||||||
|
}
|
||||||
fprintf(yyTraceFILE,"]\n");
|
fprintf(yyTraceFILE,"]\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue