mks_yacc

C interface to the parser produced by MKS yacc 

Miscellaneous Information


SYNOPSIS

#define	YYSSIZE	150

int yyparse(void);
#ifdef YACC_WINDOWS
int win_yyparse(void);
#endif

extern int yylex(void);
YYSTYPE yylval;
extern HANDLE hInst;

YYTRACE
YYDEBUG
YYSTATIC
YYALLOC
YYSYNC
YACC_WINDOWS

YYREAD
yyclearin
yyerrok
YYERROR
YYACCEPT
YYABORT
YYRETURN(value)
YYRECOVERING

extern void yyerror(char *, ...);

#if YYDEBUG
int yydebug;
int yyntoken, yynvar, yynstate, yynrule;
typedef struct {
	char	* name;
	short	type, type;
} yyNamedType;
typedef struct {
	char	* name;
	short	type;
} yyTypedRules;
typedef struct {
	int	state, lookahead, errflag, done;
	int	rule, npop;
	short	* states;
	int	nstates;
	YYSTYPE * values;
	int	nvalues;
	short	* types;
} yyTraceItems;

char * yysvar[];
yyNamedType yyTokenTypes[];
yyTypedRules yyRules[];
long yyStates[];

short yyrmap[], yysmap[];

int yyGetType(int token);
char* yyptok(int token);
int yyExpandName(int num, int isrule, char * s, int len);

void yyShowState(yyTraceItems *);
void yyShowShift(yyTraceItems *);
void yyShowReduce(yyTraceItems *);
void yyShowGoto(yyTraceItems *);
void yyShowErrRecovery(yyTraceItems *);
void yyShowErrDiscard(yyTraceItems *);
void yyShowRead(int token);
#endif


DESCRIPTION

Constants

YYSSIZE 

defines the size of the state and value stacks that yyparse() uses. Its value can be re-defined when compiling the C code produced by yacc.

Functions

yyparse() 

the name of the parser that yacc generates.

win_yyparse() 

When generating a parser compatible in a Windows environment, yacc renames the standard parser function win_yyparse() as a static function, and create another function yyparse() as a wrapper, responsible for the loading and unloading of resource based tables. This function calls win_yyparse() if tables were loaded without error. Thus, the Windows support is in effect transparent to the user of yyparse(). Ensure that the global variable hInst is set with the window handle of the application prior to calling yyparse when developing a Windows application using lex and yacc.

yylex() 

the lexical scanner that yyparse() calls when a new token is needed. It should return a token value, and possibly assign a value to yylval.

Variables

hInst 

an externally declared variable which holds the window handle of the application. It is used to access the resources which contain the parser tables when an application is developed for Microsoft Windows.

yylval 

the variable to which yylex() should assign a token value. YACC uses the type YYSTYPE to declare yylval(); if you do not use a %union, this defaults to int.

yydebug 

an int variable that is declared if YYDEBUG is defined when compiling the C code produced by yacc. If given a non-zero value, yyparse() displays a debug trace when parsing.

yyntoken, yynvar, yynstate, yynrule 

These constants contain the sizes of various debugging tables.

Compile-time Symbols

YYTRACE 

can be defined when compiling the parser code, to disable the default tracing functions.

Note:

Defining YYTRACE causes YYDEBUG to be defined.

YYDEBUG 

the C preprocessor symbol that determines whether the debugging tables and yydebug variable are declared.

Note:

YYDEBUG is defined if you define YYTRACE.

YYSTATIC 

can be defined to cause the yacc state and value stacks to be declared static; otherwise, the default definition is auto. Using YYSTATIC can save stack space.

YYALLOC 

can be defined to cause the yacc state and value stacks to be allocated dynamically, using malloc(); otherwise, the default definition is auto. Using YYALLOC can save stack and data space. The space is freed when yyparse() returns.

YYSYNC 

can be defined to cause yyparse() to fetch any lookahead before an action.

C Macros

YYREAD 

a macro that can be coded in an action to ensure a lookahead token is available.

yyclearin 

a macro that can be coded in an action to clear any lookahead tokens.

yyerrok 

a macro that can be coded in an action to clear the yacc error condition.

YYERROR 

a macro that can be coded in an action to raise a parse error.

YYACCEPT 

can be coded in an action to cause yyparse to return as though it had succeeded parsing.

YYABORT 

can be coded in an action to cause yyparse() to return as though the parse had failed.

YYRETURN(value

can be coded in an action to cause yyparse() to return the indicated value.

YYRECOVERING 

a condition macro. It can be examined to determine whether or not yyparse() is recovering from a parse error.

YACC_WINDOWS 

this is defined automatically whe creating Windows resources to enable the automatic loading and unloading of the resource based parser tables. This flag should not be enabled manually.

External Functions

yyerror() 

used to print diagnostics. A version of yyerror() is in the library; it simply passes its arguments to vfprintf() with output to the error stream stderr. A newline is written following the message. You can provide replacements.

YACC Tracing

If YYDEBUG is defined as a non-zero value, a number of tracing variables and functions are provided. You can define YYDEBUG by using the -t option to yacc, or by compiling with YYDEBUG or YYTRACE set to a non-zero value.

Tracing Variables

char * yysvar[] 

is a table of the YACC variables (non-terminals) in the grammar.

yyNamedType yyTokenTypes[] 

is a table containing the YACC token names, and their types and token values.

yyTypedRules yyRules[] 

is a table of all the rules in the grammar, and their declared type. The rules are encoded to save space; see yyExpandName().

long yyStates[] 

is a table of offsets into the statesfile produced by YACC with the -s or -S states options. This file contains encoded state strings for the grammar; see yyExpandName().

short yyrmap[] 

contains the mapping from internal to external reduction numbers. YACC encodes numbers to save table space.

short yysmap[] 

is the counterpart to yyrmap for state numbers.

Information Functions

int yyGetType(int token

returns the type of a token, using the yyTokenTypes table.

char * yyptok(int token)> 

returns a printable representation of a given token, using the yyTokenTypes table.

int yyExpandName(int n, int isrule, char* s, int len) 

looks up a state or rule number, and fills in the given string s with a printable representation of this state or rule. If isrule is set, the table yyRules is used to obtain the rule description. Otherwise, the table yyStates is used to determine the index for the state description file states.out, which YACC generates with the -s option. This file contains encoded state information.

In either case, yyExpandName() decodes the description and fills in the given string. If the string is too short, 0 is returned and the characters "..." are appended to the string; otherwise, 1 is returned.

Tracing Functions

void yyShowState(yyTraceItems * tp

is called to display the current state of the parser, before any action is taken. The current state number is in tp->state, and the current lookahead token is in tp->lookahead.

void yyShowShift(yyTraceItems * tp

is called when the parser is about to Shift to a new state. The new state is in tp->state If tp->done is set when YACC resumes, the parse is terminated.

void yyShowReduce(yyTraceItems * tp

is called just before a Reduce is carried out, and before the user action, if any. The rule being reduce is tp->rule, and the number of states being reduced is in tp->npop. If tp->done is set when YACC resumes, the parse is terminated.

void yyShowGoto(yyTraceItems * tp

is called before a Goto to a new state, which YACC takes after a Reduce. The new state is in tp->state. If tp->done. is set when YACC resumes, the parse is terminated.

void yyShowErrRecovery(yyTraceItems * tp

is called when YACC first detects a syntax error, after yyerror() has been called with a

Syntax error

message. The top item of the state stack, which is popped and discarded after this call, is available in

*(tp->states + tp->nstates - 1)

If tp->done. is set when YACC resumes, the parse is terminated.

void yyShowErrDiscard(yyTraceItems * tp

shows the token in tp->lookahead which YACC discards as it tries to resynchronize after an error. If tp->done. is set when YACC resumes, the parse is terminated.

void yyShowRead(int token

is called after a token is read. The new token is available in token.


FILES

ROOTDIR/etcyyparse.c 

prototype YACC parser

ROOTDIR/libmks/*.c 
S

source files for the YACC libraries

ROOTDIR/libmks/*.lib 

YACC library files


AVAILABILITY

PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability


SEE ALSO

Commands:
mks_lex, mks_yacc

Miscellaneous:
mks_lex

YACC Programming Guide


PTC MKS Toolkit 10.4 Documentation Build 39.