?? ss8
字號:
.SH8: The Yacc Environment.PPWhen the user inputs a specificationto Yacc, the output is a file of C programs, called.I y.tab.con mostsystems(due to local file system conventions, the names may differ frominstallation to installation).The function produced by Yacc is called.I yyparse \|;it is an integer valued function.When it is called, it in turn repeatedly calls.I yylex ,the lexical analyzersupplied by the user (see Section 3)to obtain input tokens.Eventually, either an error is detected, in which case(if no error recovery is possible).I yyparsereturns the value 1,or the lexical analyzer returns the endmarker tokenand the parser accepts.In this case,.I yyparsereturns the value 0..PPThe user must provide a certain amount of environment for thisparser in order to obtain a working program.For example, as with every C program, a program called.I mainmust be defined, that eventually calls.I yyparse .In addition, a routine called.I yyerrorprints a messagewhen a syntax error is detected..PPThese two routines must be supplied in one form or another by theuser.To ease the initial effort of using Yacc, a library has beenprovided with default versions of.I mainand.I yyerror .The name of this library is system dependent;on many systems the library is accessed by a.B \-lyargument to the loader.To show the triviality of these default programs, the source isgiven below:.DSmain(){ return( yyparse() ); }.DEand.DS# include <stdio.h>yyerror(s) char *s; { fprintf( stderr, "%s\en", s ); }.DEThe argument to.I yyerroris a string containing an error message, usuallythe string ``syntax error''.The average application will want to do better than this.Ordinarily, the program should keep track of the input line number, and print italong with the message when a syntax error is detected.The external integer variable.I yycharcontains the lookahead token number at the time the error was detected;this may be of some interest in giving better diagnostics.Since the.I mainprogram is probably supplied by the user (to read arguments, etc.)the Yacc library is useful only in smallprojects, or in the earliest stages of larger ones..PPThe external integer variable.I yydebugis normally set to 0.If it is set to a nonzero value, the parser will output averbose description of its actions, includinga discussion of which input symbols have been read, andwhat the parser actions are.Depending on the operating environment,it may be possible to set this variable by using a debugging system.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -