⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 occs.par

📁 compiler
💻 PAR
📖 第 1 页 / 共 2 页
字号:
    va_list args;
    va_start( args,  fmt );
    vfprintf( yybssout, fmt, args );
}

ANSI( void 	yycomment( char *fmt, ... )	)
KnR ( void 	yycomment( fmt )		)
KnR ( char	*fmt;				)
{
    va_list	 args;
    va_start( args,   fmt );
    vfprintf( stdout, fmt, args );
}

ANSI( void 	yyerror( char *fmt, ... )	)
KnR ( void 	yyerror( fmt )			)
KnR ( char	*fmt;				)
{
    extern char *yytext;
    extern int  yylineno;
    va_list   args;

    va_start( args, fmt );
    fprintf ( stderr, "ERROR (line %d near %s): ", yylineno, yytext );
    vfprintf( stderr, fmt, args );
    fprintf ( stderr, "\n" );
}
#endif



YYPRIVATE  void yy_shift( new_state, lookahead ) /* shift 	      */
int	    new_state;				 /* push this state   */
int	    lookahead;				 /* Current lookahead */
{
    yypush( Yy_stack, new_state );
    --Yy_vsp;			 	 /* Push garbage onto value stack */
    YYSHIFTACT( Yy_vsp );   		 /* Then do default action 	  */

#ifdef YYDEBUG
    yycomment( "Shift %0.16s (%d)\n", Yy_stok[ lookahead ], new_state);
    yypush_( Yy_dstack, Yy_stok[lookahead] );
    yy_pstack(0, 1);
#endif
}
/*----------------------------------------------------------------------*/
YYPRIVATE void yy_reduce( prod_num, amount )
int	prod_num;		/* Reduce by this production 		    */
int	amount;			/* # symbols on right-hand side of prod_num */
{
    int	next_state;

    yypopn( Yy_stack,  amount );	/* Pop n items off the state stack */
    Yy_vsp += amount;			/* and the value stack.		   */
    *--Yy_vsp = Yy_val;		  	/* Push $$ onto value stack	   */

    next_state = yy_next( Yy_goto, yystk_item(Yy_stack,0), Yy_lhs[prod_num] );

#ifndef YYDEBUG

    yypush_ ( Yy_stack, next_state );

#else

    yy_break( prod_num );	    	/* activate production breakpoint */

    yypopn_ ( Yy_dstack, amount );

    YYV( yycomment("    pop %d item%s\n", amount, amount==1 ? "" : "s"); )
    yy_pstack( 0, 0 );

    yypush_ ( Yy_stack,	next_state 	    );
    yypush_ ( Yy_dstack,  Yy_slhs[ prod_num ] );

    YYV( yycomment("    push %0.16s (%d)", Yy_slhs[prod_num], next_state ); )

    yy_pstack ( 0, 1 );
#endif
}

/*----------------------------------------------------------------------*/

YYPRIVATE void yy_init_stack()			/* Initialize the stacks  */
{
    yystk_clear( Yy_stack );
    yypush_    ( Yy_stack,  0 );		/* State stack = 0    	 */

    Yy_vsp = Yy_vstack + (YYMAXDEPTH-1);	/* Value stack = garbage */

#   ifdef YYDEBUG
    yystk_clear  ( Yy_dstack );
    yypush_	 ( Yy_dstack, "$" );
    yycomment	 ( "Shift start state\n" );
    yy_pstack	 (0, 1);			/* refresh stack window */
#   endif
}
/*----------------------------------------------------------------------*/
YYPRIVATE int yy_recover( tok, suppress )
int	tok;		/* token that caused the error		*/
int	suppress;	/* No error message is printed if true  */
{
    int	        *old_sp  = yystk_p(Yy_stack);	     /* State-stack pointer */
    YYD( char  **old_dsp = yystk_p(Yy_dstack); )
    YYD( char   *tos;  				 )

    if( !suppress )
    {
	yyerror( "Unexpected %s\n", Yy_stok[tok] );
	if( ++yynerrs > YYMAXERR )
	{
	    yyerror("Too many errors, aborting\n");
	    return 0;
	}
    }

    do {

	while( !yystk_empty(Yy_stack)
		    && yy_next( Yy_action, yystk_item(Yy_stack,0), tok) == YYF )
	{
	    yypop_( Yy_stack );

	    YYD( tos = yypop_(Yy_dstack); )
	    YYD( yycomment("Popping %s from state stack\n", tos); )
	    YYD( yy_pstack(0, 1);				   )
	}

	if( !yystk_empty(Yy_stack) )		/* Recovered successfully */
	{
	    /* Align the value (and debug) stack to agree with the current
	     * state-stack pointer.
	     */

	    Yy_vsp = Yy_vstack + (YYMAXDEPTH - yystk_ele(Yy_stack)) ;

#	    ifdef YYDEBUG
	    	yystk_p(Yy_dstack) = Yy_dstack +
					(YYMAXDEPTH - yystk_ele(Yy_stack) );
	   	yycomment("Error recovery successful\n");
	    	yy_pstack(0, 1);
#	    endif

	    return tok;
	}

	yystk_p( Yy_stack ) = old_sp ;

	YYD( yystk_p( Yy_dstack ) = old_dsp ;			)
	YYD( yycomment("Restoring state stack."); 		)
	YYD( yy_pstack(1, 1); 			 		)
	YYD( yycomment("discarding %s\n", Yy_stok[tok]);   )

    } while( ii_mark_prev(), tok = yy_nextoken() );

    YYD( yycomment("Error recovery failed\n");	)
    return 0;
}

