V6/usr/doc/yacc/ss6r

Find at most related files.
including files from this version of Unix.

.SH
Section 6R: The Ratfor Language Yacc Environment
.PP
For reasons of portability or compatibility with existing
software, it may be desired to use Yacc to generate parsers
in Ratfor, or, by extension, in portable Fortran.
The user is likely to work considerably harder doing this
than he might if he were to use C.
.PP
When the user inputs a specification to Yacc, and specifies the Ratfor option (see Appendix B), the
output is a file of Ratfor programs called ``y.tab.r''.
These programs are then compiled,
and provide the desired subroutine.
.PP
The subroutine produced by Yacc which does the input process is an integer function
called ``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 the
endmarker (type number 0), and the parser accepts.
In this case, yypars returns 0.
.PP
Unlike the C program situation
(see Section 6C) there is no library
of Ratfor routines which must be used in the loading process.
As a side effect of this,
.ul
the user must supply a main program which calls yypars.
A suggested Ratfor main program is
.DS
integer yypars
n = yypars(0)
if( n .EQ. 0 ) {
	. . .  here if the program accepted
} else {
	. . .  here if there were unrecoverable errors
}
end
.DE
Notice that there is no easy way for the user to get control when
an error is detected, since the Fortran language provides only
a very crude character string capability.
.PP
There is another feature which the Ratfor user
might 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 flag
is kept in a common variable yydebu, which
is available to the actions and may be set and reset at will.
.PP
Statement labels 1 through 1000 are reserved for the
parser, and may not appear in actions; note that, because Ratfor
has a more modern control structure than Fortran, it is rarely necessary
to use statement labels at all; the most frequent use of labels in Ratfor is
in formatted I/O.
.PP
Because Fortran has no standard character set
and not even a standard character width,
it is difficult to produce a lexical analyzer
in portable Fortran
The usual solution is to provide a routine
which 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.
.PP
Finally, we must warn the user that the Ratfor feature of Yacc
has been operational for a much shorter time than the
other portions of the system.
If past experience is any
guide, the Ratfor support will develop and become more
powerful and better human engineered in response to user complaints and requirements.
Thus, the potential Ratfor user might do well to contact
the author to discuss his own particular needs.