home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / doc / yacc / ss6r < prev    next >
Encoding:
Text File  |  1975-06-26  |  3.1 KB  |  78 lines

  1. .SH
  2. Section 6R: The Ratfor Language Yacc Environment
  3. .PP
  4. For reasons of portability or compatibility with existing
  5. software, it may be desired to use Yacc to generate parsers
  6. in Ratfor, or, by extension, in portable Fortran.
  7. The user is likely to work considerably harder doing this
  8. than he might if he were to use C.
  9. .PP
  10. When the user inputs a specification to Yacc, and specifies the Ratfor option (see Appendix B), the
  11. output is a file of Ratfor programs called ``y.tab.r''.
  12. These programs are then compiled,
  13. and provide the desired subroutine.
  14. .PP
  15. The subroutine produced by Yacc which does the input process is an integer function
  16. called ``yypars''.
  17. When it is called,
  18. it in turn repeatedly calls ``yylex'', the lexical analyzer supplied by the user
  19. (see Section 3).
  20. Eventually, either an error is detected, in which case (if no error recovery is possible)
  21. yypars returns the value 1, or the lexical analyzer returns the
  22. endmarker (type number 0), and the parser accepts.
  23. In this case, yypars returns 0.
  24. .PP
  25. Unlike the C program situation
  26. (see Section 6C) there is no library
  27. of Ratfor routines which must be used in the loading process.
  28. As a side effect of this,
  29. .ul
  30. the user must supply a main program which calls yypars.
  31. A suggested Ratfor main program is
  32. .DS
  33. integer yypars
  34. n = yypars(0)
  35. if( n .EQ. 0 ) {
  36.     . . .  here if the program accepted
  37. } else {
  38.     . . .  here if there were unrecoverable errors
  39. }
  40. end
  41. .DE
  42. Notice that there is no easy way for the user to get control when
  43. an error is detected, since the Fortran language provides only
  44. a very crude character string capability.
  45. .PP
  46. There is another feature which the Ratfor user
  47. might wish to use.
  48. The argument to yypars is normally 0.
  49. If it is set to 1, the parser will output a verbose description of its actions,
  50. including a discussion of which input symbols have been read,
  51. and what the parser actions are.
  52. During the input process, the value of this debug flag
  53. is kept in a common variable yydebu, which
  54. is available to the actions and may be set and reset at will.
  55. .PP
  56. Statement labels 1 through 1000 are reserved for the
  57. parser, and may not appear in actions; note that, because Ratfor
  58. has a more modern control structure than Fortran, it is rarely necessary
  59. to use statement labels at all; the most frequent use of labels in Ratfor is
  60. in formatted I/O.
  61. .PP
  62. Because Fortran has no standard character set
  63. and not even a standard character width,
  64. it is difficult to produce a lexical analyzer
  65. in portable Fortran
  66. The usual solution is to provide a routine
  67. which does a table search to get the internal type number for each input character,
  68. with the understanding that such a routine can be recoded to run far faster for any particular machine.
  69. .PP
  70. Finally, we must warn the user that the Ratfor feature of Yacc
  71. has been operational for a much shorter time than the
  72. other portions of the system.
  73. If past experience is any
  74. guide, the Ratfor support will develop and become more
  75. powerful and better human engineered in response to user complaints and requirements.
  76. Thus, the potential Ratfor user might do well to contact
  77. the author to discuss his own particular needs.
  78.