📄 llama.par
字号:
/*@A (C) 1992 Allen I. Holub */
/*--------------------------------------------------------------
* Parser for llama-generated tables
*/
#include <stdio.h>
#include <string.h> /* For strcat(), strlen() prototypes only. */
#include <stdlib.h> /* Needed only for prototype for exit(). Can be */
/* discarded in most non-ANSI systems. */
#ifndef va_start
#include <stdarg.h>
#endif
#include <tools/debug.h> /* These includes are needed to get prototypes */
#include <tools/l.h> /* for the ii_ and yy_ functions in l.lib */
/* You can remove them if your compiler doesn't */
/* require the prototypes. The UNIX and ANSI */
/* macros in debug.h are also used here. */
/* The UNIX, ANSI, BCC, and P, macros in debug.h */
/* are also used here. */
/* Note that there's a nested include for */
/* stdarg.h in <tools/l.h>. */
extern int yylineno; /* Supplied by LeX. */
extern int yyleng;
extern char *yytext;
extern int yylex P((void));
void yycode P(( char *fmt, ... )); /* Supplied below and */
void yydata P(( char *fmt, ... )); /* in yydebug.c */
void yybss P(( char *fmt, ... ));
void yyerror P(( char *fmt, ... ));
void yycomment P(( char *fmt, ... ));
int yy_nextoken P(( void ));
@@ Stuff from code blocks in the header part of the LLama input file goes here.
@@ LLama removes all lines that begin with @@ when it copies llout.par
@@ to the output file.
typedef unsigned char YY_TTYPE; /* Type used for tables. */
#define YYF (YY_TTYPE)( -1 ) /* Failure transition in table. */
/*----------------------------------------------------------------------*/
#define YY_ISTERM(x) (YY_MINTERM <= (x) && (x) <= YY_MAXTERM )
#define YY_ISNONTERM(x) (YY_MINNONTERM <= (x) && (x) <= YY_MAXNONTERM)
#define YY_ISACT(x) (YY_MINACT <= (x) )
#ifndef YYACCEPT
# define YYACCEPT return(0) /* Action taken when input is accepted. */
#endif
#ifndef YYABORT
# define YYABORT return(1) /* Action taken when input is rejected. */
#endif
#ifndef YYPRIVATE
# define YYPRIVATE static /* Define to a null string to make public. */
#endif
#ifndef YYMAXERR
# define YYMAXERR 25 /* Abort after this many errors. */
#endif
#ifndef YYMAXDEPTH /* Parse- and value-stack depth. */
# define YYMAXDEPTH 128
#endif
#ifndef YYSTYPE /* Used to declare fields in value stack. */
# define YYSTYPE int
#endif
int yy_act ( int actnum ); /* Supplied by llama */
YY_TTYPE yy_next ( int cur_state, unsigned c );
/*----------------------------------------------------------------------
* Parse and value stacks:
*/
#include <tools/yystack.h> /* #pp */
/* The yyabort function is needed only to keep Borland C happy. You
* can remove it and put an exit() call into yystk_err under UNIX systems.
*/
static int yyabort P((void)) { exit(1); BCC( return 0; ) }
#undef yystk_cls
#define yystk_cls YYPRIVATE
#undef yystk_err
#define yystk_err(o) ((o) ? (yyerror("Stack overflow\n" ),yyabort()) \
: (yyerror("Stack underflow\n"),yyabort()) )
#define yytos(stk) yystk_item(stk, 0) /* Evaluates to top-of-stack item.#pp*/
yystk_dcl( Yy_stack, int, YYMAXDEPTH );
typedef struct /* Typedef for value-stack elements. */
{
YYSTYPE left; /* Holds value of left-hand side attribute. */
YYSTYPE right; /* Holds value of current-symbol's attribute. */
} yyvstype;
yyvstype Yy_vstack[ YYMAXDEPTH ]; /* Value stack. */
yyvstype *Yy_vsp = Yy_vstack + YYMAXDEPTH; /* Value-stack pointer */
@@
@@ Tables go here. LLama removes all lines that begin with @@ when it copies
@@ llout.par to the output file.
/*----------------------------------------------------------------------*/
FILE *yycodeout = stdout ; /* Output stream for code. */
FILE *yybssout = stdout ; /* Output stream for initialized data. */
FILE *yydataout = stdout ; /* Output stream for uninitialized data. */
int yynerrs = 0; /* Error count. */
/*----------------------------------------------------------------------*/
#ifdef YYDEBUG /* Debugging parse stack. */
yystk_dcl( Yy_dstack, char *, YYMAXDEPTH );
ANSI( YYPRIVATE char *yy_sym( int sym ) )
KnR ( YYPRIVATE char *yy_sym( sym ) )
KnR ( int sym; )
{
/* Return a pointer to a string representing the symbol, using the
* appropriate table to map the symbol to a string.
*/
return ( YY_ISTERM( sym ) || !sym ) ? Yy_stok [sym]:
( YY_ISNONTERM( sym ) ) ? Yy_snonterm [sym - YY_MINNONTERM]:
/* assume it's an act */ Yy_sact [sym - YY_MINACT] ;
}
/* Stack-maintenance. yy_push and yy_pop push and pop items from both the
* parse and symbol stacks simultaneously. The yycomment calls in both routines
* print a message to the comment window saying what just happened. The
* yy_pstack() call refreshes the stack window and also requests a new command
* from the user. That is, in most situations, yy_pstack() won't return until
* the user has typed another command (exceptions are go mode, and so forth).
* yy_pstack() also checks for break points and halts the parse if a breakpoint
* condition is met.
*/
ANSI( YYPRIVATE void yy_push(int x, YYSTYPE val) )
KnR ( YYPRIVATE void yy_push( x, val) )
KnR ( int x; ) /* Push this onto the state stack.*/
KnR ( YYSTYPE val; ) /* Push this onto the value stack.*/
{
yypush ( Yy_stack, x );
yypush_( Yy_dstack, yy_sym(x) );
--Yy_vsp; /* The push() macro checked */
Yy_vsp->left = Yy_vsp->right = val; /* for overflow already. */
yycomment( "push %s\n", yy_sym( x ) );
yy_pstack( 0, 1 );
}
YYPRIVATE int yy_pop P((void))
{
int prev_tos = yypop( Yy_stack );
++Yy_vsp;
yycomment( "pop %s\n", yypop_( Yy_dstack ) );
yy_pstack ( 0, 1 );
return prev_tos;
}
ANSI( YYPRIVATE void yy_say_whats_happening(int tos_item, int production) )
KnR ( YYPRIVATE void yy_say_whats_happening( tos_item, production) )
KnR ( int tos_item; ) /* Item at top of stack */
KnR ( int production; ) /* production number we're about to apply */
{
/* Print a message in the comment window describing the replace operation
* about to be performed. The main problem is that you must assemble a
* string that represents the right-hand side of the indicated production.
* I do this using the appropriate Yy_pushtab element, but go through the
* array backwards (the Yy_pushtab arrays have been reversed to make the
* production-mode parse more efficient--you need to unreverse them here).
* Note that you can't just decrement end, comparing it with start in
* the for loop that does the assembling. That is, this won't work:
* while( --end >= start )
* in the 8086 compact or large models because start might be at the
* beginning of a segment. If it wraps past the start of the segement,
* then end will never be less than start. Consequently, you need the
* loop counter (nterms) to control the number of iterations.
*/
char buf[80]; /* Assemble string representing right-hand side here.*/
int count; /* Maximum size of string representing RHS. */
int *start, *end; /* Start and end of Yy_pushtab array that holds RHS. */
int nterms; /* Number of items to process in the production */
start = Yy_pushtab[ production ];
for( end = start; *end; ++end ) /* After loop, end is positioned */
; /* to right of last valid symbol */
count = sizeof(buf);
*buf = '\0';
for(nterms = end - start; --nterms >= 0 && count > 0 ; ) /* Assemble */
{ /* string. */
strncat( buf, yy_sym(*--end), count );
if( (count -= strlen( yy_sym(*end) + 1 )) < 1 )
break;
strncat( buf, " ", --count );
}
yycomment( "Applying %s->%s\n", yy_sym(tos_item), buf );
}
/* Use the following routines just like printf() to create output. In debug
* mode, all three routines print to the output window (yy_output() is in
* yydebug.c). In production mode, equivalent routines print to the associated
* streams (yycodeout, yybssout, or yydataout). The first argument to
* yy_output() tells the routine which stream is being used. If the stream is
* still set to the default stdout, then the message is written only to the
* window. If the stream has been changed, however, the output is sent both
* to the window and the associated stream.
*/
ANSI( void yycode( char *fmt, ...)) /* Write to the code-segment stream. */
KnR ( void yycode( fmt ))
KnR ( char *fmt; )
{
va_list args;
va_start( args, fmt );
yy_output( 0, fmt, args );
}
ANSI( void yydata( char *fmt, ...)) /* Write to the data-segment stream. */
KnR ( void yydata( fmt ))
KnR ( char *fmt; )
{
va_list args;
va_start( args, fmt );
yy_output( 1, fmt, args );
}
ANSI( void yybss ( char *fmt, ...)) /* Write to the bss-segment stream. */
KnR ( void yybss ( fmt ))
KnR ( char *fmt; )
{
va_list args;
va_start( args, fmt );
yy_output( 2, fmt, args );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -