yacc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. .TH YACC 1
  2. .SH NAME
  3. yacc \- yet another compiler-compiler
  4. .SH SYNOPSIS
  5. .B yacc
  6. [
  7. .I option ...
  8. ]
  9. .I grammar
  10. .SH DESCRIPTION
  11. .I Yacc
  12. converts a context-free grammar and translation code
  13. into a set of
  14. tables for an LR(1) parser and translator.
  15. The grammar may be ambiguous;
  16. specified precedence rules are used to break ambiguities.
  17. .PP
  18. The output file,
  19. .BR y.tab.c ,
  20. must be compiled by the C compiler
  21. to produce a program
  22. .LR yyparse .
  23. This program must be loaded with a lexical analyzer function,
  24. .B yylex(void)
  25. (often generated by
  26. .IR lex (1)),
  27. with a
  28. .B main(int argc, char *argv[])
  29. program, and with an error handling routine,
  30. .BR yyerror(char*) .
  31. .PP
  32. The options are
  33. .TP "\w'\fL-o \fIoutput\fLXX'u"
  34. .BI -o " output
  35. Direct output to the specified file instead of
  36. .BR y.tab.c .
  37. .TP
  38. .BI -D n
  39. Create file
  40. .BR y.debug ,
  41. containing diagnostic messages.
  42. To incorporate them in the parser, compile it with preprocessor symbol
  43. .B yydebug
  44. defined.
  45. The amount of
  46. diagnostic output from the parser is regulated by
  47. value
  48. .IR n .
  49. The value 0 reports errors; 1 reports reductions;
  50. higher values (up to 4) include more information about
  51. state transitions.
  52. .TP
  53. .B -v
  54. Create file
  55. .BR y.output ,
  56. containing a description of the parsing tables and of
  57. conflicts arising from ambiguities in the grammar.
  58. .TP
  59. .B -d
  60. Create file
  61. .BR y.tab.h ,
  62. containing
  63. .B #define
  64. statements that associate
  65. .IR yacc -assigned
  66. `token codes' with user-declared `token names'.
  67. Include it in source files other than
  68. .B y.tab.c
  69. to give access to the token codes.
  70. .TP
  71. .BI -s " stem
  72. Change the prefix
  73. .L y
  74. of the file names
  75. .BR y.tab.c ,
  76. .BR y.tab.h ,
  77. .BR y.debug ,
  78. and
  79. .B y.output
  80. to
  81. .IR stem .
  82. .TP
  83. .B -S
  84. Write a parser that uses
  85. Stdio
  86. instead of the
  87. .B print
  88. routines in libc.
  89. .PP
  90. The specification of
  91. .I yacc
  92. itself is essentially the same as the UNIX version
  93. described in the references mentioned below.
  94. Besides the
  95. .B -D
  96. option, the main relevant differences are:
  97. .IP
  98. The interface to the C environment is by default through
  99. .B <libc.h>
  100. rather than
  101. .BR <stdio.h> ;
  102. the
  103. .B -S
  104. option reverses this.
  105. .IP
  106. The parser accepts
  107. .SM UTF
  108. input text (see
  109. .IR utf (6)),
  110. which has a couple of effects.
  111. First, the return value of
  112. .B yylex()
  113. no longer fits in a
  114. .BR short ;
  115. second, the starting value for non-terminals is now 0xE000 rather than 257.
  116. .IP
  117. The generated parser can be recursive: actions can call
  118. .IR yyparse ,
  119. for example to implement a sort of
  120. .B #include
  121. statement in an interpreter.
  122. .IP
  123. Finally, some undocumented inner workings of the parser have been
  124. changed, which may affect programs that know too much about its structure.
  125. .SH FILES
  126. .TF /sys/lib/yaccpars
  127. .TP
  128. .B y.output
  129. .TP
  130. .B y.tab.c
  131. .TP
  132. .B y.tab.h
  133. .TP
  134. .B y.debug
  135. .TP
  136. .B y.tmp.*
  137. temporary file
  138. .TP
  139. .B y.acts.*
  140. temporary file
  141. .TP
  142. .B /sys/lib/yaccpar
  143. parser prototype
  144. .TP
  145. .B /sys/lib/yaccpars
  146. parser prototype using stdio
  147. .SH SOURCE
  148. .B /sys/src/cmd/yacc.c
  149. .SH "SEE ALSO"
  150. .IR lex (1)
  151. .br
  152. S. C. Johnson and R. Sethi,
  153. ``Yacc: A parser generator'',
  154. .I
  155. Unix Research System Programmer's Manual,
  156. Tenth Edition, Volume 2
  157. .br
  158. B. W. Kernighan and Rob Pike,
  159. .I
  160. The UNIX Programming Environment,
  161. Prentice Hall, 1984
  162. .SH BUGS
  163. The parser may not have full information when it writes to
  164. .B y.debug
  165. so that the names of the tokens returned by
  166. .L yylex
  167. may be missing.