📄 ss6r
字号:
.SHSection 6R: The Ratfor Language Yacc Environment.PPFor reasons of portability or compatibility with existingsoftware, it may be desired to use Yacc to generate parsersin Ratfor, or, by extension, in portable Fortran.The user is likely to work considerably harder doing thisthan he might if he were to use C..PPWhen the user inputs a specification to Yacc, and specifies the Ratfor option (see Appendix B), theoutput is a file of Ratfor programs called ``y.tab.r''.These programs are then compiled,and provide the desired subroutine..PPThe subroutine produced by Yacc which does the input process is an integer functioncalled ``yypars''.When it is called,it in turn repeatedly calls ``yylex'', the lexical analyzer supplied by the user(see Section 3).Eventually, either an error is detected, in which case (if no error recovery is possible)yypars returns the value 1, or the lexical analyzer returns theendmarker (type number 0), and the parser accepts.In this case, yypars returns 0..PPUnlike the C program situation(see Section 6C) there is no libraryof Ratfor routines which must be used in the loading process.As a side effect of this,.ulthe user must supply a main program which calls yypars.A suggested Ratfor main program is.DSinteger yyparsn = yypars(0)if( n .EQ. 0 ) { . . . here if the program accepted} else { . . . here if there were unrecoverable errors}end.DENotice that there is no easy way for the user to get control whenan error is detected, since the Fortran language provides onlya very crude character string capability..PPThere is another feature which the Ratfor usermight wish to use.The argument to yypars is normally 0.If it is set to 1, the parser will output a verbose description of its actions,including a discussion of which input symbols have been read,and what the parser actions are.During the input process, the value of this debug flagis kept in a common variable yydebu, whichis available to the actions and may be set and reset at will..PPStatement labels 1 through 1000 are reserved for theparser, and may not appear in actions; note that, because Ratforhas a more modern control structure than Fortran, it is rarely necessaryto use statement labels at all; the most frequent use of labels in Ratfor isin formatted I/O..PPBecause Fortran has no standard character setand not even a standard character width,it is difficult to produce a lexical analyzerin portable FortranThe usual solution is to provide a routinewhich does a table search to get the internal type number for each input character,with the understanding that such a routine can be recoded to run far faster for any particular machine..PPFinally, we must warn the user that the Ratfor feature of Yacchas been operational for a much shorter time than theother portions of the system.If past experience is anyguide, the Ratfor support will develop and become morepowerful and better human engineered in response to user complaints and requirements.Thus, the potential Ratfor user might do well to contactthe author to discuss his own particular needs.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -