Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
yacc(1)				 User Commands			       yacc(1)

       yacc - yet another compiler-compiler

       /usr/ccs/bin/yacc [-dltVv] [-b file_prefix] [ -Q

	[y | n]	] [-P parser] [-p sym_prefix] file

       The  yacc  command converts a context-free grammar into a set of	tables
       for a simple automaton that executes an LALR(1) parsing algorithm.  The
       grammar	may be ambiguous. Specified precedence rules are used to break

       The output file,, must be compiled by the C compiler to produce
       a function yyparse(). This program must be loaded with the lexical ana-
       lyzer program, yylex(), as well as main() and yyerror(),	an error  han-
       dling  routine. These routines must be supplied by the user. The	lex(1)
       command is useful for creating lexical analyzers	usable by yacc.

       The following options are supported:

       -b file_prefix
	     Use file_prefix instead of	y as the prefix	for all	output	files.
	     The  code	file, the header file (created when -d
	     is	specified), and	the description	file y.output (created when -v
	     is	 specified),  will  be changed to, file_pre-,	and file_prefix.output,	respectively.

       -d    Generates the file	with the #define statements that asso-
	     ciate the yacc user-assigned "token codes"	with the user-declared
	     "token names". This association allows source  files  other  than to	access the token codes.

       -l    Specifies	that the code produced in will not contain any
	     #line constructs. This option should only be used after the gram-
	     mar and the associated actions are	fully debugged.

       -P parser
	     Allows  you  to  specify  the  parser  of	your choice instead of
	     /usr/ccs/bin/yaccpar. For example,	you can	specify:

	     example% yacc -P ~/myparser parser.y

       -p sym_prefix
	     Uses sym_prefix instead of	yy as  the  prefix  for	 all  external
	     names  produced by	yacc. The names	affected include the functions
	     yyparse(),	yylex()	and yyerror(), and the variables  yylval,  yy-
	     char and yydebug. (In the remainder of this section, the six sym-
	     bols cited	are referenced using their default names only as a no-
	     tational convenience.) Local names	may also be affected by	the -p
	     option. However, the -p option does not  affect  #define  symbols
	     generated by yacc.

	     The  -Qy option puts the version stamping information in
	     This allows you to	know what version of yacc built	the file.  The
	     -Qn option	(the default) writes no	version	information.

       -t    Compiles  runtime	debugging  code	 by default. Runtime debugging
	     code is always generated in under conditional compilation
	     control.  By  default,  this code is not included when is
	     compiled. Whether or not the -t option is used, the  runtime  de-
	     bugging  code  is	under  the control of YYDEBUG ,	a preprocessor
	     symbol. If	YYDEBUG	has a non-zero value, then the debugging  code
	     is	 included.  If	its  value is 0, then the code will not	be in-
	     cluded. The size and execution time of a program produced without
	     the runtime debugging code	will be	smaller	and slightly faster.

       -V    Prints  on	 the standard error output the version information for

       -v    Prepares the file y.output, which contains	a description  of  the
	     parsing tables and	a report on conflicts generated	by ambiguities
	     in	the grammar.

       The following operand is	required:

       file  A path name of a file containing instructions for which a	parser
	     is	to be created.

       Example 1: Accessing the	yacc library

       Access  to the yacc library is obtained with library search operands to
       cc. To use the yacc library main:

       example%	cc -ly

       Both the	lex library and	the yacc library contain main. To  access  the
       yacc main:

       example%	cc lex.yy.c -ly	-ll

       This  ensures that the yacc library is searched first, so that its main
       is used.

       The historical yacc libraries have contained two	simple functions  that
       are  normally  coded by the application programmer. These library func-
       tions are similar to the	following code:

       #include	<locale.h>
       int main(void)
	       extern int yyparse();

	       setlocale(LC_ALL, "");

	       /* If the following parser is one created by lex, the
		  application must be careful to ensure	that LC_CTYPE
		  and LC_COLLATE are set to the	POSIX locale.  */
	       (void) yyparse();
	       return (0);

       #include	<stdio.h>

       int yyerror(const char *msg)
	       (void) fprintf(stderr, "%s\n", msg);
	       return (0);

       See environ(5) for descriptions of the following	environment  variables
       that affect the execution of yacc: LC_CTYPE, LC_MESSAGES, and NLSPATH.

       yacc  can handle	characters from	EUC primary and	supplementary codesets
       as one-token symbols.  EUC codes	may only be  single  character	quoted
       terminal	 symbols.  yacc	 expects  yylex()  to  return a	wide character
       (wchar_t) value for these one-token symbols.

       The following exit values are returned:

       0     Successful	completion.

       >0    An	error occurred.

	     state transitions of the generated	parser
	     source code of the	generated parser
	     header file for the generated parser

	     temporary file

	     temporary file

	     temporary file

	     parser prototype for C programs

       See attributes(5) for descriptions of the following attributes:

       |      ATTRIBUTE	TYPE	     |	    ATTRIBUTE VALUE	   |
       |Availability		     |SUNWbtool			   |

       cc(1B), lex(1), attributes(5), environ(5)

       The number of reduce-reduce and shift-reduce conflicts is  reported  on
       the  standard  error  output.  A	 more  detailed	report is found	in the
       y.output	file. Similarly, if some rules	are  not  reachable  from  the
       start symbol, this instance is also reported.

       Because file names are fixed, at	most one yacc process can be active in
       a given directory at a given time.

       Users are encouraged to avoid using '$' as part of any identifier name.

SunOS 5.9			  20 Dec 1996			       yacc(1)


Want to link to this manual page? Use this URL:

home | help