mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-21 19:51:27 +00:00
Lemon update 2016-02-16 21:19:49 on branch parser-performance
- Experimental changes to Lemon for improved parser performance. (user: drh)
This commit is contained in:
parent
7306279a87
commit
75f6d3a438
1 changed files with 50 additions and 37 deletions
|
@ -527,7 +527,7 @@ static int yy_find_reduce_action(
|
||||||
/*
|
/*
|
||||||
** The following routine is called if the stack overflows.
|
** The following routine is called if the stack overflows.
|
||||||
*/
|
*/
|
||||||
static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
|
static void yyStackOverflow(yyParser *yypParser){
|
||||||
ParseARG_FETCH;
|
ParseARG_FETCH;
|
||||||
yypParser->yyidx--;
|
yypParser->yyidx--;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -571,7 +571,7 @@ static void yy_shift(
|
||||||
yyParser *yypParser, /* The parser to be shifted */
|
yyParser *yypParser, /* The parser to be shifted */
|
||||||
int yyNewState, /* The new state to shift in */
|
int yyNewState, /* The new state to shift in */
|
||||||
int yyMajor, /* The major token to shift in */
|
int yyMajor, /* The major token to shift in */
|
||||||
YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
|
ParseTOKENTYPE yyMinor /* The minor token to shift in */
|
||||||
){
|
){
|
||||||
yyStackEntry *yytos;
|
yyStackEntry *yytos;
|
||||||
yypParser->yyidx++;
|
yypParser->yyidx++;
|
||||||
|
@ -582,14 +582,14 @@ static void yy_shift(
|
||||||
#endif
|
#endif
|
||||||
#if YYSTACKDEPTH>0
|
#if YYSTACKDEPTH>0
|
||||||
if( yypParser->yyidx>=YYSTACKDEPTH ){
|
if( yypParser->yyidx>=YYSTACKDEPTH ){
|
||||||
yyStackOverflow(yypParser, yypMinor);
|
yyStackOverflow(yypParser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if( yypParser->yyidx>=yypParser->yystksz ){
|
if( yypParser->yyidx>=yypParser->yystksz ){
|
||||||
yyGrowStack(yypParser);
|
yyGrowStack(yypParser);
|
||||||
if( yypParser->yyidx>=yypParser->yystksz ){
|
if( yypParser->yyidx>=yypParser->yystksz ){
|
||||||
yyStackOverflow(yypParser, yypMinor);
|
yyStackOverflow(yypParser);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ static void yy_shift(
|
||||||
yytos = &yypParser->yystack[yypParser->yyidx];
|
yytos = &yypParser->yystack[yypParser->yyidx];
|
||||||
yytos->stateno = (YYACTIONTYPE)yyNewState;
|
yytos->stateno = (YYACTIONTYPE)yyNewState;
|
||||||
yytos->major = (YYCODETYPE)yyMajor;
|
yytos->major = (YYCODETYPE)yyMajor;
|
||||||
yytos->minor = *yypMinor;
|
yytos->minor.yy0 = yyMinor;
|
||||||
yyTraceShift(yypParser, yyNewState);
|
yyTraceShift(yypParser, yyNewState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,7 +637,32 @@ static void yy_reduce(
|
||||||
}
|
}
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
yygotominor = yyzerominor;
|
/* yygotominor = yyzerominor; */
|
||||||
|
|
||||||
|
/* Check that the stack is large enough to grow by a single entry
|
||||||
|
** if the RHS of the rule is empty. This ensures that there is room
|
||||||
|
** enough on the stack to push the LHS value */
|
||||||
|
if( yyRuleInfo[yyruleno].nrhs==0 ){
|
||||||
|
#ifdef YYTRACKMAXSTACKDEPTH
|
||||||
|
if( yypParser->yyidx>yypParser->yyidxMax ){
|
||||||
|
yypParser->yyidxMax = yypParser->yyidx;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if YYSTACKDEPTH>0
|
||||||
|
if( yypParser->yyidx>=YYSTACKDEPTH ){
|
||||||
|
yyStackOverflow(yypParser);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if( yypParser->yyidx>=yypParser->yystksz ){
|
||||||
|
yyGrowStack(yypParser);
|
||||||
|
if( yypParser->yyidx>=yypParser->yystksz ){
|
||||||
|
yyStackOverflow(yypParser);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
switch( yyruleno ){
|
switch( yyruleno ){
|
||||||
/* Beginning here are the reduction cases. A typical example
|
/* Beginning here are the reduction cases. A typical example
|
||||||
|
@ -655,26 +680,18 @@ static void yy_reduce(
|
||||||
assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
|
assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
|
||||||
yygoto = yyRuleInfo[yyruleno].lhs;
|
yygoto = yyRuleInfo[yyruleno].lhs;
|
||||||
yysize = yyRuleInfo[yyruleno].nrhs;
|
yysize = yyRuleInfo[yyruleno].nrhs;
|
||||||
yypParser->yyidx -= yysize;
|
|
||||||
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 ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
||||||
/* If the reduce action popped at least
|
yypParser->yyidx -= yysize - 1;
|
||||||
** one element off the stack, then we can push the new element back
|
yymsp -= yysize-1;
|
||||||
** onto the stack here, and skip the stack overflow test in yy_shift().
|
yymsp->stateno = (YYACTIONTYPE)yyact;
|
||||||
** That gives a significant speed improvement. */
|
yymsp->major = (YYCODETYPE)yygoto;
|
||||||
if( yysize ){
|
yymsp->minor = yygotominor;
|
||||||
yypParser->yyidx++;
|
yyTraceShift(yypParser, yyact);
|
||||||
yymsp -= yysize-1;
|
|
||||||
yymsp->stateno = (YYACTIONTYPE)yyact;
|
|
||||||
yymsp->major = (YYCODETYPE)yygoto;
|
|
||||||
yymsp->minor = yygotominor;
|
|
||||||
yyTraceShift(yypParser, yyact);
|
|
||||||
}else{
|
|
||||||
yy_shift(yypParser,yyact,yygoto,&yygotominor);
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
assert( yyact == YY_ACCEPT_ACTION );
|
assert( yyact == YY_ACCEPT_ACTION );
|
||||||
|
yypParser->yyidx -= yysize;
|
||||||
yy_accept(yypParser);
|
yy_accept(yypParser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -708,10 +725,10 @@ static void yy_parse_failed(
|
||||||
static void yy_syntax_error(
|
static void yy_syntax_error(
|
||||||
yyParser *yypParser, /* The parser */
|
yyParser *yypParser, /* The parser */
|
||||||
int yymajor, /* The major type of the error token */
|
int yymajor, /* The major type of the error token */
|
||||||
YYMINORTYPE yyminor /* The minor type of the error token */
|
ParseTOKENTYPE yyminor /* The minor type of the error token */
|
||||||
){
|
){
|
||||||
ParseARG_FETCH;
|
ParseARG_FETCH;
|
||||||
#define TOKEN (yyminor.yy0)
|
#define TOKEN yyminor
|
||||||
/************ Begin %syntax_error code ****************************************/
|
/************ Begin %syntax_error code ****************************************/
|
||||||
%%
|
%%
|
||||||
/************ End %syntax_error code ******************************************/
|
/************ End %syntax_error code ******************************************/
|
||||||
|
@ -779,9 +796,7 @@ void Parse(
|
||||||
if( yypParser->yyidx<0 ){
|
if( yypParser->yyidx<0 ){
|
||||||
#if YYSTACKDEPTH<=0
|
#if YYSTACKDEPTH<=0
|
||||||
if( yypParser->yystksz <=0 ){
|
if( yypParser->yystksz <=0 ){
|
||||||
/*memset(&yyminorunion, 0, sizeof(yyminorunion));*/
|
yyStackOverflow(yypParser);
|
||||||
yyminorunion = yyzerominor;
|
|
||||||
yyStackOverflow(yypParser, &yyminorunion);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -798,7 +813,6 @@ void Parse(
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
yyminorunion.yy0 = yyminor;
|
|
||||||
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
|
#if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
|
||||||
yyendofinput = (yymajor==0);
|
yyendofinput = (yymajor==0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -814,7 +828,7 @@ void Parse(
|
||||||
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;
|
if( yyact > YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
|
||||||
yy_shift(yypParser,yyact,yymajor,&yyminorunion);
|
yy_shift(yypParser,yyact,yymajor,yyminor);
|
||||||
#ifndef YYNOERRORRECOVERY
|
#ifndef YYNOERRORRECOVERY
|
||||||
yypParser->yyerrcnt--;
|
yypParser->yyerrcnt--;
|
||||||
#endif
|
#endif
|
||||||
|
@ -826,6 +840,7 @@ void Parse(
|
||||||
int yymx;
|
int yymx;
|
||||||
#endif
|
#endif
|
||||||
assert( yyact == YY_ERROR_ACTION );
|
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);
|
||||||
|
@ -834,7 +849,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:
|
||||||
**
|
**
|
||||||
|
@ -852,7 +867,7 @@ void Parse(
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
if( yypParser->yyerrcnt<0 ){
|
if( yypParser->yyerrcnt<0 ){
|
||||||
yy_syntax_error(yypParser,yymajor,yyminorunion);
|
yy_syntax_error(yypParser,yymajor,yyminor);
|
||||||
}
|
}
|
||||||
yymx = yypParser->yystack[yypParser->yyidx].major;
|
yymx = yypParser->yystack[yypParser->yyidx].major;
|
||||||
if( yymx==YYERRORSYMBOL || yyerrorhit ){
|
if( yymx==YYERRORSYMBOL || yyerrorhit ){
|
||||||
|
@ -862,10 +877,10 @@ void Parse(
|
||||||
yyTracePrompt,yyTokenName[yymajor]);
|
yyTracePrompt,yyTokenName[yymajor]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion);
|
yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
}else{
|
}else{
|
||||||
while(
|
while(
|
||||||
yypParser->yyidx >= 0 &&
|
yypParser->yyidx >= 0 &&
|
||||||
yymx != YYERRORSYMBOL &&
|
yymx != YYERRORSYMBOL &&
|
||||||
(yyact = yy_find_reduce_action(
|
(yyact = yy_find_reduce_action(
|
||||||
|
@ -879,9 +894,7 @@ void Parse(
|
||||||
yy_parse_failed(yypParser);
|
yy_parse_failed(yypParser);
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
}else if( yymx!=YYERRORSYMBOL ){
|
}else if( yymx!=YYERRORSYMBOL ){
|
||||||
YYMINORTYPE u2;
|
yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
|
||||||
u2.YYERRSYMDT = 0;
|
|
||||||
yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yypParser->yyerrcnt = 3;
|
yypParser->yyerrcnt = 3;
|
||||||
|
@ -894,7 +907,7 @@ void Parse(
|
||||||
** Applications can set this macro (for example inside %include) if
|
** Applications can set this macro (for example inside %include) if
|
||||||
** they intend to abandon the parse upon the first syntax error seen.
|
** they intend to abandon the parse upon the first syntax error seen.
|
||||||
*/
|
*/
|
||||||
yy_syntax_error(yypParser,yymajor,yyminorunion);
|
yy_syntax_error(yypParser,yymajor, yyminor);
|
||||||
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
||||||
yymajor = YYNOCODE;
|
yymajor = YYNOCODE;
|
||||||
|
|
||||||
|
@ -909,7 +922,7 @@ void Parse(
|
||||||
** three input tokens have been successfully shifted.
|
** three input tokens have been successfully shifted.
|
||||||
*/
|
*/
|
||||||
if( yypParser->yyerrcnt<=0 ){
|
if( yypParser->yyerrcnt<=0 ){
|
||||||
yy_syntax_error(yypParser,yymajor,yyminorunion);
|
yy_syntax_error(yypParser,yymajor, yyminor);
|
||||||
}
|
}
|
||||||
yypParser->yyerrcnt = 3;
|
yypParser->yyerrcnt = 3;
|
||||||
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
|
||||||
|
|
Loading…
Reference in a new issue