/*----------------------------------------------------------------------*/

int	yyparse()
{
    /* General-purpose LALR parser. Return 0 normally or -1 if the error
     * recovery fails. Any other value is supplied by the user as a return
     * statement in an action.
     */

    int	act_num ;	 /* Contents of current parse table entry	*/
    int	errcode ;	 /* Error code returned from yy_act()        	*/
    int tchar   ;	 /* Used to \0-terminate the lexeme         	*/
    int suppress_err ; 	 /* Set to YYCASCADE after an error is found    */
			 /* and decremented on each parse cycle. Error	*/
			 /* messages aren't printed if it's true.	*/

#ifdef YYDEBUG
    if( !yy_init_debug( Yy_stack,  &yystk_p(Yy_stack ),
			Yy_dstack, &yystk_p(Yy_dstack),
			Yy_vstack, sizeof(YYSTYPE), YYMAXDEPTH) )
	YYABORT;
#endif

    yy_init_stack ();			/* Initialize parse stack	*/
    yy_init_occs  ( Yy_vsp );

    yylookahead  = yy_nextoken();	/* Get first input symbol	*/
    suppress_err = 0;

    while( 1 )
    {
	act_num = yy_next( Yy_action, yystk_item(Yy_stack,0), yylookahead );

	if( suppress_err )
	    --suppress_err;

	if( act_num == YYF  )
	{
	    if( !(yylookahead = yy_recover( yylookahead, suppress_err )) )
		YYABORT;

	    suppress_err = YYCASCADE;
	}
	else if( YY_IS_SHIFT(act_num) )		     /* Simple shift action */
	{
	    /* Note that yytext and yyleng are undefined at this point because
	     * they were modified in the else clause, below. You must use
	     * ii_text(), etc., to put them into a reasonable condition if
	     * you expect to access them in a YY_SHIFT action.
	     */

	    yy_shift( act_num, yylookahead );

	    ii_mark_prev();
	    yylookahead = yy_nextoken();
	}
	else
	{
	    /* Do a reduction by -act_num. The activity at 1, below, gives YACC
	     * compatibility. It's just making the current lexeme available in
	     * yytext and '\0' terminating the lexeme. The '\0' is removed at 2.
	     * The problem is that you have to read the next lookahead symbol
	     * before you can reduce by the production that had the previous
	     * symbol at its far right. Note that, since Production 0 has the
	     * goal symbol on its left-hand side, a reduce by 0 is an accept
	     * action. Also note that ii_ptext()[ii_plength()] is used at (2)
	     * rather than yytext[yyleng] because the user might have modified
	     * yytext or yyleng in an action.
	     *
	     * Rather than pushing junk as the $$=$1 action on an epsilon
	     * production, the old tos item is duplicated in this situation.
	     */

	    act_num   = -act_num ;
	    Yy_rhslen = Yy_reduce[ act_num  ];
	    Yy_val    = Yy_vsp[ Yy_rhslen ? Yy_rhslen-1 : 0 ]; 	 /* $$ = $1 */

	    if( yytext = (char *) ii_ptext() )			/* (1)     */
	    {
		yylineno       = ii_plineno() ;
		tchar          = yytext[ yyleng = ii_plength() ];
		yytext[yyleng] = '\0' ;
	    }
	    else				/* no previous token */
	    {
		yytext = "";
		yyleng = yylineno = 0;
	    }

#	    ifdef YYDEBUG
	        yycomment("Reduce by (%d) %s->%s\n", act_num,
					Yy_slhs[act_num], Yy_srhs[act_num]);
#	    endif

	    if( errcode = yy_act( act_num, Yy_vsp ) )
		return errcode;

	    if( yylineno )
		ii_ptext()[ ii_plength() ] = tchar;		 /* (2)     */

	    if( act_num == YY_IS_ACCEPT )
		break ;
	    else
		yy_reduce( act_num, Yy_rhslen );
	}
    }
    YYD(  yycomment( "Accept\n" );	)
    YYD(  yy_quit_debug();		)

    YYACCEPT;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -