home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yay-1_0.zip / yay-1_0 / doc / yay10man.ps < prev    next >
Text File  |  1995-12-07  |  254KB  |  2,937 lines

  1. %!PS-Adobe-2.0 ExitServer
  2. %%Title: Microsoft Word Driver Prolog
  3. %%Creator: Microsoft
  4. %%CreationDate: Fri Aug 18 1988
  5. %%BeginDocument: Microsoft Word 5.0 0
  6. %%msinifile: POSTSCRP
  7. %%EndComments
  8. %%BeginExitServer: 0
  9.  userdict /msinifile known 
  10.  {msinifile (POSTSCRP) eq {stop} if} if
  11.  serverdict begin 0 exitserver
  12.  userdict /msorigstate known {msorigstate restore} if
  13.  save /msorigstate exch def
  14.  /msinifile (POSTSCRP) def
  15. %%EndExitServer
  16.  
  17. %%BeginFont: mslinedraw
  18. /mslinedraw 25 dict def
  19. /PSl {msdict begin /ptop 612 def /sw 0 def
  20.  /ftsz 12 def /smode 0 def /STh -3.6 def /fs 0 def /offset 0 def fonttable 1 get fontset E 90 rotate 0 -612 translate save statusdict begin /waittimeout 360 def end} def
  21. /PSp {msdict begin /ptop 792 def /sw 0 def
  22.  /ftsz 12 def /smode 0 def /STh -3.6 def /fs 0 def /offset 0 def fonttable 1 get fontset E save statusdict begin /waittimeout 360 def end} def
  23. mslinedraw begin
  24. /FontType 3 def
  25. /FontMatrix [1.0 30.0 div 0 0 1.0 30.0 div 0 0] def
  26. /FontBBox [0 -8 18 30] def
  27. /Encoding 256 array def
  28. 0 1 255 {Encoding exch /.notdef put} for
  29. Encoding 45 [
  30.  /sp   /sh   /sh /light /med /dark
  31.  /sv   /srj  /sdjr /dsjr /sdtr /dstr /djr  /dv
  32.  /dtr  /dbr  /sdbr /dsbr /str  /sbl  /sjb  /sjt
  33.  /sjl  /sh   /sjc  /sdjl /dsjl /dbl  /dtl  /djb
  34.  /djt  /djl  /dh   /djc  /dsjb /sdjb /dsjt /sdjt
  35.  /sdbl /dsbl /dstl /sdtl  /sdjc /dsjc /sbr  /stl
  36.  /black /bb /bl /br /bt] putinterval
  37.  
  38. /a {moveto lineto stroke} bind def
  39. /b {moveto lineto lineto stroke} bind def
  40. /c {moveto 9 7 lineto stroke} bind def
  41. /d {moveto lineto lineto} bind def
  42. /e {lineto closepath fill} bind def
  43. /f {7 30 7 9 0 9 b} def
  44. /g {12 30 12 9 18 9 b} def
  45. /h {7 -8 7 5 0 5 b} def
  46. /i {12 -8 12 5 18 5 b} def
  47. /j {0 7 18 7 a} def
  48. /k {9 22 9 -8 a} def
  49. /l {0 5 18 5 a 0 9 18 9 a} def
  50. /m {7 22 7 -8 a 12 22 12 -8 a} def
  51. /n {0 -8 18 -8 18 22 d 0 22 e} def
  52.  
  53. /CharProcs 55 dict def
  54. CharProcs begin
  55. /.notdef {} def
  56. /sp { 1 1 moveto } def
  57. /sv {k} def
  58. /srj {k 0 7 c} def
  59. /sdjr {k 0 5 9 5 a 0 9 9 9 a} def
  60. /dsjr {m 0 7 7 7 a} def
  61. /sdtr {0 7 12 7 12 -8 b 7 7 7 -8 a} def
  62. /dstr {0 9 9 9 9 -8 b 0 5 9 5 a} def
  63. /djr {f h 12 -8 12 22 a} def
  64. /dv {m} def
  65. /dtr {h 0 9 12 9 12 -8 b} def
  66. /dbr {f  0 5 12 5 12 30 b} def
  67. /sdbr {0 7 12 7 12 30 b 7 7 7 30 a} def
  68. /dsbr {0 5 9 5 9 30 b 0 9 9 9 a} def
  69. /str {0 7 9 7 9 -8 b} def
  70. /sbl {9 30 9 7 18 7 b} def
  71. /sjb {j 9 30 c} def
  72. /sjt {j 9 -8 c} def
  73. /sjl {k 18 7 c} def
  74. /sh {j} def
  75. /sjc {j k} def
  76. /sdjl {k 9 9 18 9 a 9 5 18 5 a} def
  77. /dsjl {m 12 7 18 7 a} def
  78. /dbl {g 7 30 7 5 18 5 b} def
  79. /dtl {i 7 -8 7 9 18 9 b} def
  80. /djb {f g 0 5 18 5 a} def
  81. /djt {h i 0 9 18 9 a} def
  82. /djl {g i 7 -8 7 22 a} def
  83. /dh {l} def
  84. /djc {f g h i} def
  85. /dsjb {l 9 30 9 9 a} def
  86. /sdjb {j 7 7 7 30 a 12 7 12 30 a} def
  87. /dsjt {l 9 -8 9 5 a} def
  88. /sdjt {j 7 7 7 -8 a 12 7 12 -8 a} def
  89. /sdbl {7 30 7 7 18 7 b 12 30 12 7 a} def
  90. /dsbl {9 30 9 5 18 5 b 9 9 18 9 a} def
  91. /dstl {9 -8 9 9 18 9 b 9 5 18 5 a} def
  92. /sdtl {7 -8 7 7 18 7 b 12 -8 12 7 a} def
  93. /sdjc {m j} def
  94. /dsjc {l k} def
  95. /sbr {0 7 9 7 9 30 b} def
  96. /stl {9 -8 9 7 18 7 b} def
  97. /light {0.90 setgray n} def
  98. /med {0.60 setgray n} def
  99. /dark {0.30 setgray n} def
  100. /black {n} def
  101. /bt {0 7 18 7 18 22 d 0 22 e} def
  102. /bb {0 -8 18 -8 18 7 d 0 7 e} def
  103. /bl {0 -8 9 -8 9 22 d 0 22 e} def
  104. /br {9 -8 18 -8 18 22 d 9 22 e} def
  105. end %CharProcs
  106.  
  107. /BuildChar
  108.   { fs 1 and 0 eq {1} {3} ifelse setlinewidth
  109.     18 0 setcharwidth
  110.     exch begin
  111.      Encoding exch get
  112.      CharProcs exch get
  113.      exec
  114.     end
  115.   } def
  116. end %mslinedraw
  117. %%EndFont
  118.  
  119. %%BeginProcSet: msdict 1.0 0
  120. /msdict 100 dict def
  121. FontDirectory /LineDraw known not
  122.  {/LineDraw mslinedraw definefont pop} if
  123. msdict begin
  124. /SLL {/LL def} def
  125. /P {exch msu exch msu neg ptop add moveto} bind def
  126. /S {sw 0 32 4 -1 roll widthshow} bind def
  127. /C {1 string dup 0 4 -1 roll put S} bind def
  128. /J {msu ( ) stringwidth pop sub /sw exch def} bind def
  129. /PE {showpage ptop exch restore save exch /ptop exch def} bind def
  130. /SFL {msu /ptop exch def} bind def
  131. %%BeginModelCheck
  132.  statusdict begin
  133.  product (OmniLaser) eq
  134. {
  135. end
  136. /B1 {statusdict begin 0 setpapertray end} def
  137. /B2 {statusdict begin 1 setpapertray end} def
  138. }{
  139. end
  140. /B1 {statusdict begin 1 setpapertray end} def
  141. /B2 {statusdict begin 2 setpapertray end} def
  142. } ifelse
  143. %%EndModelCheck
  144. /MB {statusdict begin /manualfeed true store end} def
  145. /ME {statusdict begin /manualfeed false store end} def
  146. /B {fs 2 and 0 eq {Bft} {BIft} ifelse
  147.  ftsz scalefont setfont fs 1 or /fs exch def} bind def
  148. /E {Eft ftsz scalefont setfont /fs 0 def} bind def
  149. /I {fs 1 and 0 eq {Ift} {BIft} ifelse
  150.  ftsz scalefont setfont fs 2 or /fs exch def} bind def
  151. /BI {BIft ftsz scalefont setfont fs 
  152.  2 or 1 or /fs exch def} bind def
  153. /LU {currentpoint /uy exch def /ux exch def 1 ssm} bind def
  154. /LD {currentpoint /uy exch def /ux exch def 2 ssm} bind def
  155. /LS {currentpoint /uy exch def /ux exch def 4 ssm} bind def
  156. /LL {currentpoint /uy exch def /ux exch def /ldmode exch def 8 ssm} bind def
  157. /LE {smode 1 and 0 ne {false (_) ul} if
  158.       smode 2 and 0 ne {true (_) ul} if
  159.       smode 4 and 0 ne {false (\352) ul} if
  160.       smode 8 and 0 ne {ux uy ldot pop pop} if
  161.   not smode and /smode exch def} bind def
  162. /BD {STh ssc} def
  163. /BU {STh neg ssc} def
  164. /BN {0 ssy neg rmoveto} def
  165. /F {/ftsz exch def (-) stringwidth pop 2 div neg /STh exch def
  166.  /ftcd exch def 
  167.  0 2 fonttable length 1 sub
  168.    {dup fonttable exch get ftcd eq
  169.      {1 add fonttable exch get fontset exit}{pop}ifelse
  170.    }for
  171.  E} bind def
  172. /msfindfont {dup FontDirectory exch known not {pop /Courier} if findfont} def
  173. /fontset {dup 0 get msfindfont /Eft exch def
  174.           dup 1 get msfindfont /Bft exch def
  175.           dup 2 get msfindfont /Ift exch def
  176.           3 get msfindfont /BIft exch def
  177.          }def
  178. /msu {20 div} def
  179. /ssc {dup /ssy exch def 0 exch rmoveto} bind def
  180. /ssm {dup smode or /smode exch def} bind def
  181. /Cf {/Eft /Courier  findfont def /Bft /Courier-Bold findfont def /Ift /Courier-Oblique findfont def /BIft /Courier-BoldOblique findfont def} def
  182. /DUL {cc true charpath pathbbox newpath exch pop 2 index 2 index moveto cx1 4 -1 roll sub dup 0 rlineto 3 1 roll exch
  183. sub 0 exch rlineto neg 0 rlineto closepath fill} bind def
  184. /ul {gsave /cc exch def currentpoint pop /cx1 exch def ux uy moveto DUL {grestore gsave ux uy 2.4 sub moveto DUL} if
  185. grestore} bind def
  186. /PSe {restore end currentfile closefile} bind def
  187. /ldot {gsave 2 copy currentpoint /y exch def /x exch def
  188.  newpath
  189.  ldmode 0 eq {/offset 0 def 1 setlinewidth [1 7] 4 setdash}
  190.  {ldmode 1 eq {[6 2] 6 setdash /offset STh def .2 setlinewidth}
  191.  {ldmode 2 eq {[] 0 setdash /offset 1.4 def .2 setlinewidth} if}
  192.  ifelse} ifelse
  193.  offset sub moveto x y offset sub lineto stroke grestore} bind def
  194. /Ccs /Courier findfont /CharStrings get def
  195.  
  196. % /OrigName /NewName vector ReEncodeSmall
  197. /ReEncodeSmall { %def
  198.   exch findfont begin
  199.   currentdict dup length dict begin
  200.     { 1 index /FID ne {def} {pop pop} ifelse } forall
  201.     /FontName exch def
  202.     /Encoding foreignvec def
  203.   currentdict dup end end
  204.   /FontName get exch definefont pop
  205. } bind def
  206. /Foreign { ReEncodeSmall } def
  207.  
  208. /foreignvec StandardEncoding 256 array copy def
  209. % the following are differences from StandardEncoding.
  210. % Sequential entries do not require indices:
  211. 0 [ 39/quotesingle 96/grave
  212. 128/Ccedilla/udieresis/eacute/acircumflex/adieresis
  213. /agrave/aring/ccedilla/ecircumflex/edieresis
  214. /egrave/idieresis/icircumflex/igrave/Adieresis
  215. /Aring/Eacute/ae/AE/ocircumflex
  216. /odieresis/ograve/ucircumflex/ugrave/ydieresis
  217. /Odieresis/Udieresis/cent/sterling/yen/P/florin/aacute
  218. /iacute/oacute/uacute/ntilde/Ntilde/ordfeminine
  219. /ordmasculine/questiondown/.notdef/.notdef
  220. /.notdef/.notdef/exclamdown/guillemotleft/guillemotright
  221. /Aacute/Acircumflex/Agrave/Atilde/Ecircumflex/Edieresis
  222. /Egrave/Iacute/Icircumflex/Idieresis/Igrave/Oacute
  223. /Ocircumflex/Ograve/Otilde/Uacute/Ucircumflex/Ugrave
  224. /Scaron/Ydieresis/emdash/Zcaron/.notdef/otilde/scaron/zcaron
  225. /fraction/section/currency/quotesingle/quotedblleft
  226. /guilsinglleft/guilsinglright/.notdef/.notdef/endash/dagger/daggerdbl
  227. /paragraph/quotesinglbase/quotedblbase/quotedblright
  228. /ellipsis/.notdef/grave/acute/circumflex/tilde/macron
  229. /germandbls/breve/dotaccent/dieresis/cedilla/.notdef/hungarumlaut
  230. /ogonek/caron/emdash/Lslash/Oslash/dotlessi/lslash/oslash
  231. /.notdef/.notdef/.notdef/.notdef/.notdef/atilde
  232. /.notdef/.notdef/ring/bullet/periodcentered/.notdef/.notdef
  233. /.notdef/.notdef/.notdef
  234. ] { %forall
  235.   dup type /nametype eq { %ifelse
  236.     dup Ccs exch known not {pop /.notdef} if
  237.     foreignvec 2 index 2 index put
  238.     pop 1 add
  239.   }{ exch pop } ifelse
  240. } forall pop
  241.  
  242. %BeginMakeForeign
  243. /Courier /Courier-F Foreign
  244. /Courier-Bold /Courier-Bold-F Foreign
  245. /Courier-Oblique /Courier-Oblique-F Foreign
  246. /Courier-BoldOblique /Courier-BoldOblique-F Foreign
  247. /Helvetica /Helvetica-F Foreign
  248. /Helvetica-Bold /Helvetica-Bold-F Foreign
  249. /Helvetica-Oblique /Helvetica-Oblique-F Foreign
  250. /Helvetica-BoldOblique /Helvetica-BoldOblique-F Foreign
  251. /AvantGarde-Book /AvantGarde-Book-F Foreign
  252. /AvantGarde-Demi /AvantGarde-Demi-F Foreign
  253. /AvantGarde-BookOblique /AvantGarde-BookOblique-F Foreign
  254. /AvantGarde-DemiOblique /AvantGarde-DemiOblique-F Foreign
  255. FontDirectory /Helvetica-Condensed known
  256. {
  257. /Helvetica-Condensed /Helvetica-Narrow-F Foreign
  258. /Helvetica-Condensed-Bold /Helvetica-Narrow-Bold-F Foreign
  259. /Helvetica-Condensed-Oblique /Helvetica-Narrow-Oblique-F Foreign
  260. /Helvetica-Condensed-BoldObl /Helvetica-Narrow-BoldOblique-F Foreign
  261. }{
  262. /Helvetica-Narrow /Helvetica-Narrow-F Foreign
  263. /Helvetica-Narrow-Bold /Helvetica-Narrow-Bold-F Foreign
  264. /Helvetica-Narrow-Oblique /Helvetica-Narrow-Oblique-F Foreign
  265. /Helvetica-Narrow-BoldOblique /Helvetica-Narrow-BoldOblique-F Foreign
  266. } ifelse
  267. /Bookman-Light /Bookman-Light-F Foreign
  268. /Bookman-Demi /Bookman-Demi-F Foreign
  269. /Bookman-LightItalic /Bookman-LightItalic-F Foreign
  270. /Bookman-DemiItalic /Bookman-DemiItalic-F Foreign
  271. /Times-Roman /Times-Roman-F Foreign
  272. /Times-Bold /Times-Bold-F Foreign
  273. /Times-Italic /Times-Italic-F Foreign
  274. /Times-BoldItalic /Times-BoldItalic-F Foreign
  275. /NewCenturySchlbk-Roman /NewCenturySchlbk-Roman-F Foreign
  276. /NewCenturySchlbk-Bold /NewCenturySchlbk-Bold-F Foreign
  277. /NewCenturySchlbk-Italic /NewCenturySchlbk-Italic-F Foreign
  278. /NewCenturySchlbk-BoldItalic /NewCenturySchlbk-BoldItalic-F Foreign
  279. /Palatino-Roman /Palatino-Roman-F Foreign
  280. /Palatino-Bold /Palatino-Bold-F Foreign
  281. /Palatino-Italic /Palatino-Italic-F Foreign
  282. /Palatino-BoldItalic /Palatino-BoldItalic-F Foreign
  283. /ZapfChancery-MediumItalic /ZapfChancery-MediumItalic-F Foreign
  284. %EndMakeForeign
  285.  
  286. /fonttable
  287.  [0 [/Courier-F /Courier-Bold-F /Courier-Oblique-F /Courier-BoldOblique-F]
  288.  8 [/Helvetica-F /Helvetica-Bold-F /Helvetica-Oblique-F /Helvetica-BoldOblique-F]
  289.  9 [/AvantGarde-Book-F /AvantGarde-Demi-F /AvantGarde-BookOblique-F /AvantGarde-DemiOblique-F]
  290.  10 [/Helvetica-Narrow-F /Helvetica-Narrow-Bold-F /Helvetica-Narrow-Oblique-F /Helvetica-Narrow-BoldOblique-F]
  291.  16 [/Bookman-Light-F /Bookman-Demi-F /Bookman-LightItalic-F /Bookman-DemiItalic-F]
  292.  24 [/Times-Roman-F /Times-Bold-F /Times-Italic-F /Times-BoldItalic-F]
  293.  25 [/NewCenturySchlbk-Roman-F /NewCenturySchlbk-Bold-F /NewCenturySchlbk-Italic-F /NewCenturySchlbk-BoldItalic-F]
  294.  26 [/Palatino-Roman-F /Palatino-Bold-F /Palatino-Italic-F /Palatino-BoldItalic-F]
  295.  50 [/ZapfChancery-MediumItalic-F /ZapfChancery-MediumItalic-F /ZapfChancery-MediumItalic-F /ZapfChancery-MediumItalic-F]
  296.  56 [/Symbol /Symbol /Symbol /Symbol]
  297.  57 [/LineDraw /LineDraw /LineDraw /LineDraw]
  298.  60 [/ZapfDingbats /ZapfDingbats /ZapfDingbats 
  299. /ZapfDingbats] 
  300. ] def
  301.  
  302. %BeginGraphicsDefs
  303. /M {moveto}  def
  304. /L {lineto} def
  305. /LH {currentpoint exch pop lineto} def
  306. /LV {currentpoint pop exch lineto} def
  307. /R {3 index 1 index 1 index 5 index 5 index 1 index M L L L closepath pop pop} def
  308. /setpat {setscreen 100 div setgray} def
  309. /setgrayed {{dup mul exch dup mul add 1 exch sub} setpat} def
  310. /setbar {{pop} setpat} def
  311. /setcross {{2 copy gt {pop} {exch pop} ifelse} setpat} def
  312. /fi {1 -1 scale} def
  313. /II1 {save count /mscount exch def} def
  314. /II2 {userdict begin /showpage {} def /letter {} def
  315.   /legal {} def /a4 {} def /b5 {} def
  316.   /clear { {cleartomark count msdict /mscount get eq {exit} if} loop mark} def
  317.    mark} def
  318. /IT {pop restore} def
  319. /IX {exch msu exch msu neg ptop add translate} def
  320. /IS {div 3 1 roll div exch scale} def
  321.  
  322. save /msdictstate exch def
  323. %!PS-Adobe-2.0 
  324. PSp 15840 SFL 
  325. 7740 1968 P 8 18 F B (Thinkage) S 100 J ( Ltd.) S E 
  326. 6160 2448 P B (YAY Reference Manual) S E 
  327. 2880 8448 P 0 12 F 8 9 F (Last) S 50 J ( Revision: November 11, 1995) S 0 12 F 
  328. PE 
  329. PE 
  330. 7040 2448 P 8 18 F B (Table) S 100 J ( of Contents) S E 
  331. 2880 4468 P 0 12 F 8 12 F B (1.) S 67 J ( Introduction) S 0 LL 5398 J ( ) S LE (1) S E 
  332. 3168 5088 P 0 12 F 8 9 F B (1.1) S 50 J (  A Note to Novices) S 0 LL 4922 J ( ) S LE (1) S E 
  333. 2880 5748 P 0 12 F 8 12 F B (2.) S 67 J ( How YAY Works) S 0 LL 4933 J ( ) S LE (3) S E 
  334. 3168 6368 P 0 12 F 8 9 F B (2.1) S 50 J (  "yyparse" and "yylex") S 0 LL 4572 J ( ) S LE (3) S E 
  335. 3168 6748 P B (2.2) S 50 J (  Grammar Rules) S 0 LL 5122 J ( ) S LE (4) S E 
  336. 3168 7128 P B (2.3) S 50 J (  Notes on Compiling Source Code Produced by YAY) S 0 LL 2042 J ( ) S LE (4) S E 
  337. 2880 7788 P 0 12 F 8 12 F B (3) S 67 J ( Input to YAY) S 0 LL 5425 J ( ) S LE (6) S E 
  338. 3168 8408 P 0 12 F 8 9 F B (3.1) S 50 J (  The Declarations Section) S 0 LL 4312 J ( ) S LE (7) S E 
  339. 3456 8668 P 0 12 F 8 9 F (3.1.1) S 50 J (  Token Declarations) S 0 LL 4474 J ( ) S LE (7) S 
  340. 3456 8928 P (3.1.2) S 50 J (  Precedence and Binding) S 0 LL 4064 J ( ) S LE (8) S 
  341. 3456 9188 P (3.1.3) S 50 J (  Variable/Function Declarations) S 0 LL 3474 J ( ) S LE (10) S 
  342. 3456 9448 P (3.1.4) S 50 J (  Summary) S 0 LL 5154 J ( ) S LE (11) S 
  343. 3168 9828 P 0 12 F 8 9 F B (3.2) S 50 J (  Grammar Rules) S 0 LL 5022 J ( ) S LE (11) S E 
  344. 3456 10088 P 0 12 F 8 9 F (3.2.1) S 50 J (  Recognition Actions) S 0 LL 4334 J ( ) S LE (13) S 
  345. 3456 10348 P (3.2.2) S 50 J (  Token and Symbol Values) S 0 LL 3824 J ( ) S LE (13) S 
  346. 3456 10608 P (3.2.3) S 50 J (  Precedence in the Grammar Rules) S 0 LL 3154 J ( ) S LE (15) S 
  347. 3456 10868 P (3.2.4) S 50 J (  The Start Symbol) S 0 LL 4534 J ( ) S LE (16) S 
  348. 3456 11128 P (3.2.5) S 50 J (  The End Marker) S 0 LL 4634 J ( ) S LE (17) S 
  349. 3456 11388 P (3.2.6) S 50 J (  Declarations in yyparse) S 0 LL 4054 J ( ) S LE (17) S 
  350. 3168 11768 P 0 12 F 8 9 F B (3.3) S 50 J (  The Programs Section) S 0 LL 4452 J ( ) S LE (18) S E 
  351. 3456 12028 P 0 12 F 8 9 F (3.3.1) S 50 J (  The Lexical Analyzer) S 0 LL 4254 J ( ) S LE (18) S 
  352. 2880 12688 P 0 12 F 8 12 F B (4.) S 67 J ( Internal Structures) S 0 LL 4534 J ( ) S LE (20) S E 
  353. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  354. 2880 14800 P 0 12 F 24 10 F (Table) S 50 J ( of Contents) S 5709 J ( i) S 0 12 F 
  355. PE 
  356. 2448 1968 P 8 9 F B (4.1) S 50 J (  States) S 0 LL 5822 J ( ) S LE (20) S E 
  357. 2448 2348 P B (4.2) S 50 J (  Diagramming States) S 0 LL 4622 J ( ) S LE (21) S E 
  358. 2448 2728 P B (4.3) S 50 J (  State Actions) S 0 LL 5212 J ( ) S LE (22) S E 
  359. 2736 2988 P 0 12 F 8 9 F (4.3.1) S 50 J (  The Accept Action) S 0 LL 4464 J ( ) S LE (23) S 
  360. 2736 3248 P (4.3.2) S 50 J (  The Shift Action) S 0 LL 4654 J ( ) S LE (23) S 
  361. 2736 3508 P (4.3.3) S 50 J (  The Reduce Action) S 0 LL 4394 J ( ) S LE (24) S 
  362. 2736 3768 P (4.3.4) S 50 J (  The Goto Action) S 0 LL 4624 J ( ) S LE (25) S 
  363. 2736 4028 P (4.3.5) S 50 J (  The Error Action) S 0 LL 4614 J ( ) S LE (26) S 
  364. 2160 4688 P 0 12 F 8 12 F B (5.) S 67 J ( Error-Handling) S 0 LL 4973 J ( ) S LE (27) S E 
  365. 2448 5308 P 0 12 F 8 9 F B (5.1) S 50 J (  The "error" Symbol) S 0 LL 4702 J ( ) S LE (27) S E 
  366. 2448 5688 P B (5.2) S 50 J (  The Error Condition) S 0 LL 4662 J ( ) S LE (27) S E 
  367. 2448 6068 P B (5.3) S 50 J (  Examples) S 0 LL 5522 J ( ) S LE (28) S E 
  368. 2448 6448 P B (5.4) S 50 J (  Error Recognition Actions) S 0 LL 4122 J ( ) S LE (30) S E 
  369. 2448 6828 P B (5.5) S 50 J (  The yyclearin Macro) S 0 LL 4632 J ( ) S LE (30) S E 
  370. 2448 7208 P B (5.6) S 50 J (  The yyerror Function) S 0 LL 4562 J ( ) S LE (31) S E 
  371. 2736 7468 P 0 12 F 8 9 F (5.6.1) S 50 J (  Changing yychar in yyerror) S 0 LL 3774 J ( ) S LE (31) S 
  372. 2448 7848 P 0 12 F 8 9 F B (5.7) S 50 J (  The yyerrflag Variable) S 0 LL 4482 J ( ) S LE (32) S E 
  373. 2448 8228 P B (5.8) S 50 J (  The yyerrok Macro) S 0 LL 4762 J ( ) S LE (33) S E 
  374. 2448 8608 P B (5.9) S 50 J (  Other Error Support Routines) S 0 LL 3832 J ( ) S LE (33) S E 
  375. 2160 9268 P 0 12 F 8 12 F B (6.) S 67 J ( YAY Output) S 0 LL 5319 J ( ) S LE (35) S E 
  376. 2448 9888 P 0 12 F 8 9 F B (6.1) S 50 J (  Rules Summary) S 0 LL 5002 J ( ) S LE (36) S E 
  377. 2448 10268 P B (6.2) S 50 J (  State Descriptions) S 0 LL 4782 J ( ) S LE (36) S E 
  378. 2448 10648 P B (6.3) S 50 J (  Conflict Summary) S 0 LL 4822 J ( ) S LE (39) S E 
  379. 2448 11028 P B (6.4) S 50 J (  Parser Statistics) S 0 LL 4952 J ( ) S LE (39) S E 
  380. 2160 11688 P 0 12 F 8 12 F B (7.) S 67 J ( Types) S 0 LL 5974 J ( ) S LE (42) S E 
  381. 2448 12308 P 0 12 F 8 9 F B (The) S 50 J ( Default Action) S 0 LL 5122 J ( ) S LE (43) S E 
  382. 2160 12968 P 0 12 F 8 12 F B (8.) S 67 J ( Ambiguities) S 0 LL 5293 J ( ) S LE (45) S E 
  383. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  384. 2160 14800 P 0 12 F 24 10 F (ii) S 5653 J ( Table) S 50 J ( of Contents) S 0 12 F 
  385. PE 
  386. 3168 1968 P 8 9 F B (8.1) S 50 J (  Resolving Conflicts by Precedence) S 0 LL 3362 J ( ) S LE (46) S E 
  387. 3168 2348 P B (8.2) S 50 J (  Disambiguating Rules) S 0 LL 4472 J ( ) S LE (46) S E 
  388. 3168 2728 P B (8.3) S 50 J (  Conflicts in YAY Output) S 0 LL 4322 J ( ) S LE (48) S E 
  389. 2880 3388 P 0 12 F 8 12 F B (9.) S 67 J ( Advanced Features) S 0 LL 4455 J ( ) S LE (50) S E 
  390. 3168 4008 P 0 12 F 8 9 F B (9.1) S 50 J (  LALR\(2\) Grammars) S 0 LL 4712 J ( ) S LE (50) S E 
  391. 3456 4268 P 0 12 F 8 9 F (9.1.1) S 50 J (  The Lookahead Action) S 0 LL 4124 J ( ) S LE (50) S 
  392. 3456 4528 P (9.1.2) S 50 J (  The yy2lex Routine) S 0 LL 4384 J ( ) S LE (51) S 
  393. 3456 4788 P (9.1.3) S 50 J (  Conflicts) S 0 LL 5234 J ( ) S LE (52) S 
  394. 3168 5168 P 0 12 F 8 9 F B (9.2) S 50 J (  Multiple Actions) S 0 LL 4972 J ( ) S LE (52) S E 
  395. 3168 5548 P B (9.3) S 50 J (  Selection Preference) S 0 LL 4582 J ( ) S LE (54) S E 
  396. 3168 5928 P B (9.4) S 50 J (  Negative Numbers in $N Constructs) S 0 LL 3292 J ( ) S LE (58) S E 
  397. 3168 6308 P B (9.5) S 50 J (  Lists and Handling Null Strings) S 0 LL 3692 J ( ) S LE (59) S E 
  398. 3168 6688 P B (9.6) S 50 J (  Right vs. Left Recursion) S 0 LL 4292 J ( ) S LE (60) S E 
  399. 3168 7068 P B (9.7) S 50 J (  YYDEBUG) S 0 LL 5472 J ( ) S LE (62) S E 
  400. 3168 7448 P B (9.8) S 50 J (  Important Symbols) S 0 LL 4732 J ( ) S LE (63) S E 
  401. 3168 7828 P B (9.9) S 50 J (  How YYERROR May Be Used) S 0 LL 3872 J ( ) S LE (64) S E 
  402. 3168 8208 P B (9.10) S 50 J (  The Default Action) S 0 LL 4672 J ( ) S LE (66) S E 
  403. 3168 8588 P B (9.11) S 50 J (  Invalid Tokens) S 0 LL 5012 J ( ) S LE (67) S E 
  404. 3168 8968 P B (9.12) S 50 J (  Dynamic Stack Allocation) S 0 LL 4062 J ( ) S LE (67) S E 
  405. 3168 9348 P B (9.13) S 50 J (  Synchronizing the Lookahead) S 0 LL 3702 J ( ) S LE (68) S E 
  406. 3168 9728 P B (9.14) S 50 J (  YYSHIFT) S 0 LL 5502 J ( ) S LE (69) S E 
  407. 2880 10388 P 0 12 F 8 12 F B (An) S 67 J ( Example) S 0 LL 5561 J ( ) S LE (70) S E 
  408. 2880 11288 P B (YAY) S 67 J ( vs. YACC) S 0 LL 5295 J ( ) S LE (73) S E 
  409. 2880 12188 P B (The) S 67 J ( YAY Command Line) S 0 LL 4105 J ( ) S LE (74) S E 
  410. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  411. 2880 14800 P 0 12 F 24 10 F (Table) S 50 J ( of Contents) S 5597 J ( iii) S 0 12 F 
  412. PE 
  413. PE 
  414. 7580 2448 P 8 18 F B (1.) S 100 J ( Introduction) S E 
  415. 2880 4048 P 0 12 F 8 9 F (YAY) S 50 J ( is a tool for writing compilers and other programs that parse input according to strict) S 
  416. 2880 4288 P ("grammar" rules.  In the terminology of parsing theory, YAY can handle LALR\(2\)) S 
  417. 2880 4528 P (grammars with disambiguating rules.  This is a fairly broad class of grammars -- most of) S 
  418. 2880 4768 P (the computing languages in use today can be described using LALR\(2\) specifications.) S 
  419. 2880 5208 P (For a precise definition of this sort of grammar, see any standard text on parsing theory,) S 
  420. 2880 5448 P (e.g. ) S 0 12 F 8 9 F I (Principles) S 50 J ( of Compiler Design) S E 0 12 F 8 9 F () S 50 J ( by A.V.Aho and J.D.Ullman, Addison-Wesley, 1977, or) S 
  421. 2880 5688 P 0 12 F 8 9 F I (LR) S 50 J ( Parsing) S E 0 12 F 8 9 F () S 50 J ( by Aho and Johnson, in Computing Surveys.) S 
  422. 2880 6128 P (The appearance of YAY input is based on the input to YACC \(Yet Another Compiler-) S 
  423. 2880 6368 P (Compiler\), written by S.C.Johnson of Bell Telephone Laboratories, Murray Hill, N.J.  The) S 
  424. 2880 6608 P (LALR\(1\) version of YAY was written by K.W.Lalonde of the Software Development Group) S 
  425. 2880 6848 P (of the University of Waterloo.  Enhancements to allow YAY to handle LALR\(2\) grammars) S 
  426. 2880 7088 P (were made by P.J.Fraser, also of SDG.) S 
  427. 2880 7528 P (The parsing algorithm used by YAY is derived from the article "Methods for Computing) S 
  428. 2880 7768 P (LALR\(k\) Lookahead" by B.B.Kristensen and O.L.Madsen, ) S 0 12 F 8 9 F I (ACM) S 50 J ( Transactions on) S E 
  429. 2880 8008 P I (Programming Languages and Systems) S E 0 12 F 8 9 F (,) S 50 J ( Vol.3, No.1, January 1981, pp.60-82.  Those) S 
  430. 2880 8248 P (interested in reading this article should first have a good grasp of parsing theory principles.) S 
  431. 2880 9068 P 0 12 F 8 12 F B (1.1) S 67 J (  A Note to Novices) S E 
  432. 2880 9788 P 0 12 F 8 9 F (YAY) S 50 J ( can produce anything from a simple parser for a desk calculator program to a very) S 
  433. 2880 10028 P (complicated parser for a programming language.  Those who are using YAY for complex) S 
  434. 2880 10268 P (tasks have to know all the idiosyncrasies of the program, including a good deal about the) S 
  435. 2880 10508 P (internal workings of YAY.  On the other hand, the internal workings are mostly irrelevant to) S 
  436. 2880 10748 P (someone who is making an easy straightforward parser.) S 
  437. 2880 11188 P (For this reason, novices may want to skip some the sections of the manual which describe) S 
  438. 2880 11428 P (very technical aspects of YAY.  This is particularly true on first reading, when it is more) S 
  439. 2880 11668 P (important to get an overview of how YAY is used than to try to comprehend every little) S 
  440. 2880 11908 P (detail.  We therefore suggest that novices concentrate on the following sections, and only) S 
  441. 2880 12148 P (look at other sections if the requirements of your parser make it necessary.) S 
  442. 2880 12588 P (  --          All of Chapter 2) S 
  443. 2880 12828 P (  --          All of Chapter 3) S 
  444. 2880 13068 P (  --          All of Chapter 4) S 
  445. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  446. 2880 14800 P 0 12 F 24 10 F (1) S 4338 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  447. PE 
  448. 2160 1968 P 8 9 F () S 50 J (  --          Sections 6.0, 6.1, 6.2) S 
  449. 2160 2208 P (  --          all of Chapter 7) S 
  450. 2160 2448 P (  --          Sections 9.3, 9.5, 9.6) S 
  451. 2160 2888 P (Novices may be particularly interested in Appendix A which gives an example of YAY) S 
  452. 2160 3128 P (input for a simple parser.) S 
  453. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  454. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4338 J ( 2) S 0 12 F 
  455. PE 
  456. 6880 2448 P 8 18 F B (2.) S 100 J ( How YAY Works) S E 
  457. 2880 4048 P 0 12 F 8 9 F (The) S 50 J ( input to YAY describes the rules of a grammar.  YAY uses these rules to produce the) S 
  458. 2880 4288 P (source code for a program that will parse the grammar.  This source code can then be) S 
  459. 2880 4528 P (compiled to obtain a program that reads input, parses it according to the grammar, and) S 
  460. 2880 4768 P (takes action based on the result.) S 
  461. 2880 5208 P (The source code produced by YAY consists of a number of data tables that represent the) S 
  462. 2880 5448 P (grammar, plus a C function named ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (.) S 50 J (  By default, all the symbol names used) S 
  463. 2880 5688 P (by YAY begin with ) S 0 12 F 0 9 F ("yy") S 0 12 F 8 9 F (.) S 50 J (  This is an historical convention, dating back to YAY's) S 
  464. 2880 5928 P (predecessor YACC.  Users can avoid conflicts with YAY names by avoiding symbols that) S 
  465. 2880 6168 P (start with ) S 0 12 F 0 9 F ("yy") S 0 12 F 8 9 F (.) S 
  466. 2880 6608 P (Users) S 50 J ( who want to use a different prefix may indicate this with a line of the form) S 
  467. 3600 7028 P 0 12 F 0 9 F (%prefix) S 108 J ( PREFIX) S 
  468. 2880 7468 P 0 12 F 8 9 F (at) S 50 J ( the beginning of their YAY input.  For example,) S 
  469. 3600 7888 P 0 12 F 0 9 F (%prefix) S 108 J ( ww) S 
  470. 2880 8328 P 0 12 F 8 9 F (asks) S 50 J ( for a prefix of ) S 0 12 F 0 9 F ("ww") S 0 12 F 8 9 F () S 50 J ( instead of ) S 0 12 F 0 9 F ("yy") S 0 12 F 8 9 F (.) S 50 J (  The prefix chosen should be one or two) S 
  471. 2880 8568 P (characters long -- longer prefixes will lead to name conflicts on machines where external) S 
  472. 2880 8808 P (names are truncated to six characters during the loading process.  In addition, at least one) S 
  473. 2880 9048 P (of the characters in the prefix should be a lower case letter \(because YAY uses an all) S 
  474. 2880 9288 P (upper case version of the prefix for some special names, and this has to be different from) S 
  475. 2880 9528 P (the real prefix\).) S 
  476. 2880 9968 P (Different prefixes are useful when two YAY-produced parsers are to be merged into a) S 
  477. 2880 10208 P (single program.  For the sake of convenience, however, the ) S 0 12 F 0 9 F ("yy") S 0 12 F 8 9 F () S 50 J ( convention will be used) S 
  478. 2880 10448 P (in this manual.) S 
  479. 2880 11268 P 0 12 F 8 12 F B (2.1) S 67 J (  "yyparse" and "yylex") S E 
  480. 2880 11988 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( returns a value of 0 if the input it parses is valid according to the given) S 
  481. 2880 12228 P (grammar rules.  It returns a 1 if the input is invalid and error recovery is impossible.) S 
  482. 2880 12468 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( does not do its own lexical analysis.  In other words, it does not pull the input) S 
  483. 2880 12708 P (apart into tokens ready for parsing.  Instead, it calls a routine called ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( every time it) S 
  484. 2880 12948 P (wishes to obtain a token from the input.) S 
  485. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  486. 2880 14800 P 0 12 F 24 10 F (3) S 4338 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  487. PE 
  488. 2160 1968 P 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( returns a value indicating the ) S 0 12 F 8 9 F I (type) S E 0 12 F 8 9 F () S 50 J ( of token that has been obtained.  If the token) S 
  489. 2160 2208 P (has an actual ) S 0 12 F 8 9 F I (value) S E 0 12 F 8 9 F (,) S 50 J ( this value \(or some representation of the value, e.g. a pointer to a) S 
  490. 2160 2448 P (string containing the value\) is returned in an external variable named ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F (.) S 
  491. 2160 2888 P (It) S 50 J ( is up to the user to write a ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( routine that breaks the input into tokens and returns) S 
  492. 2160 3128 P (the tokens one by one to ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (.) S 50 J (  We will say more about the lexical analyzer in) S 
  493. 2160 3368 P (Section 3.3.) S 
  494. 2160 4188 P 0 12 F 8 12 F B (2.2) S 67 J (  Grammar Rules) S E 
  495. 2160 4908 P 0 12 F 8 9 F (The) S 50 J ( grammar rules given to YAY not only describe what inputs are valid according to the) S 
  496. 2160 5148 P (grammar but also specify what action should be taken when a given input is encountered.) S 
  497. 2160 5388 P (For example, if the parser recognizes a statement that assigns a value to a variable, the) S 
  498. 2160 5628 P (parser should either perform the assignment itself or take some action to ensure that the) S 
  499. 2160 5868 P (assignment will eventually take place.) S 
  500. 2160 6308 P (As an example, if the parser is part of an interactive desk calculator, it could carry out) S 
  501. 2160 6548 P (arithmetic calculations as soon as the instructions are recognized.  However, if the parser) S 
  502. 2160 6788 P (is acting as the first pass in a multi-pass compiler, it may simply encode the input in a way) S 
  503. 2160 7028 P (that will be used in a later code-generation pass.) S 
  504. 2160 7468 P (In summary, the user must provide a number of things when using YAY to produce a) S 
  505. 2160 7708 P (parser:) S 
  506. 2160 8148 P (\(1\)          grammar rules indicating what input is and isn't valid;) S 
  507. 2160 8588 P (\(2\)          a lexical analyzer \() S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (\)) S 50 J ( that breaks raw input into tokens for the parsing) S 
  508. 2880 8828 P (routine ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (;) S 
  509. 2160 9268 P (\(3\)) S 500 J ( any) S 50 J ( source code or functions that may be needed to perform appropriate actions) S 
  510. 2880 9508 P (once particular inputs are recognized;) S 
  511. 2160 9948 P (\(4\)          a mainline routine that performs any necessary initializations, calls ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (,) S 
  512. 2880 10188 P (then) S 50 J ( performs possible clean-up actions.  The simplest kind of mainline is just a) S 
  513. 2880 10428 P (function ) S 0 12 F 0 9 F ("main") S 0 12 F 8 9 F () S 50 J ( that calls ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (,) S 50 J ( then returns.) S 
  514. 2160 11248 P 0 12 F 8 12 F B (2.3) S 67 J (  Notes on Compiling Source Code Produced by YAY) S E 
  515. 2160 11968 P 0 12 F 8 9 F (By) S 50 J ( default, C source code produced by YAY contains the line) S 
  516. 2880 12388 P 0 12 F 0 9 F (#define) S 108 J ( YYSCTAB const) S 
  517. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  518. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4338 J ( 4) S 0 12 F 
  519. PE 
  520. 2880 1968 P 8 9 F (It) S 50 J ( then uses the ) S 0 12 F 0 9 F (YYSCTAB) S 0 12 F 8 9 F () S 50 J ( manifest to declare various data objects as ) S 0 12 F 0 9 F B (const) S E 0 12 F 8 9 F (.) S 50 J (  If you will) S 
  521. 2880 2208 P (be compiling the YAY output with an old C compiler that doesn't recognize the ) S 0 12 F 0 9 F B (const) S E 
  522. 2880 2448 P 0 12 F 8 9 F (qualifier,) S 50 J ( you should change the definition to read) S 
  523. 3600 2868 P 0 12 F 0 9 F (#define) S 108 J ( YYSCTAB) S 
  524. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  525. 2880 14800 P 0 12 F 24 10 F (5) S 4338 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  526. PE 
  527. 6900 2448 P 8 18 F B (3) S 100 J ( Input to YAY) S E 
  528. 2160 4048 P 0 12 F 8 9 F (This) S 50 J ( chapter describes the input to YAY when you are defining an LALR\(1\) grammar.) S 
  529. 2160 4288 P (Chapter 9 will talk about additional needs for LALR\(2\) grammars.) S 
  530. 2160 4728 P (The input to YAY is broken into three sections:) S 
  531. 2160 5168 P (  --          declarations) S 
  532. 2160 5408 P (  --          grammar rules) S 
  533. 2160 5648 P (  --          programs) S 
  534. 2160 6088 P (The contents of each section will be described shortly, but first we will give some overall) S 
  535. 2160 6328 P (rules for YAY input.) S 
  536. 2160 6768 P (Sections of YAY input are separated by the symbol ) S 0 12 F 0 9 F (%%) S 0 12 F 8 9 F (.) S 50 J (  The general lay-out of YAY input) S 
  537. 2160 7008 P (is therefore) S 
  538. 2880 7428 P 0 12 F 0 9 F (declarations) S 
  539. 2880 7648 P (%%) S 
  540. 2880 7868 P (grammar) S 108 J ( rules) S 
  541. 2880 8088 P (%%) S 
  542. 2880 8308 P (programs) S 
  543. 2160 8748 P 0 12 F 8 9 F (The) S 50 J ( declarations section may be omitted if no declarations are necessary.  This will mean) S 
  544. 2160 8988 P (that the input starts with the first ) S 0 12 F 0 9 F (%%) S 0 12 F 8 9 F (.) S 50 J (  The programs section may also be omitted, from the) S 
  545. 2160 9228 P (second ) S 0 12 F 0 9 F (%%) S 0 12 F 8 9 F () S 50 J ( on.  The simplest input for YAY is therefore) S 
  546. 2880 9648 P 0 12 F 0 9 F (%%) S 
  547. 2880 9868 P (grammar) S 108 J ( rules) S 
  548. 2160 10308 P 0 12 F 8 9 F (Blanks,) S 50 J ( tabs, and new-lines are used to separate items in YAY input.  These are called) S 
  549. 2160 10548 P 0 12 F 8 9 F I (white-space) S E 0 12 F 8 9 F () S 50 J ( characters.  Any place one white-space character is valid, any number of) S 
  550. 2160 10788 P (blanks, tabs, and/or new-lines may be used.  This means, for example, that the ) S 0 12 F 0 9 F (%%) S 0 12 F 8 9 F () S 50 J ( to) S 
  551. 2160 11028 P (separate sections does not have to be on a line all by itself.  However, giving it a line of its) S 
  552. 2160 11268 P (own makes the YAY input easier to read.) S 
  553. 2160 11708 P (Comments may appear anywhere a blank is valid.  As in C, comments begin with ) S 0 12 F 0 9 F (/*) S 0 12 F 8 9 F () S 50 J ( and) S 
  554. 2160 11948 P (end with ) S 0 12 F 0 9 F (*/) S 0 12 F 8 9 F (.) S 
  555. 2160 12388 P (Identifiers) S 50 J ( used in YAY input may be of arbitrary length, and may consist of all letters) S 
  556. 2160 12628 P (\(upper and lower case\), all digits, and the characters dot \() S 0 12 F 0 9 F (.) S 0 12 F 8 9 F (\)) S 50 J ( and underscore \() S 0 12 F 0 9 F (_) S 0 12 F 8 9 F (\).) S 50 J (  The first) S 
  557. 2160 12868 P (character of an identifier may not be a digit.  YAY distinguishes between upper and lower) S 
  558. 2160 13108 P (case letters, so ) S 0 12 F 0 9 F ("this") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("THIS") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("This") S 0 12 F 8 9 F () S 50 J ( are all different symbols.) S 
  559. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  560. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4338 J ( 6) S 0 12 F 
  561. PE 
  562. 2880 2168 P 8 9 F (Literals) S 50 J ( in YAY input consist of a single ASCII character enclosed in single quotes, e.g.) S 
  563. 2880 2408 P 0 12 F 0 9 F ('c') S 0 12 F 8 9 F (.) S 50 J (  The standard C escape sequences are recognized:) S 
  564. 3600 2828 P 0 12 F 0 9 F (\\b) S 108 J (   -- ) S 0 12 F 8 9 F (backspace) S 
  565. 3600 3048 P 0 12 F 0 9 F (\\n) S 108 J (   -- ) S 0 12 F 8 9 F (new-line) S 
  566. 3600 3268 P 0 12 F 0 9 F (\\r) S 108 J (   -- ) S 0 12 F 8 9 F (carriage) S 50 J ( return) S 
  567. 3600 3488 P 0 12 F 0 9 F (\\t) S 108 J (   -- ) S 0 12 F 8 9 F (tab) S 
  568. 3600 3708 P 0 12 F 0 9 F (\\') S 108 J (   -- ) S 0 12 F 8 9 F (single) S 50 J ( quote) S 
  569. 3600 3928 P 0 12 F 0 9 F (\\\\) S 108 J (   -- ) S 0 12 F 8 9 F (backslash) S 
  570. 3600 4148 P 0 12 F 0 9 F (\\xxx) S 108 J ( -- ) S 0 12 F 8 9 F (any) S 50 J ( ASCII character) S 
  571. 3600 4368 P 0 12 F 0 9 F () S 108 J (        ) S 0 12 F 8 9 F (\() S 0 12 F 0 9 F ("xxx") S 0 12 F 8 9 F () S 50 J ( is octal representation\)) S 
  572. 2880 4808 P (For technical reasons, the null character ) S 0 12 F 0 9 F ('\\000') S 0 12 F 8 9 F () S 50 J ( should never appear in YAY input.) S 
  573. 2880 5628 P 0 12 F 8 12 F B (3.1) S 67 J (  The Declarations Section) S E 
  574. 2880 6348 P 0 12 F 8 9 F (The) S 50 J ( declarations section describes many of the identifiers that will be used in the rest of) S 
  575. 2880 6588 P (the YAY input.  There are two types of declarations:) S 
  576. 2880 7028 P (\(a\)          Token declarations;) S 
  577. 2880 7468 P (\(b\)          Declarations of functions and variables used in the actions that the parser takes) S 
  578. 3600 7708 P (when a particular input is recognized.) S 
  579. 2880 8148 P (The declarations section can also specify rules for the precedence and binding of) S 
  580. 2880 8388 P (operators used in the grammar.  For example, the standard order of arithmetic operations) S 
  581. 2880 8628 P (would normally be set up in the declarations section.) S 
  582. 2880 9748 P 0 12 F 8 12 F I (3.1.1) S 67 J (  Token Declarations) S E 
  583. 2880 10468 P 0 12 F 8 9 F (All) S 50 J ( ASCII characters are automatically recognized as tokens.  For example, ) S 0 12 F 0 9 F ('a') S 0 12 F 8 9 F () S 50 J ( stands for) S 
  584. 2880 10708 P (a token that is the literal character ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F (.) S 
  585. 2880 11148 P (Other) S 50 J ( tokens are declared with statements of the form) S 
  586. 3600 11568 P 0 12 F 0 9 F (%token) S 108 J ( name1 name2 name3 ...) S 
  587. 2880 12008 P 0 12 F 8 9 F (This) S 50 J ( tells YAY that the given names will refer to tokens.  For example,) S 
  588. 3600 12428 P 0 12 F 0 9 F (%token) S 108 J ( INTNUM) S 
  589. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  590. 2880 14800 P 0 12 F 24 10 F (7) S 4338 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  591. PE 
  592. 2160 1968 P 8 9 F (indicates) S 50 J ( that the identifier ) S 0 12 F 0 9 F (INTNUM) S 0 12 F 8 9 F () S 50 J ( will refer to a particular type of token returned by the) S 
  593. 2160 2208 P (lexical analyzer ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (.) S 50 J (  If ) S 0 12 F 0 9 F (INTNUM) S 0 12 F 8 9 F () S 50 J ( stands for any integer number token, you might) S 
  594. 2160 2448 P (have the following code in ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (.) S 
  595. 2880 2868 P 0 12 F 0 9 F (c) S 108 J ( = getchar\(\);) S 
  596. 2880 3088 P (if \( \(c >= '0'\) && \(c <= '9'\) \) {) S 
  597. 2880 3308 P (    yylval = 0;) S 
  598. 2880 3528 P (    do {) S 
  599. 2880 3748 P (        yylval = \(yylval * 10\) + \(c - '0'\);) S 
  600. 2880 3968 P (        c = getchar\(\);) S 
  601. 2880 4188 P (    } while \(c >= '0' && c <= '9'\);) S 
  602. 2880 4408 P (    ungetc\(c, stdin\);) S 
  603. 2880 4628 P (    return\( INTNUM \);) S 
  604. 2880 4848 P (}) S 
  605. 2160 5288 P ("yylex") S 0 12 F 8 9 F () S 50 J ( returns ) S 0 12 F 0 9 F (INTNUM) S 0 12 F 8 9 F () S 50 J ( to indicate that a certain kind of token \(an integer number\) has) S 
  606. 2160 5528 P (been returned.  The actual value of this number is returned in ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F (.) S 50 J (  The grammar) S 
  607. 2160 5768 P (rules in the YAY input would dictate where an ) S 0 12 F 0 9 F (INTNUM) S 0 12 F 8 9 F () S 50 J ( token is valid.) S 
  608. 2160 6208 P (In the C source code produced by YAY, the identifiers named in a ) S 0 12 F 0 9 F (%token) S 0 12 F 8 9 F () S 50 J ( statement will) S 
  609. 2160 6448 P (appear as constants set up with ) S 0 12 F 0 9 F B (#define) S E 0 12 F 8 9 F (.) S 50 J (  The first named token has a #defined value of) S 
  610. 2160 6688 P 0 12 F 0 9 F (257) S 0 12 F 8 9 F (,) S 50 J ( the next is #defined as ) S 0 12 F 0 9 F (258) S 0 12 F 8 9 F (,) S 50 J ( and so on.  Token values start at ) S 0 12 F 0 9 F (257) S 0 12 F 8 9 F () S 50 J ( so they will not) S 
  611. 2160 6928 P (conflict with any of the ) S 0 12 F 0 9 F (256) S 0 12 F 8 9 F () S 50 J ( ASCII characters.) S 
  612. 2160 7368 P (Because token identifiers are set up as manifest constants, they must not conflict with) S 
  613. 2160 7608 P (reserved words or other identifiers that will be used by the parser.  For example,) S 
  614. 2880 8028 P 0 12 F 0 9 F (%token) S 108 J ( if yyparse ...) S 
  615. 2160 8468 P 0 12 F 8 9 F (will) S 50 J ( almost certainly lead to errors when you try to compile the source code output of YAY.) S 
  616. 2160 8708 P (By convention, this manual will always create token names in upper case, and we) S 
  617. 2160 8948 P (recommend that you follow the same practice.) S 
  618. 2160 10068 P 0 12 F 8 12 F I (3.1.2) S 67 J (  Precedence and Binding) S E 
  619. 2160 10788 P 0 12 F 8 9 F (Parsers) S 50 J ( that evaluate expressions usually have to establish the order in which various) S 
  620. 2160 11028 P (operations are carried out.  For example, parsers for arithmetic expressions usually carry) S 
  621. 2160 11268 P (out multiplications before additions.  Two factors affect order of operation: precedence and) S 
  622. 2160 11508 P (binding.) S 
  623. 2160 11948 P 0 12 F 8 9 F I (Precedence) S E 0 12 F 8 9 F () S 50 J ( dictates which of two ) S 0 12 F 8 9 F B (different) S E 0 12 F 8 9 F () S 50 J ( operations should be carried out first.  For) S 
  624. 2160 12188 P (example, in) S 
  625. 2880 12608 P 0 12 F 0 9 F (A) S 108 J ( + B * C) S 
  626. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  627. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4338 J ( 8) S 0 12 F 
  628. PE 
  629. 2880 1968 P 8 9 F (the) S 50 J ( standard arithmetic rules of precedence dictate that the multiplication should take) S 
  630. 2880 2208 P (place before the addition.  Operations that should be carried out first are said to have a) S 
  631. 2880 2448 P 0 12 F 8 9 F I (higher) S E 0 12 F 8 9 F () S 50 J ( precedence than operations that should be performed later.) S 
  632. 2880 2888 P (Different operators can sometimes have the same precedence.  In C, for example,) S 
  633. 2880 3128 P (addition and subtraction are similar enough to share the same precedence.) S 
  634. 2880 3568 P 0 12 F 8 9 F I (Binding) S E 0 12 F 8 9 F () S 50 J ( indicates which of two ) S 0 12 F 8 9 F B (similar) S E 0 12 F 8 9 F () S 50 J ( operations should be carried out first.  By "similar",) S 
  635. 2880 3808 P (we mean operations with the same precedence \(e.g. addition and subtraction in C\).  For) S 
  636. 2880 4048 P (example, C chooses to parse) S 
  637. 3600 4468 P 0 12 F 0 9 F (A) S 108 J ( - B - C) S 
  638. 2880 4908 P 0 12 F 8 9 F (as) S 
  639. 3600 5328 P 0 12 F 0 9 F (\(A) S 108 J ( - B\) - C) S 
  640. 2880 5768 P 0 12 F 8 9 F (while) S 50 J ( a language like APL would use) S 
  641. 3600 6188 P 0 12 F 0 9 F (A) S 108 J ( - \(B - C\)) S 
  642. 2880 6628 P 0 12 F 8 9 F (If) S 50 J ( we evaluate the first operation before the second \(as C does\), we say the operation is) S 
  643. 2880 6868 P 0 12 F 8 9 F I (left-associative) S E 0 12 F 8 9 F (.) S 50 J ( If we evaluate the second operation before the first \(as APL does\), we say) S 
  644. 2880 7108 P (the operation is ) S 0 12 F 8 9 F I (right-associative.) S E 
  645. 2880 7548 P 0 12 F 8 9 F (Occasionally,) S 50 J ( a compiler may have operations which are not associative.  For example,) S 
  646. 2880 7788 P (Fortran regards) S 
  647. 3600 8208 P 0 12 F 0 9 F (A) S 108 J ( .GT. B .GT. C) S 
  648. 2880 8648 P 0 12 F 8 9 F (as) S 50 J ( invalid.  In this case, we say the operation is ) S 0 12 F 8 9 F I (non-associative) S E 0 12 F 8 9 F (.) S 50 J (  The precedence and) S 
  649. 2880 8888 P (associativity of operator tokens may be declared in the declarations section using the) S 
  650. 2880 9128 P (keywords) S 
  651. 3600 9548 P 0 12 F 0 9 F (%left) S 
  652. 3600 9768 P (%right) S 
  653. 3600 9988 P (%nonassoc) S 
  654. 2880 10428 P 0 12 F 8 9 F (For) S 50 J ( example,) S 
  655. 3600 10848 P 0 12 F 0 9 F (%left) S 108 J ( '+' '-') S 
  656. 2880 11288 P 0 12 F 8 9 F (indicates) S 50 J ( that the ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F () S 50 J ( operations have the same precedence and are left-associative.) S 
  657. 2880 11728 P (Associativity declarations should be given in order of precedence.  Operations with lowest) S 
  658. 2880 11968 P (precedence are listed first, and those with highest precedence are listed last.  Operations) S 
  659. 2880 12208 P (with equal precedence are listed on the same line.  For example,) S 
  660. 3600 12628 P 0 12 F 0 9 F (%right) S 108 J ( '=') S 
  661. 3600 12848 P (%left  '+' '-') S 
  662. 3600 13068 P (%left  '*' '/' '%') S 
  663. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  664. 2880 14800 P 0 12 F 24 10 F (9) S 4338 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  665. PE 
  666. 2160 2168 P 8 9 F (says) S 50 J ( that ) S 0 12 F 0 9 F (=) S 0 12 F 8 9 F () S 50 J ( has a lower precedence than ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F (,) S 50 J ( which in turn have a lower precedence) S 
  667. 2160 2408 P (than ) S 0 12 F 0 9 F (*) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (/) S 0 12 F 8 9 F (,) S 50 J ( and ) S 0 12 F 0 9 F (%) S 0 12 F 8 9 F (.) S 50 J (  ) S 0 12 F 0 9 F (=) S 0 12 F 8 9 F () S 50 J ( is also right-associative, so that) S 
  668. 2880 2828 P 0 12 F 0 9 F (A) S 108 J ( = B = C) S 
  669. 2160 3268 P 0 12 F 8 9 F (is) S 50 J ( parsed as) S 
  670. 2880 3688 P 0 12 F 0 9 F (A) S 108 J ( = \(B = C\)) S 
  671. 2160 4128 P 0 12 F 8 9 F (Because) S 50 J ( of the way YAY specifies precedence and associativity, operators with equal) S 
  672. 2160 4368 P (precedence will always have the same associativity.  For example, if A and B have equal) S 
  673. 2160 4608 P (precedence, their precedence must have been set with one of) S 
  674. 2880 5028 P 0 12 F 0 9 F (%left) S 108 J ( A B) S 
  675. 2880 5248 P (%right A B) S 
  676. 2880 5468 P (%nonassoc A B) S 
  677. 2160 5908 P 0 12 F 8 9 F (which) S 50 J ( means A and B must have the same associativity.) S 
  678. 2160 6348 P (The names supplied with ) S 0 12 F 0 9 F (%right) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (%left) S 0 12 F 8 9 F (,) S 50 J ( and ) S 0 12 F 0 9 F (%nonassoc) S 0 12 F 8 9 F () S 50 J ( may be literals or YAY) S 
  679. 2160 6588 P (identifiers.  If they are identifiers, they are regarded as token names.  YAY generates a) S 
  680. 2160 6828 P 0 12 F 0 9 F (%token) S 0 12 F 8 9 F () S 50 J ( directive for such names if they have not already been declared.  For example, in) S 
  681. 2880 7248 P 0 12 F 0 9 F (%left) S 108 J ( '+' '-') S 
  682. 2880 7468 P (%left '*' '/') S 
  683. 2880 7688 P (%left UMINUS) S 
  684. 2160 8128 P (UMINUS) S 0 12 F 8 9 F () S 50 J ( is taken to be a token identifier.  There is no need to define ) S 0 12 F 0 9 F (UMINUS) S 0 12 F 8 9 F () S 50 J ( as a token) S 
  685. 2160 8368 P (identifier -- a ) S 0 12 F 0 9 F (%token) S 0 12 F 8 9 F () S 50 J ( directive will be generated automatically if necessary. It is perfectly) S 
  686. 2160 8608 P (valid to have an explicit) S 
  687. 2880 9028 P 0 12 F 0 9 F (%token) S 108 J ( UMINUS) S 
  688. 2160 9468 P 0 12 F 8 9 F (if) S 50 J ( you want.  However, it must precede the ) S 0 12 F 0 9 F (%left) S 0 12 F 8 9 F () S 50 J ( declaration.) S 
  689. 2160 9908 P (For a more technical discussion of how precedence and binding rules affect a parser, see) S 
  690. 2160 10148 P (Chapter 8.) S 
  691. 2160 11268 P 0 12 F 8 12 F I (3.1.3) S 67 J (  Variable/Function Declarations) S E 
  692. 2160 11988 P 0 12 F 8 9 F (The) S 50 J ( declarations section may contain standard C declarations for variables and/or) S 
  693. 2160 12228 P (functions used in the actions specified in the grammar rules section.  All such declarations) S 
  694. 2160 12468 P (should be included in a block that begins with ) S 0 12 F 0 9 F (%{) S 0 12 F 8 9 F () S 50 J ( and ends with ) S 0 12 F 0 9 F (%}) S 0 12 F 8 9 F (.) S 50 J (  For example,) S 
  695. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  696. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 10) S 0 12 F 
  697. PE 
  698. 3600 1948 P 0 9 F (%{) S 
  699. 3600 2168 P () S 108 J (    int i, j, k;) S 
  700. 3600 2388 P (    static float x = 1.0;) S 
  701. 3600 2608 P (%}) S 
  702. 2880 3048 P 0 12 F 8 9 F (gives) S 50 J ( a few variable declarations.  These declarations are essentially transferred "as is" to) S 
  703. 2880 3288 P (the ) S 0 12 F 8 9 F I (beginning) S E 0 12 F 8 9 F () S 50 J ( of the source code that is produced by YAY.  This means that they will be) S 
  704. 2880 3528 P 0 12 F 8 9 F I (external) S E 0 12 F 8 9 F () S 50 J ( to ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( and therefore ) S 0 12 F 0 9 F B (extern) S E 0 12 F 8 9 F () S 50 J ( definitions.) S 
  705. 2880 4648 P 0 12 F 8 12 F I (3.1.4) S 67 J (  Summary) S E 
  706. 2880 5368 P 0 12 F 8 9 F (The) S 50 J ( source code produced by YAY contains the following.) S 
  707. 2880 5808 P (  --          code from the declarations section) S 
  708. 2880 6048 P (  --          code given in the programs section) S 
  709. 2880 6288 P (  --          parsing tables produced by YAY to represent the grammar) S 
  710. 2880 6528 P (  --          the ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( routine) S 
  711. 2880 7348 P 0 12 F 8 12 F B (3.2) S 67 J (  Grammar Rules) S E 
  712. 2880 8068 P 0 12 F 8 9 F (A) S 50 J ( YAY grammar rule has the general form) S 
  713. 3600 8488 P 0 12 F 0 9 F (identifier) S 108 J ( : definition ;) S 
  714. 2880 8928 P 0 12 F 8 9 F (A) S 50 J ( colon separates the definition from the identifier being defined.  A semicolon marks the) S 
  715. 2880 9168 P (end of the definition.) S 
  716. 2880 9608 P (The identifiers defined in the grammar rule section are known as ) S 0 12 F 8 9 F I (non-terminal) S 50 J ( symbols) S E 0 12 F 8 9 F (.) S 
  717. 2880 9848 P ("Non-terminal") S 50 J ( suggests that these symbols aren't the "end of the line".  Instead, they are) S 
  718. 2880 10088 P (made up of smaller things: tokens or other non-terminal symbols.) S 
  719. 2880 10528 P (Here is a simple example of the definition of a non-terminal symbol.) S 
  720. 3600 10948 P 0 12 F 0 9 F (paren_expr) S 108 J ( : '\(' expr '\)' ;) S 
  721. 2880 11388 P 0 12 F 8 9 F (This) S 50 J ( says that a ) S 0 12 F 0 9 F ("paren_expr") S 0 12 F 8 9 F () S 50 J ( consists of a left parenthesis, followed by an ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (,) S 
  722. 2880 11628 P (followed) S 50 J ( by a right parenthesis.  The ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( is either a token or a non-terminal symbol) S 
  723. 2880 11868 P (defined in another grammar rule.  This grammar rule could be interpreted to say that a) S 
  724. 2880 12108 P (parenthesized expression consists of a normal expression inside parentheses.) S 
  725. 2880 12548 P (A non-terminal symbol may have more than one definition.  For example, we might define) S 
  726. 2880 12788 P 0 12 F 0 9 F ("if") S 0 12 F 8 9 F () S 50 J ( statements with) S 
  727. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  728. 2880 14800 P 0 12 F 24 10 F (11) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  729. PE 
  730. 2880 1948 P 0 9 F (if_stat) S 108 J ( : IF '\(' expr '\)' stat ;) S 
  731. 2880 2168 P (if_stat : IF '\(' expr '\)' stat ELSE stat ;) S 
  732. 2160 2608 P 0 12 F 8 9 F (This) S 50 J ( definition assumes that ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F () S 50 J ( are tokens recognized by the lexical analyzer) S 
  733. 2160 2848 P (\(which means that this parser's ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( can recognize keywords\).  The definition also) S 
  734. 2160 3088 P (assumes that ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("stat") S 0 12 F 8 9 F () S 50 J ( are non-terminal symbols defined elsewhere.) S 
  735. 2160 3528 P (When a single symbol has more than one meaning, YAY lets you join the various) S 
  736. 2160 3768 P (possibilities into a single definition.  Different meanings are separated by or-bars \() S 0 12 F 0 9 F (|) S 0 12 F 8 9 F (\).) S 
  737. 2160 4008 P (Thus) S 50 J ( you could write) S 
  738. 2880 4428 P 0 12 F 0 9 F (if_stat) S 108 J ( : IF '\(' expr '\)' stat) S 
  739. 2880 4648 P (        | IF '\(' expr '\)' stat ELSE stat ;) S 
  740. 2160 5088 P 0 12 F 8 9 F (This) S 50 J ( technique is highly recommended, since it makes YAY input more readable.) S 
  741. 2160 5528 P (Definitions in a grammar may be recursive.  For example,) S 
  742. 2880 5948 P 0 12 F 0 9 F (list) S 108 J ( : item) S 
  743. 2880 6168 P (     | list ',' item;) S 
  744. 2160 6608 P 0 12 F 8 9 F (defines) S 50 J ( ) S 0 12 F 0 9 F ("list") S 0 12 F 8 9 F () S 50 J ( to be one or more items separated by commas.) S 
  745. 2880 7028 P 0 12 F 0 9 F (intexp) S 108 J ( : '\(' intexp '\)') S 
  746. 2880 7248 P (       | intexp '+' intexp) S 
  747. 2880 7468 P (       | intexp '-' intexp) S 
  748. 2880 7688 P (       | intexp '*' intexp) S 
  749. 2880 7908 P (       | intexp '/' intexp) S 
  750. 2880 8128 P (       | INTNUM ;) S 
  751. 2160 8568 P 0 12 F 8 9 F (says) S 50 J ( that an integer expression can be another integer expression in parentheses, the) S 
  752. 2160 8808 P (sum of integer expressions, the difference of integer expressions, the product of integer) S 
  753. 2160 9048 P (expressions, the quotient of integer expressions, or an integer number standing on its own) S 
  754. 2160 9288 P (\(where ) S 0 12 F 0 9 F (INTNUM) S 0 12 F 8 9 F () S 50 J ( is a token recognized by the lexical analyzer\).) S 
  755. 2160 9728 P (In recursive symbol definitions, it is often useful to have the empty string as one of the) S 
  756. 2160 9968 P (possible definitions.  For example,) S 
  757. 2880 10388 P 0 12 F 0 9 F (program) S 108 J ( :) S 
  758. 2880 10608 P (      /* the empty string */) S 
  759. 2880 10828 P (      | statement ';' program ;) S 
  760. 2160 11268 P 0 12 F 8 9 F (defines) S 50 J ( a program as zero or more statements separated by semicolons.) S 
  761. 2160 11708 P (Our definition of ) S 0 12 F 0 9 F ("list") S 0 12 F 8 9 F () S 50 J ( above was an example of ) S 0 12 F 8 9 F I (left) S 50 J ( recursion) S E 0 12 F 8 9 F () S 50 J ( because ) S 0 12 F 0 9 F ("list") S 0 12 F 8 9 F () S 50 J ( was on) S 
  762. 2160 11948 P (the left in the recursive definition.  The definition of ) S 0 12 F 0 9 F ("program") S 0 12 F 8 9 F () S 50 J ( was an example of ) S 0 12 F 8 9 F I (right) S E 
  763. 2160 12188 P I (recursion) S E 0 12 F 8 9 F (.) S 50 J (  In Section 9.6, we discuss the pros and cons of the two types of recursion.) S 
  764. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  765. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 12) S 0 12 F 
  766. PE 
  767. 2880 2308 P 8 12 F I (3.2.1) S 67 J (  Recognition Actions) S E 
  768. 2880 3028 P 0 12 F 8 9 F (In) S 50 J ( addition to defining what a non-terminal symbol is, a grammar rule usually describes) S 
  769. 2880 3268 P (what to do if the non-terminal symbol is encountered in parser input.  We call this a) S 
  770. 2880 3508 P 0 12 F 8 9 F I (recognition) S 50 J ( action.) S E 
  771. 2880 3948 P 0 12 F 8 9 F (Recognition) S 50 J ( actions are specified as part of the grammar rule.  They are enclosed in brace) S 
  772. 2880 4188 P (brackets in the definition, as in) S 
  773. 3600 4608 P 0 12 F 0 9 F (break_stat) S 108 J ( : BREAK ';') S 
  774. 3600 4828 P (    { breakfn\(\); };) S 
  775. 2880 5268 P 0 12 F 8 9 F (In) S 50 J ( this definition, ) S 0 12 F 0 9 F ("break_stat") S 0 12 F 8 9 F () S 50 J ( is a non-terminal symbol made up of the token known as) S 
  776. 2880 5508 P 0 12 F 0 9 F (BREAK) S 0 12 F 8 9 F (,) S 50 J ( followed by a semicolon.  If this symbol is recognized, the parser will invoke a) S 
  777. 2880 5748 P (function named ) S 0 12 F 0 9 F ("breakfn") S 0 12 F 8 9 F (.) S 50 J (  Presumably this is a user-defined function that handles a) S 
  778. 2880 5988 P 0 12 F 0 9 F ("break;") S 0 12 F 8 9 F () S 50 J ( statement.) S 
  779. 2880 6428 P (Note that a semicolon is needed to mark the end of the definition even though the) S 
  780. 2880 6668 P (recognition action ends in a brace bracket.  Programmers who are used to the way C) S 
  781. 2880 6908 P (works should bear this in mind.) S 
  782. 2880 7348 P (For compatibility with some versions of YACC, YAY lets you put an equals sign \() S 0 12 F 0 9 F (=) S 0 12 F 8 9 F (\)) S 50 J ( before) S 
  783. 2880 7588 P (the opening brace that begins a recognition action, as in) S 
  784. 3600 8008 P 0 12 F 0 9 F (break_stat) S 108 J ( : BREAK ';') S 
  785. 3600 8228 P (    = { breakfn\(\); };) S 
  786. 2880 8668 P 0 12 F 8 9 F (When) S 50 J ( a symbol has more than one definition, a different recognition action may be) S 
  787. 2880 8908 P (associated with each definition.  We will show some examples of this in a moment.) S 
  788. 2880 10028 P 0 12 F 8 12 F I (3.2.2) S 67 J (  Token and Symbol Values) S E 
  789. 2880 10748 P 0 12 F 8 9 F (One) S 50 J ( of the most common recognition actions is to return a value.  For example, if an input) S 
  790. 2880 10988 P (is recognized as an expression to be evaluated, the parser may want to return the) S 
  791. 2880 11228 P (resulting value of the expression.  To return a value, the recognition action merely assigns) S 
  792. 2880 11468 P (the value to a special variable named ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F (.) S 50 J (  For example,) S 
  793. 3600 11888 P 0 12 F 0 9 F (hexdigit) S 108 J ( : '0' { $$ = 0; }) S 
  794. 3600 12108 P (         | '1' { $$ = 1; }) S 
  795. 3600 12328 P (                 ...) S 
  796. 3600 12548 P (         | 'A' { $$ = 10; }) S 
  797. 3600 12768 P (         | 'B' { $$ = 11; }) S 
  798. 3600 12988 P (         | 'C' { $$ = 12; }) S 
  799. 3600 13208 P (         | 'D' { $$ = 13; }) S 
  800. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  801. 2880 14800 P 0 12 F 24 10 F (13) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  802. PE 
  803. 2880 1948 P 0 9 F () S 108 J (         | 'E' { $$ = 14; }) S 
  804. 2880 2168 P (         | 'F' { $$ = 15; } ;) S 
  805. 2160 2608 P 0 12 F 8 9 F (could) S 50 J ( be a way to convert hexadecimal digits into numeric values.  In this case, ) S 0 12 F 0 9 F ("yylex") S 
  806. 2160 2848 P 0 12 F 8 9 F (just) S 50 J ( returns the digits it finds and ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( performs the actual conversion.) S 
  807. 2160 3288 P (Another common recognition action is to return a value based on one or more of the items) S 
  808. 2160 3528 P (that make up the non-terminal symbol.  Inside the recognition action, ) S 0 12 F 0 9 F ($1) S 0 12 F 8 9 F () S 50 J ( stands for the) S 
  809. 2160 3768 P (value of the first item in the symbol, ) S 0 12 F 0 9 F ($2) S 0 12 F 8 9 F () S 50 J ( stands for the value of the second item, and so on.) S 
  810. 2160 4008 P (If the item is a token, its value is the ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F () S 50 J ( value returned by ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( when the) S 
  811. 2160 4248 P (token was read.  If the item is non-terminal symbol, its value is the ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( value set by the) S 
  812. 2160 4488 P (recognition action associated with the symbol.  Thus we might write) S 
  813. 2880 4908 P 0 12 F 0 9 F (intexp) S 108 J ( : '\(' intexp '\)') S 
  814. 2880 5128 P (              {) S 
  815. 2880 5348 P (                  $$ = $2;) S 
  816. 2880 5568 P (              }) S 
  817. 2880 5788 P (          /* value of parenthesized expression) S 
  818. 2880 6008 P (             is expression inside parentheses */) S 
  819. 2880 6228 P (       | intexp '+' intexp) S 
  820. 2880 6448 P (              {) S 
  821. 2880 6668 P (                  $$ = $1 + $3 ;) S 
  822. 2880 6888 P (              }) S 
  823. 2880 7108 P (         /* value of addition is sum of two) S 
  824. 2880 7328 P (            expressions */) S 
  825. 2880 7548 P (       | intexp '-' intexp) S 
  826. 2880 7768 P (              {) S 
  827. 2880 7988 P (                  $$ = $1 - $3 ;) S 
  828. 2880 8208 P (              }) S 
  829. 2880 8428 P (         /* value of subtraction is difference) S 
  830. 2880 8648 P (            of two expressions */) S 
  831. 2880 8868 P (       |  /* and so on */) S 
  832. 2880 9088 P (       ;) S 
  833. 2160 9528 P 0 12 F 8 9 F (Note) S 50 J ( that this particular definition shows that each part of a multiple definition may have a) S 
  834. 2160 9768 P (different recognition action.) S 
  835. 2160 10208 P (In the source code for ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (,) S 50 J ( this set of actions will be turned into a large ) S 0 12 F 0 9 F B (switch) S E 
  836. 2160 10448 P 0 12 F 8 9 F (statement.) S 50 J (  The cases of the ) S 0 12 F 0 9 F B (switch) S E 0 12 F 8 9 F () S 50 J ( will be the various possible recognition actions.) S 
  837. 2160 10888 P (If no recognition action is specified for a definition, the default is) S 
  838. 2880 11308 P 0 12 F 0 9 F ({) S 108 J ( $$ = $1 ; }) S 
  839. 2160 11748 P 0 12 F 8 9 F (This) S 50 J ( action just returns the value of the first item \(if the item has a value\).) S 
  840. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  841. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 14) S 0 12 F 
  842. PE 
  843. 2880 2308 P 8 12 F I (3.2.3) S 67 J (  Precedence in the Grammar Rules) S E 
  844. 2880 3028 P 0 12 F 8 9 F (In) S 50 J ( our discussion of the declarations section, we showed how precedence could be) S 
  845. 2880 3268 P (assigned to ) S 0 12 F 8 9 F I (operators) S E 0 12 F 8 9 F (.) S 50 J ( Precedence can also be assigned to ) S 0 12 F 8 9 F I (grammar) S 50 J ( rules,) S E 0 12 F 8 9 F () S 50 J ( and this is) S 
  846. 2880 3508 P (done in the grammar input section.) S 
  847. 2880 3948 P (One way to give a grammar rule a precedence uses the ) S 0 12 F 0 9 F (%prec) S 0 12 F 8 9 F () S 50 J ( construct.) S 
  848. 3600 4368 P 0 12 F 0 9 F (%prec) S 108 J ( TOKEN) S 
  849. 2880 4808 P 0 12 F 8 9 F (in) S 50 J ( a grammar rule indicates that the rule should have the same precedence as the) S 
  850. 2880 5048 P (specified token.) S 
  851. 2880 5488 P (As a simple example, consider the case of the unary minus operator.  Suppose our) S 
  852. 2880 5728 P (declaration section contains) S 
  853. 3600 6148 P 0 12 F 0 9 F (%left) S 108 J ( '+' '-') S 
  854. 3600 6368 P (%left '*' '/') S 
  855. 3600 6588 P (%left UMINUS) S 
  856. 2880 7028 P 0 12 F 8 9 F (In) S 50 J ( the grammar rules section, we can write) S 
  857. 3600 7448 P 0 12 F 0 9 F (exp) S 108 J ( : exp '+' exp) S 
  858. 3600 7668 P (    | exp '-' exp) S 
  859. 3600 7888 P (    | exp '*' exp) S 
  860. 3600 8108 P (    | exp '/' exp) S 
  861. 3600 8328 P (    | '-' exp %prec UMINUS) S 
  862. 3600 8548 P (    | /* and so on */) S 
  863. 3600 8768 P (    ;) S 
  864. 2880 9208 P 0 12 F 8 9 F (We) S 50 J ( could not directly set up a precedence for the unary minus, since we had already set) S 
  865. 2880 9448 P (up a precedence for the ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F () S 50 J ( token.  Instead, we created a token named UMINUS and gave it) S 
  866. 2880 9688 P (the precedence we wanted to assign the unary minus.  When we wrote out the grammar) S 
  867. 2880 9928 P (rule for the unary minus, we added) S 
  868. 3600 10348 P 0 12 F 0 9 F (%prec) S 108 J ( UMINUS) S 
  869. 2880 10788 P 0 12 F 8 9 F (to) S 50 J ( show that this rule should have the precedence of ) S 0 12 F 0 9 F (UMINUS) S 0 12 F 8 9 F (.) S 
  870. 2880 11228 P (As) S 50 J ( another example, we might set up precedence rules for the right shift and left shift) S 
  871. 2880 11468 P (operations of C with) S 
  872. 3600 11888 P 0 12 F 0 9 F (%left) S 108 J ( RS LS) S 
  873. 3600 12108 P (    ...) S 
  874. 3600 12328 P (exp :) S 
  875. 3600 12548 P (    | exp '<' '<' exp %prec LS) S 
  876. 3600 12768 P (    | exp '>' '>' exp %prec RS) S 
  877. 3600 12988 P (    ...) S 
  878. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  879. 2880 14800 P 0 12 F 24 10 F (15) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  880. PE 
  881. 2160 1968 P 8 9 F (In) S 50 J ( this way we give the shift operations the proper precedence and avoid confusing them) S 
  882. 2160 2208 P (with the comparison operations ) S 0 12 F 0 9 F (>) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (<) S 0 12 F 8 9 F (.) S 50 J (  Of course, another way to resolve this problem) S 
  883. 2160 2448 P (is to make the lexical analyzer clever enough to recognize ) S 0 12 F 0 9 F (>>) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (<<) S 0 12 F 8 9 F () S 50 J ( and to return the RS) S 
  884. 2160 2688 P (or LS tokens directly.) S 
  885. 2160 3128 P (Although symbols like ) S 0 12 F 0 9 F (UMINUS) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (LS) S 0 12 F 8 9 F (,) S 50 J ( and ) S 0 12 F 0 9 F (RS) S 0 12 F 8 9 F () S 50 J ( are treated as tokens, they do not have to) S 
  886. 2160 3368 P (correspond to actual input.  They may just be placeholders for operator tokens that have) S 
  887. 2160 3608 P (two different meanings.) S 
  888. 2160 4048 P (We should note that the use of ) S 0 12 F 0 9 F (%prec) S 0 12 F 8 9 F () S 50 J ( is relatively rare in YAY.  People don't usually think) S 
  889. 2160 4288 P (of ) S 0 12 F 0 9 F (%prec) S 0 12 F 8 9 F () S 50 J ( in their first draft of a grammar.  ) S 0 12 F 0 9 F (%prec) S 0 12 F 8 9 F () S 50 J ( is only added in later drafts, when it is) S 
  890. 2160 4528 P (needed to resolve conflicts that appear when the rules are run through YAY.) S 
  891. 2160 4968 P (If a grammar rule is not assigned a precedence using ) S 0 12 F 0 9 F (%prec) S 0 12 F 8 9 F (,) S 50 J ( the precedence of the rule is) S 
  892. 2160 5208 P (taken from the last ) S 0 12 F 8 9 F I (token) S E 0 12 F 8 9 F () S 50 J ( in the rule.  For example, if the rule is) S 
  893. 2880 5628 P 0 12 F 0 9 F (expr) S 108 J ( : expr '+' expr) S 
  894. 2160 6068 P 0 12 F 8 9 F (the) S 50 J ( last token in the rule is ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( \(since ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( is a non-terminal symbol, not a token\).  Thus) S 
  895. 2160 6308 P (the precedence of the rule is the same as the precedence of ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F (.) S 
  896. 2160 6748 P (If) S 50 J ( the last token in a rule has no assigned precedence, the rule will not have a precedence.) S 
  897. 2160 6988 P (This can result in some surprises if you aren't careful.  For example, if you define) S 
  898. 2880 7408 P 0 12 F 0 9 F (expr) S 108 J ( : expr '+' expr ';') S 
  899. 2160 7848 P 0 12 F 8 9 F (the) S 50 J ( last token in the rule is ) S 0 12 F 0 9 F (;) S 0 12 F 8 9 F () S 50 J ( so the rule probably won't have a precedence even if ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( does.) S 
  900. 2160 8288 P (A rule that contains no tokens cannot have a precedence.) S 
  901. 2160 9408 P 0 12 F 8 12 F I (3.2.4) S 67 J (  The Start Symbol) S E 
  902. 2160 10128 P 0 12 F 8 9 F (The) S 50 J ( first non-terminal symbol defined in the rules section is called the ) S 0 12 F 8 9 F I (start) S 50 J ( symbol) S E 0 12 F 8 9 F (.) S 50 J (  This) S 
  903. 2160 10368 P (symbol is taken to be the largest, most general structure described by the grammar rules.) S 
  904. 2160 10608 P (For example, if you are generating the parser for a compiler, the start symbol should) S 
  905. 2160 10848 P (describe what a complete program looks like in the language to be parsed.) S 
  906. 2160 11288 P (If you do not want the first grammar rule to be taken as the start symbol, you can use the) S 
  907. 2160 11528 P (directive) S 
  908. 2880 11948 P 0 12 F 0 9 F (%start) S 108 J ( NAME) S 
  909. 2160 12388 P 0 12 F 8 9 F (in) S 50 J ( your rules section.  This indicates that the non-terminal symbol named ) S 0 12 F 0 9 F (NAME) S 0 12 F 8 9 F () S 50 J ( is the start) S 
  910. 2160 12628 P (symbol.  ) S 0 12 F 0 9 F (NAME) S 0 12 F 8 9 F () S 50 J ( must be defined somewhere in the rules section.) S 
  911. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  912. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 16) S 0 12 F 
  913. PE 
  914. 2880 1968 P 8 9 F (The) S 50 J ( start symbol must be all-encompassing: every other rule in the grammar must be) S 
  915. 2880 2208 P (related to the start symbol.  In a sense, the grammar forms a "tree": the root is the start) S 
  916. 2880 2448 P (symbol, the first set of branches are the symbols that make up the start symbol, the next) S 
  917. 2880 2688 P (set of branches are the symbols that make up the first set, and so on.  Any symbol that is) S 
  918. 2880 2928 P ("outside" this tree is reported as a ) S 0 12 F 8 9 F I (useless) S 50 J ( variable) S E 0 12 F 8 9 F () S 50 J ( in YAY output.  Useless variables are) S 
  919. 2880 3168 P (ignored by the parser -- the parser is looking for a complete start symbol, and nothing) S 
  920. 2880 3408 P (else.) S 
  921. 2880 4528 P 0 12 F 8 12 F I (3.2.5) S 67 J (  The End Marker) S E 
  922. 2880 5248 P 0 12 F 8 9 F (The) S 50 J ( end of parser input is marked by a special token called the ) S 0 12 F 8 9 F I (end) S 50 J ( marker) S E 0 12 F 8 9 F (.) S 50 J (  This token is) S 
  923. 2880 5488 P (often written as ) S 0 12 F 0 9 F ($end) S 0 12 F 8 9 F (;) S 50 J ( the value of the token is zero.) S 
  924. 2880 5928 P (It is the job of the lexical analyzer "yylex" to return a zero to indicate ) S 0 12 F 0 9 F ($end) S 0 12 F 8 9 F () S 50 J ( when the end of) S 
  925. 2880 6168 P (input is reached \(e.g. at end of file, or at a keyword that indicates end of input\).) S 
  926. 2880 6608 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( terminates when it has parsed a start symbol followed by the end marker.) S 
  927. 2880 7728 P 0 12 F 8 12 F I (3.2.6) S 67 J (  Declarations in yyparse) S E 
  928. 2880 8448 P 0 12 F 8 9 F (You) S 50 J ( can specify C declarations that will be local to ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( in much the same way) S 
  929. 2880 8688 P (that you specify external declarations in the Declarations Section.  Enclose the) S 
  930. 2880 8928 P (declarations in ) S 0 12 F 0 9 F (%{) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (%}) S 0 12 F 8 9 F () S 50 J ( symbols, as in) S 
  931. 3600 9348 P 0 12 F 0 9 F (%{) S 
  932. 3600 9568 P () S 108 J (    /* External declaratios */) S 
  933. 3600 9788 P (%}) S 
  934. 3600 10008 P (%%) S 
  935. 3600 10228 P (/* Rules Section starts here */) S 
  936. 3600 10448 P ({%) S 
  937. 3600 10668 P (    /* Declarations here will be) S 
  938. 3600 10888 P (       local to "yyparse" */) S 
  939. 3600 11108 P (%}) S 
  940. 3600 11328 P (/* Rules */) S 
  941. 3600 11548 P (%%) S 
  942. 3600 11768 P (/* Program section */) S 
  943. 2880 12208 P 0 12 F 8 9 F (You) S 50 J ( may also put declarations at the start of recognition action code.) S 
  944. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  945. 2880 14800 P 0 12 F 24 10 F (17) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  946. PE 
  947. 2160 2308 P 8 12 F B (3.3) S 67 J (  The Programs Section) S E 
  948. 2160 3028 P 0 12 F 8 9 F (The) S 50 J ( programs section of YAY input may contain functions that should be linked in with the) S 
  949. 2160 3268 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( routine.  YAY itself does nothing with these functions -- it simply adds the) S 
  950. 2160 3508 P (source code on the end of the source code produced from the grammar rules.  In this way,) S 
  951. 2160 3748 P (the functions can be compiled at the same time that the YAY-produced code is compiled.) S 
  952. 2160 4188 P (Of course, these additional functions could be compiled separately and linked with the) S 
  953. 2160 4428 P (YAY-produced code later on \(once everything is in object code format\).  Separate) S 
  954. 2160 4668 P (compilation of modules is strongly recommended for large parsers.  However, functions) S 
  955. 2160 4908 P (that are compiled separately need a special mechanism if they want to use any manifests) S 
  956. 2160 5148 P (that are defined in the YAY-produced code, and it is sometimes simpler to make the) S 
  957. 2160 5388 P (program part of the YAY input.) S 
  958. 2160 5828 P (For example, consider the case of ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (.) S 50 J (  Every time ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( obtains a token from) S 
  959. 2160 6068 P (the input, it returns to ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( with a value that indicates the type of token found.) S 
  960. 2160 6308 P (Obviously then, ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( must agree on which return values indicate) S 
  961. 2160 6548 P (which kind of tokens.  Since ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( already refers to tokens using manifest) S 
  962. 2160 6788 P (constants \(created in the declarations section with the ) S 0 12 F 0 9 F (%token) S 0 12 F 8 9 F () S 50 J ( directive\), it makes sense) S 
  963. 2160 7028 P (for ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( to use the same manifest constants.  The lexical analyzer can do this very) S 
  964. 2160 7268 P (easily if it is compiled along with ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (.) S 
  965. 2160 7708 P (Size) S 50 J ( might be the determining factor.  With very simple parsers, it's easier to put ) S 0 12 F 0 9 F ("yylex") S 
  966. 2160 7948 P 0 12 F 8 9 F (in) S 50 J ( the Programs Section.  With larger parsers, the advantages of separate compilation are) S 
  967. 2160 8188 P (well worth the extra effort.) S 
  968. 2160 8628 P (If you are going to compile ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( or other routines separately from ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (,) S 50 J ( use) S 
  969. 2160 8868 P (the) S 
  970. 2880 9288 P 0 12 F 0 9 F (Header=file) S 
  971. 2160 9728 P 0 12 F 8 9 F (option) S 50 J ( on the YAY command line.  YAY will write out the manifest definitions to the file of) S 
  972. 2160 9968 P (your choice.  This file can then be #included to obtain these definitions for ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( or) S 
  973. 2160 10208 P (any other routine that needs them.  The manifests are already included in the generated) S 
  974. 2160 10448 P (parser code, so you only need them for separately compiled modules.) S 
  975. 2160 11568 P 0 12 F 8 12 F I (3.3.1) S 67 J (  The Lexical Analyzer) S E 
  976. 2160 12288 P 0 12 F 8 9 F (The) S 50 J ( lexical analyzer ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( reads input and breaks it into tokens.  It is ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( that) S 
  977. 2160 12528 P (determines what constitutes a token.  For example, some lexical analyzers may return) S 
  978. 2160 12768 P (numbers one digit at a time while others collect numbers in their entirety before passing) S 
  979. 2160 13008 P (them to the parser.) S 
  980. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  981. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 18) S 0 12 F 
  982. PE 
  983. 2880 1968 P 8 9 F (Similarly,) S 50 J ( some lexical analyzers may recognize keywords such as ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (WHILE) S 0 12 F 8 9 F () S 50 J ( and will) S 
  984. 2880 2208 P (tell the parser that an ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( token or ) S 0 12 F 0 9 F (WHILE) S 0 12 F 8 9 F () S 50 J ( token has been found.  Others may not be) S 
  985. 2880 2448 P (designed to recognize keywords, so it is up to the parser itself to distinguish between) S 
  986. 2880 2688 P (keywords and other things like variable names.) S 
  987. 2880 3128 P (As noted before, each token named in the declarations section of the YAY input is set up) S 
  988. 2880 3368 P (as a manifest constant.  The value of the first token named is ) S 0 12 F 0 9 F (257) S 0 12 F 8 9 F (,) S 50 J ( the value of the next is) S 
  989. 2880 3608 P 0 12 F 0 9 F (258) S 0 12 F 8 9 F (,) S 50 J ( and so on.  You can also set your own values for tokens by placing a positive integer) S 
  990. 2880 3848 P (after the first appearance of any token in the declarations section. For example,) S 
  991. 3600 4268 P 0 12 F 0 9 F (%token) S 108 J ( AA 56) S 
  992. 2880 4708 P 0 12 F 8 9 F (assigns) S 50 J ( a value of ) S 0 12 F 0 9 F (56) S 0 12 F 8 9 F () S 50 J ( to the manifest \(token\) symbol ) S 0 12 F 0 9 F (AA) S 0 12 F 8 9 F (.) S 50 J (  This mechanism is very seldom) S 
  993. 2880 4948 P (needed, and we recommend that users avoid it whenever possible.) S 
  994. 2880 5388 P (There is little else to say about requirements for ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (.) S 50 J (  If it wishes to return the value) S 
  995. 2880 5628 P (of a token as well as an indication of its type, the value is assigned to the external variable) S 
  996. 2880 5868 P 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F (.) S 50 J (  By default, ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F () S 50 J ( is defined as an ) S 0 12 F 0 9 F B (int) S E 0 12 F 8 9 F () S 50 J ( value but it can also be used to) S 
  997. 2880 6108 P (hold other types of values.  For more information, see the description of ) S 0 12 F 0 9 F (%union) S 0 12 F 8 9 F () S 50 J ( in) S 
  998. 2880 6348 P (Chapter 7.) S 
  999. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1000. 2880 14800 P 0 12 F 24 10 F (19) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1001. PE 
  1002. 5760 2448 P 8 18 F B (4.) S 100 J ( Internal Structures) S E 
  1003. 2160 4048 P 0 12 F 8 9 F (In) S 50 J ( order to use YAY effectively, it is helpful to understand some of the internal workings of) S 
  1004. 2160 4288 P (the parser that YAY produces.  In this chapter, we will look at some of these structures.) S 
  1005. 2160 4728 P (To give us a point of reference, suppose we have produced a parser with grammar) S 
  1006. 2880 5148 P 0 12 F 0 9 F (%token) S 108 J ( NUM) S 
  1007. 2880 5368 P (%left '+' '-') S 
  1008. 2880 5588 P (%left '*' '/') S 
  1009. 2880 5808 P (%%) S 
  1010. 2880 6028 P (expr : NUM) S 
  1011. 2880 6248 P (     | expr '+' expr) S 
  1012. 2880 6468 P (     | expr '-' expr) S 
  1013. 2880 6688 P (     | expr '*' expr) S 
  1014. 2880 6908 P (     | expr '/' expr) S 
  1015. 2880 7128 P (     | '\(' expr '\)') S 
  1016. 2880 7348 P (     ;) S 
  1017. 2160 8168 P 0 12 F 8 12 F B (4.1) S 67 J (  States) S E 
  1018. 2160 8888 P 0 12 F 8 9 F (As) S 50 J ( the parser reads in token after token, it switches between various ) S 0 12 F 8 9 F I (states) S E 0 12 F 8 9 F (.) S 50 J (  You can) S 
  1019. 2160 9128 P (think of a state as point where the parser says, "I have read ) S 0 12 F 8 9 F I (this) S E 0 12 F 8 9 F () S 50 J ( particular sequence of) S 
  1020. 2160 9368 P (input tokens and now I am looking for one of ) S 0 12 F 8 9 F I (these) S E 0 12 F 8 9 F () S 50 J ( tokens.") S 
  1021. 2160 9808 P (For example, a parser for the C language might be in a state where it has finished reading) S 
  1022. 2160 10048 P (a complete statement and is ready for the start of a new statement.  It therefore expects) S 
  1023. 2160 10288 P (some token that can legitimately start a statement \(e.g. a keyword like ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (WHILE) S 0 12 F 8 9 F (,) S 50 J ( or the) S 
  1024. 2160 10528 P (name of a variable for an assignment\).) S 
  1025. 2160 10968 P (In this state, it reads a token.  Say it finds the token corresponding to the keyword ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F (.) S 50 J (  It) S 
  1026. 2160 11208 P (then switches to a new state where it says "I have seen an ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( and now I want to see the ) S 0 12 F 0 9 F (\() S 
  1027. 2160 11448 P 0 12 F 8 9 F (that) S 50 J ( begins the ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( condition."  When it finds the ) S 0 12 F 0 9 F (\() S 0 12 F 8 9 F (,) S 50 J ( it switches again to a state that says "I) S 
  1028. 2160 11688 P (have found ) S 0 12 F 0 9 F (IF\() S 0 12 F 8 9 F () S 50 J ( and now I want the start of a condition expression.") S 
  1029. 2160 12128 P (States break the parsing process into simple steps.  At each step, the parser knows what) S 
  1030. 2160 12368 P (it has seen and what it is looking for next.) S 
  1031. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1032. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 20) S 0 12 F 
  1033. PE 
  1034. 2880 1968 P 8 9 F (YAY) S 50 J ( assigns numbers to every possible state the parser can enter.  The 0th state is) S 
  1035. 2880 2208 P (always the one that describes the parser's condition before it has read any input.  Other) S 
  1036. 2880 2448 P (states are numbered arbitrarily.) S 
  1037. 2880 2888 P (Sometimes a particular input can only be the start of one construct.  For example, the ) S 0 12 F 0 9 F (FOR) S 
  1038. 2880 3128 P 0 12 F 8 9 F (keyword) S 50 J ( in C can only be the start of a ) S 0 12 F 0 9 F (FOR) S 0 12 F 8 9 F () S 50 J ( statement, and the ) S 0 12 F 0 9 F (FOR) S 0 12 F 8 9 F () S 50 J ( statement only has) S 
  1039. 2880 3368 P (one form.) S 
  1040. 2880 3808 P (On the other hand, a grammar may have several non-terminal symbols that start the same) S 
  1041. 2880 4048 P (way.  In our sample grammar, all of) S 
  1042. 3600 4468 P 0 12 F 0 9 F (expr) S 108 J ( '+' expr) S 
  1043. 3600 4688 P (expr '-' expr) S 
  1044. 3600 4908 P (expr '*' expr) S 
  1045. 3600 5128 P (expr '/' expr) S 
  1046. 2880 5568 P 0 12 F 8 9 F (start) S 50 J ( with an ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 50 J (  If the parser finds that the input begins with an ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (,) S 50 J ( the parser) S 
  1047. 2880 5808 P (has no idea which rule matches the input until it has read the operator following the first) S 
  1048. 2880 6048 P 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 
  1049. 2880 6488 P (The) S 50 J ( parser chooses which state it will enter next by looking at the next input token.  This) S 
  1050. 2880 6728 P (token is called the ) S 0 12 F 8 9 F I (lookahead) S 50 J ( symbol) S E 0 12 F 8 9 F () S 50 J ( for that state.) S 
  1051. 2880 7548 P 0 12 F 8 12 F B (4.2) S 67 J (  Diagramming States) S E 
  1052. 2880 8268 P 0 12 F 8 9 F (YAY) S 50 J ( uses simple diagrams to describe the various states of the parser.  These diagrams) S 
  1053. 2880 8508 P (show what the parser has seen and what it is looking for next.  The diagrams are given in) S 
  1054. 2880 8748 P (the Parser Description report prouced by YAY \(see Chapter 6\).) S 
  1055. 2880 9188 P (For example, consider the state where the parser has just read a complete ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( at the) S 
  1056. 2880 9428 P (beginning of a larger expression.  It is now in a state where it expects to see one of the) S 
  1057. 2880 9668 P (operators ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (*) S 0 12 F 8 9 F (,) S 50 J ( or ) S 0 12 F 0 9 F (/) S 0 12 F 8 9 F (,) S 50 J ( or perhaps the ) S 0 12 F 0 9 F ($end) S 0 12 F 8 9 F () S 50 J ( marker indicating the end of input.  YAY) S 
  1058. 2880 9908 P (diagrams this state as) S 
  1059. 3600 10328 P 0 12 F 0 9 F ($accept:) S 108 J (  expr.$end) S 
  1060. 3600 10548 P (expr:     expr.'+' expr) S 
  1061. 3600 10768 P (expr:     expr.'-' expr) S 
  1062. 3600 10988 P (expr:     expr.'*' expr) S 
  1063. 3600 11208 P (expr:     expr.'/' expr) S 
  1064. 2880 11648 P 0 12 F 8 9 F (This) S 50 J ( lists the possible grammar constructs that the parser may be working on.  \(The first) S 
  1065. 2880 11888 P (line ) S 0 12 F 0 9 F ($accept) S 0 12 F 8 9 F () S 50 J ( stands for the Start symbol.\)  The ) S 0 12 F 0 9 F (".") S 0 12 F 8 9 F () S 50 J ( indicates how much the parser has) S 
  1066. 2880 12128 P (read so far.) S 
  1067. 2880 12568 P (If the lookahead symbol is ) S 0 12 F 0 9 F (*) S 0 12 F 8 9 F (,) S 50 J ( the parser will switch to a state diagrammed by) S 
  1068. 3600 12988 P 0 12 F 0 9 F (expr:) S 108 J (     expr '*'.expr) S 
  1069. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1070. 2880 14800 P 0 12 F 24 10 F (21) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1071. PE 
  1072. 2160 1968 P 8 9 F (In) S 50 J ( this state, the parser knows that the next thing to come will be another ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 50 J (  This) S 
  1073. 2160 2208 P (means that the only valid tokens that can be read next are ) S 0 12 F 0 9 F (\() S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (NUM) S 0 12 F 8 9 F (,) S 50 J ( since those are the) S 
  1074. 2160 2448 P (only things that start a valid ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 
  1075. 2160 3268 P 0 12 F 8 12 F B (4.3) S 67 J (  State Actions) S E 
  1076. 2160 3988 P 0 12 F 8 9 F (There) S 50 J ( are several possible actions that the parser can take in a state:) S 
  1077. 2160 4428 P (\(a\)          ) S 0 12 F 8 9 F I (accept) S E 0 12 F 8 9 F () S 50 J ( the input;) S 
  1078. 2160 4868 P (\(b\)          ) S 0 12 F 8 9 F I (shift) S E 0 12 F 8 9 F () S 50 J ( to a new state;) S 
  1079. 2160 5308 P (\(c\)) S 510 J ( ) S 0 12 F 8 9 F I (reduce) S E 0 12 F 8 9 F () S 50 J ( one or more input tokens to a single non-terminal symbol, according to a) S 
  1080. 2880 5548 P (grammar rule;) S 
  1081. 2160 5988 P (\(d\)          ) S 0 12 F 8 9 F I (goto) S E 0 12 F 8 9 F () S 50 J ( a new state;) S 
  1082. 2160 6428 P (\(e\)          raise an ) S 0 12 F 8 9 F I (error) S E 0 12 F 8 9 F () S 50 J ( condition.) S 
  1083. 2160 6868 P (In order to decide which action to take, the parser checks the lookahead symbol \(except in) S 
  1084. 2160 7108 P (states where the parser can only take one possible action so the lookahead symbol is) S 
  1085. 2160 7348 P (irrelevant\).) S 
  1086. 2160 7788 P (This means that a typical state has a series of possible actions based upon the possible) S 
  1087. 2160 8028 P (values of the lookahead symbol.  In YAY output, you might see) S 
  1088. 2880 8448 P 0 12 F 0 9 F ('+') S 108 J (   shift 8) S 
  1089. 2880 8668 P ('-'   shift 7) S 
  1090. 2880 8888 P ('*'   shift 6) S 
  1091. 2880 9108 P ('/'   shift 5) S 
  1092. 2880 9328 P ('\)'   shift 9) S 
  1093. 2880 9548 P ( .    error) S 
  1094. 2160 9988 P 0 12 F 8 9 F (This) S 50 J ( says that if the parser is in this state and the lookahead symbol is ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F (,) S 50 J ( the parser will) S 
  1095. 2160 10228 P (shift to State 8.  If the lookahead symbol is ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F (,) S 50 J ( the parser will shift to State 7, and so on.) S 
  1096. 2160 10668 P (The ) S 0 12 F 0 9 F (".") S 0 12 F 8 9 F () S 50 J ( in the final line stands for any other token not mentioned in the preceding list. If) S 
  1097. 2160 10908 P (the parser finds any unexpected tokens in this particular state, it will take the ) S 0 12 F 0 9 F (error) S 
  1098. 2160 11148 P 0 12 F 8 9 F (action.) S 
  1099. 2160 11588 P (The) S 50 J ( sections that follow explain precisely what each state action means and what the) S 
  1100. 2160 11828 P (parser does to handle these actions.) S 
  1101. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1102. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 22) S 0 12 F 
  1103. PE 
  1104. 2880 2308 P 8 12 F I (4.3.1) S 67 J (  The Accept Action) S E 
  1105. 2880 3028 P 0 12 F 8 9 F (The) S 50 J ( Accept action only happens when the parser is in a state that indicates it has seen a) S 
  1106. 2880 3268 P (complete input and the lookahead symbol is the end marker ) S 0 12 F 0 9 F ($end) S 0 12 F 8 9 F (.) S 50 J (  When the parser) S 
  1107. 2880 3508 P (takes the Accept action, ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( terminates and returns a zero to indicate that the) S 
  1108. 2880 3748 P (input was correct.) S 
  1109. 2880 4868 P 0 12 F 8 12 F I (4.3.2) S 67 J (  The Shift Action) S E 
  1110. 2880 5588 P 0 12 F 8 9 F (The) S 50 J ( Shift action happens when the parser is part way through a grammar construct and a) S 
  1111. 2880 5828 P (new token is read in.  As an example, State 4 in our sample parser is diagrammed with) S 
  1112. 3600 6248 P 0 12 F 0 9 F (expr:) S 108 J (     expr.'+' expr) S 
  1113. 3600 6468 P (expr:     expr.'-' expr) S 
  1114. 3600 6688 P (expr:     expr.'*' expr) S 
  1115. 3600 6908 P (expr:     expr.'/' expr) S 
  1116. 3600 7128 P (expr:     '\(' expr.'\)') S 
  1117. 3600 7548 P ('+'   shift 8) S 
  1118. 3600 7768 P ('-'   shift 7) S 
  1119. 3600 7988 P ('*'   shift 6) S 
  1120. 3600 8208 P ('/'   shift 5) S 
  1121. 3600 8428 P ('\)'   shift 9) S 
  1122. 3600 8648 P ( .    error) S 
  1123. 2880 9088 P 0 12 F 8 9 F (This) S 50 J ( shows that the parser will shift to various other states depending on the value of the) S 
  1124. 2880 9328 P (lookahead symbol.  For example, if the lookahead symbol is ) S 0 12 F 0 9 F (*) S 0 12 F 8 9 F () S 50 J ( the parser shifts to State 6) S 
  1125. 2880 9568 P (which has the diagram) S 
  1126. 3600 10028 P 0 12 F 0 9 F (expr:) S 108 J (     expr '*'.expr) S 
  1127. 3600 10448 P (NUM   shift 2) S 
  1128. 3600 10668 P ('\('   shift 1) S 
  1129. 3600 10888 P ( .    error) S 
  1130. 3600 11308 P (expr  goto 11) S 
  1131. 2880 11748 P 0 12 F 8 9 F (In) S 50 J ( this new state, the parser has further shifts it can make, depending on the next) S 
  1132. 2880 11988 P (lookahead symbol.) S 
  1133. 2880 12428 P (When the parser shifts to a new state, it saves the previous state on a stack called the) S 
  1134. 2880 12668 P 0 12 F 8 9 F I (state) S 50 J ( stack) S E 0 12 F 8 9 F (.) S 50 J (  The stack provides a history of the states that the parser has passed through) S 
  1135. 2880 12908 P (while it was reading input.  It is also a control mechanism as will be seen later in this) S 
  1136. 2880 13148 P (chapter.) S 
  1137. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1138. 2880 14800 P 0 12 F 24 10 F (23) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1139. PE 
  1140. 2160 2168 P 8 9 F (Paralleling) S 50 J ( the state stack is a ) S 0 12 F 8 9 F I (value) S E 0 12 F 8 9 F () S 50 J ( stack that records the values of tokens and non-) S 
  1141. 2160 2408 P (terminal symbols encountered while parsing.  The value of a token is the ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F () S 50 J ( value) S 
  1142. 2160 2648 P (returned by ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( at the time the token was read.  The value of a non-terminal symbol) S 
  1143. 2160 2888 P (is the ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( value set by the recognition action associated with that symbol's definition.  If the) S 
  1144. 2160 3128 P (definition didn't have an associate recognition action, the value of the symbol is the value) S 
  1145. 2160 3368 P (of the first item in the symbol's definition.) S 
  1146. 2160 3808 P (At the same time that the Shift action pushes the current state onto the state stack, it also) S 
  1147. 2160 4048 P (pushes the ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F () S 50 J ( value of the lookahead symbol \(token\) onto the value stack.) S 
  1148. 2160 5168 P 0 12 F 8 12 F I (4.3.3) S 67 J (  The Reduce Action) S E 
  1149. 2160 5888 P 0 12 F 8 9 F (The) S 50 J ( Reduce action takes place in states where the parser has recognized all the items) S 
  1150. 2160 6128 P (that make up a non-terminal symbol.  For example, the diagram of State 9 in our sample) S 
  1151. 2160 6368 P (grammar is) S 
  1152. 2880 6788 P 0 12 F 0 9 F (expr:) S 108 J (     '\(' expr '\)'.) S 
  1153. 2880 7208 P ( .    reduce \(6\)) S 
  1154. 2160 7648 P 0 12 F 8 9 F (At) S 50 J ( this point, the parser has seen all three components that make up the non-terminal) S 
  1155. 2160 7888 P (symbol ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (:) S 
  1156. 2880 8308 P 0 12 F 0 9 F ('\(') S 
  1157. 2880 8528 P (expr) S 
  1158. 2880 8748 P ('\)') S 
  1159. 2160 9188 P 0 12 F 8 9 F (As) S 50 J ( the line) S 
  1160. 2880 9608 P 0 12 F 0 9 F () S 108 J ( .    reduce \(6\)) S 
  1161. 2160 10048 P 0 12 F 8 9 F (shows,) S 50 J ( it doesn't matter what the lookahead symbol is at this point.  The non-terminal) S 
  1162. 2160 10288 P (symbol has been recognized, and the parser is ready for a Reduce action.  \(Note that the) S 
  1163. 2160 10528 P (\(6\) in the above line just means that the parser has recognized the non-terminal symbol) S 
  1164. 2160 10768 P (defined in rule \(6\) of the grammar.  We will say more about this in a later chapter.\)) S 
  1165. 2160 11208 P (The Reduce action performs a number of operations.  First, it pops states off the state) S 
  1166. 2160 11448 P (stack.  If the recognized non-terminal symbol had N components, a reduction pops N-1) S 
  1167. 2160 11688 P (states off the stack.  In other words, the parser goes back to the state it was in when it first) S 
  1168. 2160 11928 P (began to gather the recognized construct.) S 
  1169. 2160 12368 P (Next, the Reduce action pops values off the value stack.  If the definition that is being) S 
  1170. 2160 12608 P (reduced consisted of N items, the Reduce action conceptually pops N values off the stack.) S 
  1171. 2160 12848 P (The topmost value on the stack is assigned to ) S 0 12 F 0 9 F ($N) S 0 12 F 8 9 F (,) S 50 J ( the next to ) S 0 12 F 0 9 F ($N-1) S 0 12 F 8 9 F (,) S 50 J ( and so on down to) S 
  1172. 2160 13088 P 0 12 F 0 9 F ($1) S 0 12 F 8 9 F (.) S 
  1173. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1174. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 24) S 0 12 F 
  1175. PE 
  1176. 2880 2168 P 8 9 F (Once) S 50 J ( the Reduce action has gathered all the ) S 0 12 F 0 9 F ($X) S 0 12 F 8 9 F () S 50 J ( values, the parser invokes the recognition) S 
  1177. 2880 2408 P (action that was associated with the grammar rule being reduced.  This recognition will use) S 
  1178. 2880 2648 P (the ) S 0 12 F 0 9 F ($X) S 0 12 F 8 9 F () S 50 J ( values to come up with a ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( value for the non-terminal symbol.  This value is) S 
  1179. 2880 2888 P (pushed onto the value stack, thereby replacing the N values that were previously on the) S 
  1180. 2880 3128 P (stack.) S 
  1181. 2880 3568 P (If the non-terminal symbol had no recognition action, or if the recognition action did not set) S 
  1182. 2880 3808 P 0 12 F 0 9 F ($$) S 0 12 F 8 9 F (,) S 50 J ( the parser puts the value of ) S 0 12 F 0 9 F ($1) S 0 12 F 8 9 F () S 50 J ( back on the stack.  \(In reality, the value is never) S 
  1183. 2880 4048 P (popped off.\)) S 
  1184. 2880 4488 P (Lastly, the Reduce action sets things up so that  the lookahead symbol seems to be the) S 
  1185. 2880 4728 P (non-terminal symbol that was just recognized.  For example, it may say that the lookahead) S 
  1186. 2880 4968 P (symbol is now an ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( instead of a token.) S 
  1187. 2880 6088 P 0 12 F 8 12 F I (4.3.4) S 67 J (  The Goto Action) S E 
  1188. 2880 6808 P 0 12 F 8 9 F (The) S 50 J ( Goto action is a continuation of the Reduce process.  Goto is almost the same as) S 
  1189. 2880 7048 P (Shift -- the only difference is that the Goto action takes place when the lookahead symbol) S 
  1190. 2880 7288 P (is a non-terminal symbol while a Shift takes place when the lookahead symbol is a token.) S 
  1191. 2880 7728 P (For example, State 6 in our sample grammar reads) S 
  1192. 3600 8148 P 0 12 F 0 9 F (expr:) S 108 J (    expr '*'.expr) S 
  1193. 3600 8568 P (NUM   shift 2) S 
  1194. 3600 8788 P ('\('   shift 1) S 
  1195. 3600 9008 P ( .    error) S 
  1196. 3600 9428 P (expr  goto 12) S 
  1197. 2880 9868 P 0 12 F 8 9 F (The) S 50 J ( first time the parser enters this state, the lookahead symbol will be a token and the) S 
  1198. 2880 10108 P (parser will Shift on the token into some state where it will begin to gather an ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 
  1199. 2880 10348 P (When) S 50 J ( it has a complete ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (,) S 50 J ( it will perform a Reduce action that will return to this) S 
  1200. 2880 10588 P (state and set the lookahead symbol to ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 50 J (  Now when the parser has to decide what) S 
  1201. 2880 10828 P (to do next, it sees that it has an ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( for the lookahead symbol and therefore takes the) S 
  1202. 2880 11068 P (Goto action and moves to State 12.) S 
  1203. 2880 11508 P (The Shift action pushes the current state onto the state stack.  The Goto does not have to) S 
  1204. 2880 11748 P (do this -- the state was on the stack already.  Similarly, Shift pushes a value onto the value) S 
  1205. 2880 11988 P (stack, but Goto does not, since the value corresponding to the non-terminal symbol was) S 
  1206. 2880 12228 P (already put on the value stack by the Reduce action.) S 
  1207. 2880 12668 P (When the parser reaches the new state, the lookahead symbol will be restored to) S 
  1208. 2880 12908 P (whatever it was at the time of the Reduce action.) S 
  1209. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1210. 2880 14800 P 0 12 F 24 10 F (25) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1211. PE 
  1212. 2160 1968 P 8 9 F (Essentially) S 50 J ( then, a Goto is like a Shift except that it takes place when you come ) S 0 12 F 8 9 F I (back) S E 0 12 F 8 9 F () S 50 J ( to a) S 
  1213. 2160 2208 P (state with the Reduce action.  Also, a Shift is based on the value of a single input token) S 
  1214. 2160 2448 P (while a Goto is based on a non-terminal symbol.) S 
  1215. 2160 3568 P 0 12 F 8 12 F I (4.3.5) S 67 J (  The Error Action) S E 
  1216. 2160 4288 P 0 12 F 8 9 F (The) S 50 J ( parser takes the Error action when it encounters any input token which cannot validly) S 
  1217. 2160 4528 P (appear in a particular input location.  When this happens, the parser raises the ) S 0 12 F 0 9 F ("error") S 
  1218. 2160 4768 P 0 12 F 8 9 F (condition.) S 50 J (  Since error-handling can be quite complicated, we will devote the whole of the) S 
  1219. 2160 5008 P (next chapter to the subject.) S 
  1220. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1221. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 26) S 0 12 F 
  1222. PE 
  1223. 7140 2448 P 8 18 F B (5.) S 100 J ( Error-Handling) S E 
  1224. 2880 4048 P 0 12 F 8 9 F (If) S 50 J ( a piece of input is invalid, the parser can do nothing with it.  Except in extreme cases,) S 
  1225. 2880 4288 P (however, it is inappropriate for the parser to stop all processing as soon as an error is) S 
  1226. 2880 4528 P (found.  Instead, the parser should skip over the invalid input and resume parsing as soon) S 
  1227. 2880 4768 P (after the error as possible.  In this way, the parser can find many syntax errors in one pass) S 
  1228. 2880 5008 P (through the input, saving time and trouble for the user.) S 
  1229. 2880 5448 P (YAY therefore tries to generate a parser that can "restart" as soon as possible after an) S 
  1230. 2880 5688 P (error occurs.  YAY does this by letting you specify points at which the parser can pick up) S 
  1231. 2880 5928 P (after errors.  You may also dictate what special processing should take place if an error is) S 
  1232. 2880 6168 P (encountered at one of these points.) S 
  1233. 2880 6988 P 0 12 F 8 12 F B (5.1) S 67 J (  The "error" Symbol) S E 
  1234. 2880 7708 P 0 12 F 8 9 F (YAY's) S 50 J ( error handling facilities use the keyword ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( to signify an erroneous input.  As a) S 
  1235. 2880 7948 P (result, ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( may not be used as the name of a user-defined token or non-terminal) S 
  1236. 2880 8188 P (symbol.) S 
  1237. 2880 8628 P (You should put ") S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F (") S 50 J ( in your grammar rules where error recovery might take place.) S 
  1238. 2880 8868 P (For example, you might write) S 
  1239. 3600 9288 P 0 12 F 0 9 F (statement:) S 108 J ( error) S 
  1240. 3600 9508 P (    | /* other definitions of a statement */;) S 
  1241. 2880 9948 P 0 12 F 8 9 F (This) S 50 J ( tells YAY that errors may occur in statements, and that after an error, the parser is) S 
  1242. 2880 10188 P (free to restart parsing at the end of a complete statement.) S 
  1243. 2880 11008 P 0 12 F 8 12 F B (5.2) S 67 J (  The Error Condition) S E 
  1244. 2880 11728 P 0 12 F 8 9 F (As) S 50 J ( noted in the last chapter, YAY will take the Error action if it finds an input that is not) S 
  1245. 2880 11968 P (valid in a particular location.  The Error action has the following steps.) S 
  1246. 2880 12408 P (\(a\)          See if the current state has a Shift action associated with the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( symbol.  If it) S 
  1247. 3600 12648 P (does, shift on this action.) S 
  1248. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1249. 2880 14800 P 0 12 F 24 10 F (27) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1250. PE 
  1251. 2160 1968 P 8 9 F (\(b\)) S 500 J ( If) S 50 J ( the current state has no such action, pop the state off the stack and check the) S 
  1252. 2880 2208 P (next state.  Also pop off the top value on the value stack, so that the state stack) S 
  1253. 2880 2448 P (and value stack stay in synch.) S 
  1254. 2160 2888 P (\(c\)) S 510 J ( Repeat) S 50 J ( \(b\) until the parser finds a state that can shift on the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( symbol.) S 
  1255. 2160 3328 P (\(d\)          Take the Shift action associated with the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( symbol.  Note that this pushes) S 
  1256. 2880 3568 P (the current state on the stack, i.e. the state that is capable of handling errors.  No) S 
  1257. 2880 3808 P (new value is pushed onto the value stack -- the parser keeps whatever value was) S 
  1258. 2880 4048 P (already associated with the state that can handle errors.) S 
  1259. 2160 4488 P (When the parser shifts out of the state that can handle errors, the lookahead symbol will) S 
  1260. 2160 4728 P (be whatever token caused the error condition in the first place.  The parser will then try to) S 
  1261. 2160 4968 P (proceed with normal processing.) S 
  1262. 2160 5408 P (Of course, it is quite possible that the original lookahead symbol is invalid in the new) S 
  1263. 2160 5648 P (context.  If the lookahead symbol causes an error again, it is discarded and the error) S 
  1264. 2160 5888 P (condition stays in effect.  The parser will continue to read new tokens and discard them) S 
  1265. 2160 6128 P (until it finds a token that can validly follow the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F (.) S 50 J (  The parser will then take whatever) S 
  1266. 2160 6368 P (action is associated with the valid token.) S 
  1267. 2160 6808 P (In a typical grammar, the state that has been handling errors will eventually be popped off) S 
  1268. 2160 7048 P (the stack in a Reduce operation.) S 
  1269. 2160 7488 P (Notice that the parser always ) S 0 12 F 8 9 F I (Shifts) S E 0 12 F 8 9 F () S 50 J ( on the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( token.  It will never Reduce on ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F (,) S 
  1270. 2160 7728 P (even) S 50 J ( if the grammar has a state where ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( is associated with a Reduce action.) S 
  1271. 2160 8168 P (In some situations, an error condition will be raised and the parser will pop all the way to) S 
  1272. 2160 8408 P (the bottom of the state stack without finding a state that can handle the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( symbol.) S 
  1273. 2160 8648 P (For example, the grammar may have no provisions for error recovery. In this case,) S 
  1274. 2160 8888 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( simply terminates and returns a 1 to its caller.) S 
  1275. 2160 9708 P 0 12 F 8 12 F B (5.3) S 67 J (  Examples) S E 
  1276. 2160 10428 P 0 12 F 8 9 F (As) S 50 J ( a simple example, consider a parser for a simple desk calculator.  All statements end in) S 
  1277. 2160 10668 P (a semicolon.  Thus we might see the rule) S 
  1278. 2880 11088 P 0 12 F 0 9 F (statement) S 108 J ( : var '=' expr ';') S 
  1279. 2880 11308 P (          | expr ';') S 
  1280. 2880 11528 P (          | error ';') S 
  1281. 2880 11748 P (          ;) S 
  1282. 2160 12188 P 0 12 F 8 9 F (When) S 50 J ( an error occurs in input, the parser will pop back through the state stack until it) S 
  1283. 2160 12428 P (comes to a state where the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( symbol is recognized.  For example, the state might be) S 
  1284. 2160 12668 P (diagrammed as) S 
  1285. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1286. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 28) S 0 12 F 
  1287. PE 
  1288. 3600 1948 P 0 9 F ($accept:) S 108 J (   .statement $end) S 
  1289. 3600 2368 P (error  shift 2) S 
  1290. 3600 2588 P (NUM    shift 4) S 
  1291. 3600 2808 P (.      error) S 
  1292. 3600 3228 P (var       goto 7) S 
  1293. 3600 3448 P (expr      goto 3) S 
  1294. 3600 3668 P (statement goto 5) S 
  1295. 2880 4108 P 0 12 F 8 9 F (If) S 50 J ( an error occurs anywhere in an input statement, the parser will pop back to this state,) S 
  1296. 2880 4348 P (then Shift to State 2.  State 2 will look like) S 
  1297. 3600 4768 P 0 12 F 0 9 F (statement:) S 108 J (   error.';') S 
  1298. 2880 4968 P 0 12 F 8 7 F (.) S 
  1299. 3600 5188 P 0 12 F 0 9 F (';') S 108 J (   shift 6) S 
  1300. 3600 5408 P ( .    error) S 
  1301. 2880 5848 P 0 12 F 8 9 F (In) S 50 J ( other words, the next token must be a semicolon.  If it isn't, another error occurs.  The) S 
  1302. 2880 6088 P (parser pops back to the previous state and takes the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( shift again.  Input will be) S 
  1303. 2880 6328 P (discarded token by token until a semicolon is found.  When the semicolon is found, the) S 
  1304. 2880 6568 P (parser will be able to shift from State 2 to State 6 which is) S 
  1305. 3600 6988 P 0 12 F 0 9 F (statement:) S 108 J (  error ';'.) S 
  1306. 3600 7408 P ( .    reduce \(3\)) S 
  1307. 2880 7848 P 0 12 F 8 9 F (The) S 50 J ( erroneous line is reduced to a ) S 0 12 F 0 9 F ("statement") S 0 12 F 8 9 F () S 50 J ( non-terminal symbol.) S 
  1308. 2880 8288 P (Now this example is simple, but it has its drawbacks.  It will get you into trouble if the) S 
  1309. 2880 8528 P (grammar has any concept of block structure or parenthesization.  Why?  Once an error) S 
  1310. 2880 8768 P (occurs, the rule) S 
  1311. 3600 9188 P 0 12 F 0 9 F (statement) S 108 J ( : error ';') S 
  1312. 2880 9628 P 0 12 F 8 9 F (effectively) S 50 J ( tells the parser to discard absolutely everything until it finds a ) S 0 12 F 0 9 F (;) S 0 12 F 8 9 F () S 50 J ( character.  If) S 
  1313. 2880 9868 P (you have a parser for C, for example, it would skip over important characters like ) S 0 12 F 0 9 F (\)) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (}) S 
  1314. 2880 10108 P 0 12 F 8 9 F (until) S 50 J ( it found a semicolon.  Your parentheses and braces would be out of balance for the) S 
  1315. 2880 10348 P (rest of the input and the whole parsing process would be a waste of time.  The same) S 
  1316. 2880 10588 P (principle applies to any rule that shows the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( token followed by some other non-null) S 
  1317. 2880 10828 P (symbol: it can lead to hopeless confusion in a lot of grammars.) S 
  1318. 2880 11268 P (It is safer to write the rule in a form like) S 
  1319. 3600 11688 P 0 12 F 0 9 F (statement) S 108 J ( : error) S 
  1320. 3600 11908 P (          | ';') S 
  1321. 3600 12128 P (          | /* other stuff */) S 
  1322. 2880 12568 P 0 12 F 8 9 F (In) S 50 J ( this case, the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( token only matches material until the parser finds something else) S 
  1323. 2880 12808 P (it recognizes \(e.g. the semicolon\).  Once this happens, the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( state will be reduced to) S 
  1324. 2880 13048 P (a ) S 0 12 F 0 9 F ("statement") S 0 12 F 8 9 F () S 50 J ( symbol and popped off the stack.  Parsing can then proceed as usual.) S 
  1325. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1326. 2880 14800 P 0 12 F 24 10 F (29) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1327. PE 
  1328. 2160 2308 P 8 12 F B (5.4) S 67 J (  Error Recognition Actions) S E 
  1329. 2160 3028 P 0 12 F 8 9 F (The) S 50 J ( easiest way to generate an error message is to associate a recognition action with the) S 
  1330. 2160 3268 P (grammar rule that recognizes the error.  You can do something simple like) S 
  1331. 2880 3688 P 0 12 F 0 9 F (statement:) S 108 J ( error) S 
  1332. 2880 3908 P (    {) S 
  1333. 2880 4128 P (        printf\("You made an error!\\n"\);) S 
  1334. 2880 4348 P (    }) S 
  1335. 2160 4788 P 0 12 F 8 9 F (or) S 50 J ( you can be fancier, as in) S 
  1336. 2880 5208 P 0 12 F 0 9 F (line:) S 108 J ( error '\\n' prompt line) S 
  1337. 2880 5428 P (    { $$ = $4; };) S 
  1338. 2880 5648 P (prompt: /* null token */) S 
  1339. 2880 5868 P (    { printf\("Please re-enter line.\\n"\); };) S 
  1340. 2160 6308 P 0 12 F 8 9 F (If) S 50 J ( an error occurs, the parser skips until it finds a new-line character.  After the new-line, it) S 
  1341. 2160 6548 P (will always find a null token matching ) S 0 12 F 0 9 F ("prompt") S 0 12 F 8 9 F (,) S 50 J ( and the recognition action for ) S 0 12 F 0 9 F ("prompt") S 
  1342. 2160 6788 P 0 12 F 8 9 F (will) S 50 J ( print out the message) S 
  1343. 2880 7208 P 0 12 F 0 9 F (Please) S 108 J ( re-enter line) S 
  1344. 2160 7648 P 0 12 F 8 9 F (The) S 50 J ( final symbol in the rule is another ) S 0 12 F 0 9 F ("line") S 0 12 F 8 9 F (,) S 50 J ( and the action after the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( rule shows) S 
  1345. 2160 7888 P (that the result of the rule \() S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F (\)) S 50 J ( should be the material associated with the second input line.) S 
  1346. 2160 8328 P (All this means that if the user makes a mistake entering an input line, the parser prints out) S 
  1347. 2160 8568 P (an error message and accepts a second input line in place of the first.  This allows for an) S 
  1348. 2160 8808 P (interactive user to correct an input line that was incorrectly typed the first time.) S 
  1349. 2160 9248 P (Of course, this set-up will only work if the user doesn't make an error the second time the) S 
  1350. 2160 9488 P (line is typed too. If the next token he or she types is also invalid, the parser will discard the) S 
  1351. 2160 9728 P (token and decide that it's still gobbling up the original error.) S 
  1352. 2160 10548 P 0 12 F 8 12 F B (5.5) S 67 J (  The yyclearin Macro) S E 
  1353. 2160 11268 P 0 12 F 8 9 F (After) S 50 J ( an Error action, the parser will restore the lookahead symbol to the value it had at the) S 
  1354. 2160 11508 P (time the error was detected.  However, this is sometimes undesirable.) S 
  1355. 2160 11948 P (For example, your grammar may have a recognition action associated with the ) S 0 12 F 0 9 F B (error) S E 
  1356. 2160 12188 P 0 12 F 8 9 F (symbol) S 50 J ( and this may read through the next lot of input until it finds the next sure-to-be-) S 
  1357. 2160 12428 P (valid data.  If this happens, you certainly don't want the parser to pick up the old) S 
  1358. 2160 12668 P (lookahead symbol again once error recovery is finished.) S 
  1359. 2160 13108 P (If you want the parser to throw away the old lookahead symbol after an error, put) S 
  1360. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1361. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 30) S 0 12 F 
  1362. PE 
  1363. 3600 2148 P 0 9 F (yyclearin) S 108 J ( ;) S 
  1364. 2880 2588 P 0 12 F 8 9 F (in) S 50 J ( the recognition action associated with the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( symbol.  ) S 0 12 F 0 9 F ("yyclearin") S 0 12 F 8 9 F () S 50 J ( is a macro) S 
  1365. 2880 2828 P (that expands into code that discards the lookahead symbol.) S 
  1366. 2880 3648 P 0 12 F 8 12 F B (5.6) S 67 J (  The yyerror Function) S E 
  1367. 2880 4368 P 0 12 F 8 9 F (The) S 50 J ( first thing the parser does when it performs the Error action is to call a function named) S 
  1368. 2880 4608 P 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F (.) S 50 J (  This happens ) S 0 12 F 8 9 F I (before) S E 0 12 F 8 9 F () S 50 J ( the parser begins going down the state stack in search) S 
  1369. 2880 4848 P (of a state that can handle the ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( symbol.  ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( must be supplied by the user --) S 
  1370. 2880 5088 P (note that its name is in lower case.) S 
  1371. 2880 5528 P (The simplest ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( functions either abort the parsing job or just return so that the) S 
  1372. 2880 5768 P (parser can perform its standard error handling.) S 
  1373. 2880 6208 P (The ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( function is passed one argument: a character string describing the type) S 
  1374. 2880 6448 P (of error that just took place.  This string is almost always) S 
  1375. 3600 6868 P 0 12 F 0 9 F ("Syntax) S 108 J ( error") S 
  1376. 2880 7308 P 0 12 F 8 9 F (The) S 50 J ( only other argument strings that might be passed are) S 
  1377. 3600 7728 P 0 12 F 0 9 F ("Not) S 108 J ( enough space for parser stacks") S 
  1378. 3600 7948 P ("Parser stack overflow") S 
  1379. 2880 8388 P 0 12 F 8 9 F (which) S 50 J ( are used when the parser runs out of memory for the state stack.) S 
  1380. 2880 8828 P (Once ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( returns to ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (,) S 50 J ( the parser will proceed popping down the stack) S 
  1381. 2880 9068 P (in search of a state that can handle errors.) S 
  1382. 2880 9508 P (If another error is encountered soon after the first, ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( will ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( be called again.) S 
  1383. 2880 9748 P (The parser considers itself to be in a "potential error" situation until it finds three correct) S 
  1384. 2880 9988 P (tokens in a row.  This avoids the torrents of error messages that often occur as the parser) S 
  1385. 2880 10228 P (wades through input in search of some recognizable sequence.) S 
  1386. 2880 10668 P (Once the parser has found three correct tokens in a row, it leaves the "potential error") S 
  1387. 2880 10908 P (situation.  If a new error is found later on, ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( will be called again.) S 
  1388. 2880 12028 P 0 12 F 8 12 F I (5.6.1) S 67 J (  Changing yychar in yyerror) S E 
  1389. 2880 12748 P 0 12 F 8 9 F (The) S 50 J ( ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( function may change the value of ) S 0 12 F 0 9 F ("yychar") S 0 12 F 8 9 F () S 50 J ( \(the variable that indicates) S 
  1390. 2880 12988 P (the type of token just read by ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (\).) S 50 J (  If ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( does this, ) S 0 12 F 0 9 F ("yyparse") S 
  1391. 2880 13228 P 0 12 F 8 9 F (immediately) S 50 J ( gets rid of the error condition and tries to make a shift or reduce using the) S 
  1392. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1393. 2880 14800 P 0 12 F 24 10 F (31) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1394. PE 
  1395. 2160 1968 P 8 9 F (new) S 50 J ( ) S 0 12 F 0 9 F ("yychar") S 0 12 F 8 9 F () S 50 J ( token.  If there is a valid action that can be taken, ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( will) S 
  1396. 2160 2208 P (proceed as if the error never happened.) S 
  1397. 2160 2648 P (This behavior can help you deal with at least two kinds of unusual situations:) S 
  1398. 2160 3088 P (\(a\)          When ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( is attempting to correct a problem by supplying the correct) S 
  1399. 2880 3328 P (input.  For example, it may be possible to determine what input should have been) S 
  1400. 2880 3568 P (received; the classic example is a compiler which can figure out that a particular) S 
  1401. 2880 3808 P (statement should have ended in a semicolon.  In this case, ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( can) S 
  1402. 2880 4048 P (supply the missing semicolon by assigning an appropriate value to ) S 0 12 F 0 9 F ("yychar") S 0 12 F 8 9 F (.) S 50 J (  If) S 
  1403. 2880 4288 P 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( guessed correctly, action can proceed as if the problem didn't occur.) S 
  1404. 2160 4728 P (\(b\)          When a particular token can be interpreted in different ways in different contexts.) S 
  1405. 2880 4968 P (For example, suppose that ) S 0 12 F 0 9 F (X) S 0 12 F 8 9 F () S 50 J ( can be a keyword in some contexts and a variable) S 
  1406. 2880 5208 P (name in others.  You can write ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( so that it always interprets ) S 0 12 F 0 9 F (X) S 0 12 F 8 9 F () S 50 J ( as a) S 
  1407. 2880 5448 P (keyword.  If ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( is invoked because that keyword is invalid in a particular) S 
  1408. 2880 5688 P (context, ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( can change ) S 0 12 F 0 9 F ("yychar") S 0 12 F 8 9 F () S 50 J ( and see if the input is valid when ) S 0 12 F 0 9 F (X) S 
  1409. 2880 5928 P 0 12 F 8 9 F (is) S 50 J ( interpreted as a variable name.) S 
  1410. 2160 6368 P (If ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( changes ) S 0 12 F 0 9 F ("yychar") S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( may have to inform ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( of the) S 
  1411. 2160 6608 P (situation so that ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( can return the proper input token the next time it is called.) S 
  1412. 2160 7428 P 0 12 F 8 12 F B (5.7) S 67 J (  The yyerrflag Variable) S E 
  1413. 2160 8148 P 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( is an external integer variable whose value must be ) S 0 12 F 0 9 F (0) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (1) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (2) S 0 12 F 8 9 F (,) S 50 J ( or ) S 0 12 F 0 9 F (3) S 0 12 F 8 9 F (.) S 
  1414. 2160 8388 P 0 12 F 0 9 F (YYABORT) S 0 12 F 8 9 F () S 50 J ( \(described in a later section\) is called if ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( does not have one of) S 
  1415. 2160 8628 P (these values.) S 
  1416. 2160 9068 P (As we mentioned earlier, ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( doesn't leave its error state until three consecutive) S 
  1417. 2160 9308 P (valid tokens have been read.  ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( is used in this process.) S 
  1418. 2160 9748 P (If ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( is zero, ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( will be invoked the next time an error is) S 
  1419. 2160 9988 P (encountered.  As soon as ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( is invoked, it sets ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( to ) S 0 12 F 0 9 F (3) S 0 12 F 8 9 F (.) S 50 J (  Each time a) S 
  1420. 2160 10228 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( shifts on a valid token, ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( is decremented, until it gets to zero.  At) S 
  1421. 2160 10468 P (this point, ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( leaves its error state; if a new error occurs, ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( will be) S 
  1422. 2160 10708 P (called again.) S 
  1423. 2160 11148 P (There are two ways in which actions can use ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F (.) S 50 J (  First, they can check the) S 
  1424. 2160 11388 P (variable to see if there has been a recent error.  For example, if an action encounters a) S 
  1425. 2160 11628 P (semantic error, it can check ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( to see if it is non-zero \(meaning that there has) S 
  1426. 2160 11868 P (been a recent syntax error\).  If ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( is non-zero, the semantic error is almost) S 
  1427. 2160 12108 P (certainly a result of the previous syntax error.  Using this information, the action may) S 
  1428. 2160 12348 P (choose to modify or suppress the semantic error message.) S 
  1429. 2160 12788 P (Second, actions can set ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( to a value if they want to prevent calls to) S 
  1430. 2160 13028 P 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F (.) S 50 J (  As long as ) S 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( is non-zero, ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( will not be called.  This) S 
  1431. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1432. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 32) S 0 12 F 
  1433. PE 
  1434. 2880 1968 P 8 9 F (may) S 50 J ( be useful if an action is smart enough to realize that it is still recovering from a) S 
  1435. 2880 2208 P (previous error and ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( should not be called again for a while.) S 
  1436. 2880 3028 P 0 12 F 8 12 F B (5.8) S 67 J (  The yyerrok Macro) S E 
  1437. 2880 3748 P 0 12 F 8 9 F (In) S 50 J ( some situations, you may want ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( to be called even if the parser hasn't seen) S 
  1438. 2880 3988 P (three correct tokens since the last error.) S 
  1439. 2880 4428 P (For example, suppose you have a parser for a line by line desk calculator.  A line of input) S 
  1440. 2880 4668 P (contains errors, so ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( is called.  ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( prints an error message to the) S 
  1441. 2880 4908 P (user, throws away the rest of the line, and prompts for new input.  If the next line contains) S 
  1442. 2880 5148 P (an error in the first three tokens, the parser will normally start discarding input ) S 0 12 F 8 9 F I (without) S E 
  1443. 2880 5388 P 0 12 F 8 9 F (calling) S 50 J ( ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( again.  This means that ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( doesn't print an error message) S 
  1444. 2880 5628 P (for the user, even though the input line is wrong.) S 
  1445. 2880 6068 P (To avoid this problem, you can explicitly tell the parser to leave its "potential error" state,) S 
  1446. 2880 6308 P (even if it hasn't yet seen three correct tokens.  Simply say) S 
  1447. 3600 6728 P 0 12 F 0 9 F (yyerrok) S 108 J ( ;) S 
  1448. 2880 7168 P 0 12 F 8 9 F (as) S 50 J ( part of the error recognition action.  For example, you might have the rule) S 
  1449. 3600 7588 P 0 12 F 0 9 F (expr) S 108 J ( : error) S 
  1450. 3600 7808 P (     {) S 
  1451. 3600 8028 P (         yyerrok;) S 
  1452. 3600 8248 P (         printf\("Please re-enter line.\\n"\);) S 
  1453. 3600 8468 P (         yyclearin;) S 
  1454. 3600 8688 P (     }) S 
  1455. 2880 9128 P ("yyerrok") S 0 12 F 8 9 F () S 50 J ( is a macro that is expanded into code that takes the parser out of its) S 
  1456. 2880 9368 P ("potential error" state and lets it start fresh.  More precisely, ) S 0 12 F 0 9 F ("yyerrok") S 0 12 F 8 9 F () S 50 J ( sets) S 
  1457. 2880 9608 P 0 12 F 0 9 F ("yyerrflag") S 0 12 F 8 9 F () S 50 J ( to zero.) S 
  1458. 2880 10428 P 0 12 F 8 12 F B (5.9) S 67 J (  Other Error Support Routines) S E 
  1459. 2880 11148 P 0 12 F 0 9 F (YYABORT) S 0 12 F 8 9 F () S 50 J ( halts ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( in midstream and immediately returns a ) S 0 12 F 0 9 F (1) S 0 12 F 8 9 F (.) S 50 J (  To the function) S 
  1460. 2880 11388 P (that called ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (,) S 50 J ( this means that ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( failed for some reason.) S 
  1461. 2880 11828 P 0 12 F 0 9 F (YYACCEPT) S 0 12 F 8 9 F () S 50 J ( halts the parser in midstream and returns a ) S 0 12 F 0 9 F (0) S 0 12 F 8 9 F (.) S 50 J (  To the function that called) S 
  1462. 2880 12068 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (,) S 50 J ( this means that ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( terminated successfully, even if the entire input) S 
  1463. 2880 12308 P (has not yet been scanned.) S 
  1464. 2880 12748 P 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( \(note that this is upper case\) is a macro that "fakes" an error.  When ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( is) S 
  1465. 2880 12988 P (encountered in the code, the parser will react as if it just saw an error and will go about) S 
  1466. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1467. 2880 14800 P 0 12 F 24 10 F (33) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1468. PE 
  1469. 2160 1968 P 8 9 F (recovering) S 50 J ( from the error.  In Chapter 9, we will give an example of how ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( can be) S 
  1470. 2160 2208 P (useful.) S 
  1471. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1472. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 34) S 0 12 F 
  1473. PE 
  1474. 7660 2448 P 8 18 F B (6.) S 100 J ( YAY Output) S E 
  1475. 2880 4048 P 0 12 F 8 9 F (YAY) S 50 J ( can produce several output files.  Options on the YAY command line dictate which) S 
  1476. 2880 4288 P (files are actually generated.) S 
  1477. 2880 4728 P (The most important output file is the one containing source code that can be compiled into) S 
  1478. 2880 4968 P (the actual parser.  The name of this file is specified with the ) S 0 12 F 0 9 F (Parser=file) S 0 12 F 8 9 F () S 50 J ( command line) S 
  1479. 2880 5208 P (option.) S 
  1480. 2880 5648 P (Another possible output file contains manifest definitions.  The name of this file is specified) S 
  1481. 2880 5888 P (with ) S 0 12 F 0 9 F (Header=file) S 0 12 F 8 9 F () S 50 J ( on the command line.  This file is a distillation of the declarations) S 
  1482. 2880 6128 P (section of the YAY input.  For example, all the ) S 0 12 F 0 9 F (%token) S 0 12 F 8 9 F () S 50 J ( directives are restated in terms of) S 
  1483. 2880 6368 P (manifest definitions.) S 
  1484. 3600 6788 P 0 12 F 0 9 F (%token) S 108 J ( IF) S 
  1485. 2880 7228 P 0 12 F 8 9 F (would) S 50 J ( appear as) S 
  1486. 3600 7648 P 0 12 F 0 9 F (#define) S 108 J ( IF 257) S 
  1487. 2880 8088 P 0 12 F 8 9 F (in) S 50 J ( the C version of the manifests \(assuming that ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( was the first token in the declarations) S 
  1488. 2880 8328 P (section\).  By including this file with) S 
  1489. 3600 8748 P 0 12 F 0 9 F (#include) S 108 J ( "filename") S 
  1490. 2880 9188 P 0 12 F 8 9 F (separately) S 50 J ( compiled modules can make use of all the pertinent definitions in the YAY) S 
  1491. 2880 9428 P (input.) S 
  1492. 2880 9868 P (The third output file that YAY can produce is called the Parser Description.  The name of) S 
  1493. 2880 10108 P (the file is specified with ) S 0 12 F 0 9 F (Description=file) S 0 12 F 8 9 F () S 50 J ( on the command line.  The Parser) S 
  1494. 2880 10348 P (Description is split into three sections:) S 
  1495. 2880 10788 P (\(a\)          a summary of the grammar rules;) S 
  1496. 2880 11228 P (\(b\)          a list of state descriptions;) S 
  1497. 2880 11668 P (\(c\)) S 510 J ( a) S 50 J ( list of statistics for the parser generated by YAY.) S 
  1498. 2880 12108 P (In the sections that follow, we will show what the Parser Description looks like for the) S 
  1499. 2880 12348 P (following grammar:) S 
  1500. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1501. 2880 14800 P 0 12 F 24 10 F (35) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1502. PE 
  1503. 2880 1948 P 0 9 F (%token) S 108 J ( IF ELSE A) S 
  1504. 2880 2168 P (%%) S 
  1505. 2880 2388 P (stmt : IF stmt ELSE stmt) S 
  1506. 2880 2608 P (     | IF stmt) S 
  1507. 2880 2828 P (     | A) S 
  1508. 2880 3048 P (     ;) S 
  1509. 2160 3868 P 0 12 F 8 12 F B (6.1) S 67 J (  Rules Summary) S E 
  1510. 2160 4588 P 0 12 F 8 9 F (The) S 50 J ( rules summary section of the Parser Description begins with the command line used) S 
  1511. 2160 4828 P (to invoke YAY.  This is intended to serve as a "heading" for the output material.  We'll use) S 
  1512. 2160 5068 P (the command line) S 
  1513. 2880 5488 P 0 12 F 0 9 F (yay) S 108 J ( infile.y description=out +verbose) S 
  1514. 2160 5928 P 0 12 F 8 9 F (YAY) S 50 J ( input is in the file ) S 0 12 F 0 9 F (infile.y) S 0 12 F 8 9 F () S 50 J ( and output is written to the file ) S 0 12 F 0 9 F (out) S 0 12 F 8 9 F (.) S 50 J (  We have specified) S 
  1515. 2160 6168 P (the ) S 0 12 F 0 9 F (+Verbose) S 0 12 F 8 9 F () S 50 J ( option because this provides the largest amount of output.  See Appendix) S 
  1516. 2160 6408 P (C for more information on the YAY command line.) S 
  1517. 2160 6848 P (Next comes a summary of the grammar rules.  In our example, we will have) S 
  1518. 2880 7268 P 0 12 F 0 9 F (Rules:) S 
  1519. 2880 7488 P () S 108 J (   \(0\)  $accept:  stmt $end) S 
  1520. 2880 7708 P (   \(1\)  stmt:     IF stmt ELSE stmt) S 
  1521. 2880 7928 P (   \(2\)  stmt:     IF stmt) S 
  1522. 2880 8148 P (   \(3\)  stmt:     A) S 
  1523. 2160 8588 P 0 12 F 8 9 F (The) S 50 J ( 0th rule will always be the definition for a symbol named ) S 0 12 F 0 9 F ($accept) S 0 12 F 8 9 F (.) S 50 J (  This describes) S 
  1524. 2160 8828 P (what a complete input looks like: the Start symbol followed by the end marker.  Other rules) S 
  1525. 2160 9068 P (are those given in the grammar.) S 
  1526. 2160 9508 P (YAY puts a formfeed character on the line after the last grammar rule so that the next part) S 
  1527. 2160 9748 P (of the Parser Description starts on a new page.) S 
  1528. 2160 10568 P 0 12 F 8 12 F B (6.2) S 67 J (  State Descriptions) S E 
  1529. 2160 11288 P 0 12 F 8 9 F (The) S 50 J ( Parser Description output contains complete descriptions of every possible state.  For) S 
  1530. 2160 11528 P (example, here is the description of one state from our sample grammar.) S 
  1531. 2880 11948 P 0 12 F 0 9 F (State) S 108 J ( 2) S 
  1532. 2880 12168 P (    stmt :  IF.stmt ELSE stmt) S 
  1533. 2880 12388 P (    stmt :  IF.stmt) S 
  1534. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1535. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 36) S 0 12 F 
  1536. PE 
  1537. 3600 1948 P 0 9 F () S 108 J (    IF   shift 2) S 
  1538. 3600 2168 P (    A    shift 1) S 
  1539. 3600 2388 P (    .    error) S 
  1540. 3600 2808 P (    stmt     goto 4) S 
  1541. 2880 3248 P 0 12 F 8 9 F (By) S 50 J ( now, this sort of diagram should be familiar to you.  The numbers after the word) S 
  1542. 2880 3488 P 0 12 F 0 9 F ("shift") S 0 12 F 8 9 F () S 50 J ( indicate the state to which the parser will Shift if the lookahead symbol happens) S 
  1543. 2880 3728 P (to be ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (A) S 0 12 F 8 9 F (.) S 50 J (  If the lookahead symbol is anything else, the parser raises the error) S 
  1544. 2880 3968 P (condition and starts error recovery.) S 
  1545. 2880 4408 P (If the parser pops back to state 2 by means of a Reduce Action, the lookahead symbol will) S 
  1546. 2880 4648 P (now be ) S 0 12 F 0 9 F ("stmt") S 0 12 F 8 9 F () S 50 J ( and the parser will Goto state 4.) S 
  1547. 2880 5088 P (As another example of a state, here is State 1.) S 
  1548. 3600 5508 P 0 12 F 0 9 F (State) S 108 J ( 1) S 
  1549. 3600 5728 P (    stmt :  A.  \(3\)) S 
  1550. 3600 6148 P (    .     reduce \(3\)) S 
  1551. 2880 6588 P 0 12 F 8 9 F (This) S 50 J ( is the state that is entered when an ) S 0 12 F 0 9 F (A) S 0 12 F 8 9 F () S 50 J ( token has been found.  The \(3\) on the end of) S 
  1552. 2880 6828 P (the first line is a ) S 0 12 F 8 9 F I (rule) S 50 J ( number) S E 0 12 F 8 9 F (.) S 50 J (  It indicates that this particular line sums up the whole of the) S 
  1553. 2880 7068 P (third grammar rule that was specified in the YAY input.  The line) S 
  1554. 3600 7488 P 0 12 F 0 9 F () S 108 J (    .    reduce \(3\)) S 
  1555. 2880 7928 P 0 12 F 8 9 F (indicates) S 50 J ( that no matter what token comes next, we can reduce this particular input using) S 
  1556. 2880 8168 P (grammar rule \(3\) and say that we have successfully collected a valid ) S 0 12 F 0 9 F ("stmt") S 0 12 F 8 9 F (.) S 50 J (  The parser) S 
  1557. 2880 8408 P (will perform a reduction by popping the top state off the stack and setting the lookahead) S 
  1558. 2880 8648 P (symbol to ) S 0 12 F 0 9 F ("stmt") S 0 12 F 8 9 F (.) S 
  1559. 2880 9088 P (It) S 50 J ( is important to distinguish between) S 
  1560. 3600 9508 P 0 12 F 0 9 F () S 108 J (  A  shift 1) S 
  1561. 2880 9948 P 0 12 F 8 9 F (in) S 50 J ( State 2 and) S 
  1562. 3600 10368 P 0 12 F 0 9 F () S 108 J (  .  reduce \(3\)) S 
  1563. 2880 10808 P 0 12 F 8 9 F (in) S 50 J ( State 1.  In the Shift instruction, the number that follows is the number of a ) S 0 12 F 8 9 F I (state) S E 0 12 F 8 9 F (.) S 50 J (  In the) S 
  1564. 2880 11048 P (Reduce instruction, the number that follows is the number of a ) S 0 12 F 8 9 F I (grammar) S 50 J ( rule) S E 0 12 F 8 9 F () S 50 J ( \(using the) S 
  1565. 2880 11288 P (numbers given to the grammar rules in the first part of the Parser Description\).  The) S 
  1566. 2880 11528 P (Parser Description always encloses rule numbers in parentheses, and leaves state) S 
  1567. 2880 11768 P (numbers as they are.) S 
  1568. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1569. 2880 14800 P 0 12 F 24 10 F (37) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1570. PE 
  1571. 2160 1968 P 8 9 F (The) S 50 J ( complete state descriptions for the grammar are given below.) S 
  1572. 2880 2388 P 0 12 F 0 9 F (State) S 108 J ( 0) S 
  1573. 2880 2608 P (         $accept: .stmt $end) S 
  1574. 2880 3028 P (    IF    shift 2) S 
  1575. 2880 3248 P (    A     shift 1) S 
  1576. 2880 3468 P (    .     error) S 
  1577. 2880 3888 P (    stmt    goto 3) S 
  1578. 2880 4308 P (State 1) S 
  1579. 2880 4528 P (    \(3\)  stmt:     A.) S 
  1580. 2880 4948 P (    .     reduce \(3\)) S 
  1581. 2880 5368 P (State 2) S 
  1582. 2880 5588 P (         stmt:     IF.stmt ELSE stmt) S 
  1583. 2880 5808 P (         stmt:     IF.stmt) S 
  1584. 2880 6228 P (    IF    shift 2) S 
  1585. 2880 6448 P (    A     shift 1) S 
  1586. 2880 6668 P (    .     error) S 
  1587. 2880 7088 P (    stmt    goto 4) S 
  1588. 2880 7508 P (State 3) S 
  1589. 2880 7728 P (         $accept:  stmt.$end) S 
  1590. 2880 8148 P (    $end  accept) S 
  1591. 2880 8368 P (    .     error) S 
  1592. 2880 8788 P (State 4) S 
  1593. 2880 9008 P (         stmt:     IF stmt.ELSE stmt) S 
  1594. 2880 9228 P (    \(2\)  stmt:     IF stmt. [ $end ELSE ]) S 
  1595. 2880 9648 P (  Shift/reduce conflict \(5,2\) on ELSE) S 
  1596. 2880 9868 P (    ELSE  shift 5) S 
  1597. 2880 10088 P (    .     reduce \(2\)) S 
  1598. 2880 10508 P (State 5) S 
  1599. 2880 10728 P (         stmt:     IF stmt ELSE.stmt) S 
  1600. 2880 11148 P (    IF    shift 2) S 
  1601. 2880 11368 P (    A     shift 1) S 
  1602. 2880 11588 P (    .     error) S 
  1603. 2880 12008 P (    stmt    goto 6) S 
  1604. 2880 12428 P (State 6) S 
  1605. 2880 12648 P (    \(1\)  stmt:     IF stmt ELSE stmt.) S 
  1606. 2880 13068 P (    .     reduce \(1\)) S 
  1607. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1608. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 38) S 0 12 F 
  1609. PE 
  1610. 2880 2168 P 8 9 F (The) S 50 J ( parser always begins in State 0, i.e. in a state where no input has been read yet.  An) S 
  1611. 2880 2408 P (acceptable input is a ) S 0 12 F 0 9 F ("stmt") S 0 12 F 8 9 F () S 50 J ( followed by the end marker.  When a ) S 0 12 F 0 9 F ("stmt") S 0 12 F 8 9 F () S 50 J ( has been) S 
  1612. 2880 2648 P (collected, the parser goes to State 3.  In State 3, the required end marker ) S 0 12 F 0 9 F ($end) S 0 12 F 8 9 F () S 50 J ( indicates) S 
  1613. 2880 2888 P (that the input should be accepted.  If anything else is found, it is excess input and means) S 
  1614. 2880 3128 P (an error.) S 
  1615. 2880 3568 P (In State 4, the rule labelled \(2\) has) S 
  1616. 3600 3988 P 0 12 F 0 9 F ([) S 108 J ( $end ELSE ]) S 
  1617. 2880 4428 P 0 12 F 8 9 F (on) S 50 J ( the end.  This just means that the parser expects to see one of these two tokens next.) S 
  1618. 2880 5248 P 0 12 F 8 12 F B (6.3) S 67 J (  Conflict Summary) S E 
  1619. 2880 5968 P 0 12 F 8 9 F (As) S 50 J ( noted in the sample output, there is a shift/reduce conflict in State 4.  If an ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F () S 50 J ( is) S 
  1620. 2880 6208 P (encountered while the parser is in this state, the parser doesn't know whether to shift \(into) S 
  1621. 2880 6448 P (State 5\) or to reduce using rule \(2\).  Thus YAY prints the message) S 
  1622. 3600 6868 P 0 12 F 0 9 F (Shift/reduce) S 108 J ( conflict \(5,2\) on ELSE) S 
  1623. 2880 7308 P 0 12 F 8 9 F (After) S 50 J ( the state descriptions, YAY prints a summary of all such conflicts.  With our sample) S 
  1624. 2880 7548 P (grammar, the output contains) S 
  1625. 3600 7968 P 0 12 F 0 9 F (Conflicts:) S 
  1626. 3600 8188 P () S 108 J (    State  Token        Action) S 
  1627. 3600 8408 P (        4  ELSE         shift 5) S 
  1628. 3600 8628 P (        4  ELSE         reduce \(2\)) S 
  1629. 2880 9068 P 0 12 F 8 9 F (Each) S 50 J ( line in this summary gives the number of the state in which the conflict occurs, the) S 
  1630. 2880 9308 P (token\(s\) that cause the conflict, and the conflicting actions.) S 
  1631. 2880 10128 P 0 12 F 8 12 F B (6.4) S 67 J (  Parser Statistics) S E 
  1632. 2880 10848 P 0 12 F 8 9 F (The) S 50 J ( last section of the Parser Description is a set of statistics summarizing YAY's work.) S 
  1633. 2880 11088 P (Here are the stats we got when we ran our sample grammar through YAY.) S 
  1634. 2880 11508 P 0 12 F 0 10 F (4) S 120 J ( rules, 5 tokens, 2 variables, 7 states) S 
  1635. 2880 11728 P (Memory:  max = 8K) S 
  1636. 2880 11948 P (States: 3 wasted, 4 resets) S 
  1637. 2880 12168 P (Items:  18, 0 kernel, \(2,0\) per state, maxival=16 \(1 w/s\)) S 
  1638. 2880 12388 P (Lalr:  1 calls, 2 recurs, \(0 trans, 12 epred\)) S 
  1639. 2880 12608 P (Actions:  0 entries, gotos: 0 entries) S 
  1640. 2880 12828 P (Exceptions: 1 states, 4 entries) S 
  1641. 2880 13048 P (Simple state elim: 0%, Error default elim: 33%) S 
  1642. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1643. 2880 14800 P 0 12 F 24 10 F (39) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1644. PE 
  1645. 2160 1948 P 0 10 F (Optimizer:) S 120 J ( in 0, out 0) S 
  1646. 2160 2168 P (Size of tables:  24 bytes) S 
  1647. 2160 2388 P (2 seconds, final mem = 4) S 
  1648. 2160 2608 P (1 shift/reduce conflict) S 
  1649. 2160 3048 P 0 12 F 8 9 F (Some) S 50 J ( of these values are machine independent \(e.g. the number of rules\), others are) S 
  1650. 2160 3288 P (machine dependent \(e.g. the amount of memory used\), and some can be different every) S 
  1651. 2160 3528 P (time you run the job \(e.g. time elapsed while YAY was running\).) S 
  1652. 2160 3968 P (The statistic lines are described below.  Many of these will be of no interest to the normal) S 
  1653. 2160 4208 P (user; YAY only generates them for the use of those maintaining the YAY software.  A) S 
  1654. 2160 4448 P (number of the statistics refer to shift/reduce or reduce/reduce conflicts.  We will discuss) S 
  1655. 2160 4688 P (these in a later chapter.) S 
  1656. 2160 5128 P 0 12 F 0 9 F (4) S 108 J ( rules, 5 tokens, 2 variables, 7 states) S 
  1657. 2880 5368 P 0 12 F 8 9 F (The) S 50 J ( four rules are the grammar rules given in the first part of the Parser) S 
  1658. 2880 5608 P (Description.  The five tokens are ) S 0 12 F 0 9 F (A) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ($end) S 0 12 F 8 9 F (,) S 50 J ( and ) S 0 12 F 0 9 F (error) S 0 12 F 8 9 F () S 50 J ( \(which is always) S 
  1659. 2880 5848 P (defined, even if we don't use it in this grammar\).  The two variables are the non-) S 
  1660. 2880 6088 P (terminal symbols, ) S 0 12 F 0 9 F ("stmt") S 0 12 F 8 9 F () S 50 J ( and the special ) S 0 12 F 0 9 F ($accept) S 0 12 F 8 9 F (.) S 50 J (  The seven states are) S 
  1661. 2880 6328 P (states 0 to 6.) S 
  1662. 2160 6768 P 0 12 F 0 9 F (Memory:) S 108 J (  max = 8K) S 
  1663. 2880 7008 P 0 12 F 8 9 F (This) S 50 J ( gives the maximum amount of dynamic memory that YAY required while) S 
  1664. 2880 7248 P (producing the parser.  This line may also have a "success rate" that tells how) S 
  1665. 2880 7488 P (often YAY succeeded in having enough memory to handle a situation and how) S 
  1666. 2880 7728 P (often it had to ask for more memory.) S 
  1667. 2160 8168 P 0 12 F 0 9 F (States:) S 108 J ( 3 wasted, 4 resets) S 
  1668. 2880 8408 P 0 12 F 8 9 F (The) S 50 J ( algorithm that constructs states from the grammar rules makes a guess at) S 
  1669. 2880 8648 P (the number of states it will need, very early on in the YAY process.  If this guess) S 
  1670. 2880 8888 P (is too high, the excess states are said to be "wasted".) S 
  1671. 2880 9368 P (When creating states from the various grammar rules, it is sometimes found that) S 
  1672. 2880 9608 P (a state from one rule duplicates the state from another \(for example, there were) S 
  1673. 2880 9848 P (two rules that started with ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( in our example above\).  In the final parsing tables,) S 
  1674. 2880 10088 P (such duplicate states are merged together into a single state.  The number of) S 
  1675. 2880 10328 P ("resets" is the number of duplicate states formed, then merged.) S 
  1676. 2160 10768 P 0 12 F 0 9 F (Items:) S 108 J ( 18, 0 kernel, \(2,0\) per state, maxival=16 \(1 w/s\)) S 
  1677. 2880 11008 P 0 12 F 8 9 F (A) S 50 J ( state is made of items, and the kernel items are an important subset of these:) S 
  1678. 2880 11248 P (the size of the resulting parsing tables and the running time for YAY are) S 
  1679. 2880 11488 P (proportional to the number of items and kernel items.  The rest of the statistics in) S 
  1680. 2880 11728 P (this line are not of interest to normal users.) S 
  1681. 2160 12168 P 0 12 F 0 9 F (Lalr:) S 108 J ( 1 call, 2 recurs, \(0 trans, 12 epred\)) S 
  1682. 2880 12408 P 0 12 F 8 9 F (This) S 50 J ( gives the number of calls and recursive calls to the conflict resolution) S 
  1683. 2880 12648 P (routine.  The parenthesized figures are related to the same process.  In some) S 
  1684. 2880 12888 P (ways, this is a measure of the complexity of the grammar being parsed.  This line) S 
  1685. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1686. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 40) S 0 12 F 
  1687. PE 
  1688. 3600 1968 P 8 9 F (will) S 50 J ( not appear if there are no reduce/reduce or shift/reduce conflicts in your) S 
  1689. 3600 2208 P (grammar.) S 
  1690. 2880 2648 P 0 12 F 0 9 F (Actions:) S 108 J ( 0 entries, gotos: 0 entries) S 
  1691. 3600 2888 P 0 12 F 8 9 F (This) S 50 J ( gives the number of entries in the tables ) S 0 12 F 0 9 F ("yyact") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("yygo") S 0 12 F 8 9 F (.) S 50 J (  ) S 0 12 F 0 9 F ("yyact") S 
  1692. 3600 3128 P 0 12 F 8 9 F (keeps) S 50 J ( track of the possible Shifts that a program may make and ) S 0 12 F 0 9 F ("yygo") S 0 12 F 8 9 F () S 50 J ( keeps) S 
  1693. 3600 3368 P (track of the "gotos" that take place at the end of states.) S 
  1694. 2880 3808 P 0 12 F 0 9 F (Exceptions:) S 108 J ( 1 states, 4 entries) S 
  1695. 3600 4048 P 0 12 F 8 9 F (This) S 50 J ( gives the number of entries in the table ) S 0 12 F 0 9 F ("yydef") S 0 12 F 8 9 F (,) S 50 J ( yet another table used in) S 
  1696. 3600 4288 P (YAY.  ) S 0 12 F 0 9 F ("yydef") S 0 12 F 8 9 F () S 50 J ( keeps track of the possible Reduce, Accept, and Error actions) S 
  1697. 3600 4528 P (that a program may make.) S 
  1698. 2880 4968 P 0 12 F 0 9 F (Simple) S 108 J ( state elim: 0%, Error default elim: 33%) S 
  1699. 3600 5208 P 0 12 F 8 9 F (The) S 50 J ( percentage figures indicate how much table space could be saved through) S 
  1700. 3600 5448 P (various optimization processes.  The better written your grammar, the greater the) S 
  1701. 3600 5688 P (percentage of space that can be saved.  Therefore, high percentages here are an) S 
  1702. 3600 5928 P (indication of a well-written grammar.) S 
  1703. 2880 6368 P 0 12 F 0 9 F (Optimizer:) S 108 J ( in 0, out 0) S 
  1704. 3600 6608 P 0 12 F 8 9 F (More) S 50 J ( optimization statistics: not of interest to normal YAY users.) S 
  1705. 2880 7048 P 0 12 F 0 9 F (Size) S 108 J ( of tables: 24 bytes) S 
  1706. 3600 7288 P 0 12 F 8 9 F (The) S 50 J ( size of the tables generated to represent the parsing rules.  This size is given) S 
  1707. 3600 7528 P (in bytes on the host machine, so it will be inaccurate if a cross-compiler is being) S 
  1708. 3600 7768 P (used on the eventual source code output.  The size does not include stack space) S 
  1709. 3600 8008 P (used by ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( or debug tables obtained by defining ) S 0 12 F 0 9 F (YYDEBUG) S 0 12 F 8 9 F (.) S 
  1710. 2880 8448 P 0 12 F 0 9 F (2) S 108 J ( seconds, final mem = 4) S 
  1711. 3600 8688 P 0 12 F 8 9 F (Total) S 50 J ( real time that YAY used to produce the parser, and the final dynamic) S 
  1712. 3600 8928 P (memory of the parser \(in K bytes\).) S 
  1713. 2880 9368 P 0 12 F 0 9 F (1) S 108 J ( shift/reduce conflict) S 
  1714. 3600 9608 P 0 12 F 8 9 F (Number) S 50 J ( of conflicts in the grammar.) S 
  1715. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1716. 2880 14800 P 0 12 F 24 10 F (41) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1717. PE 
  1718. 7920 2448 P 8 18 F B (7.) S 100 J ( Types) S E 
  1719. 2160 4048 P 0 12 F 8 9 F (Earlier) S 50 J ( we mentioned that ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F () S 50 J ( is ) S 0 12 F 0 9 F B (int) S E 0 12 F 8 9 F () S 50 J ( by default, as are ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ($1) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ($2) S 0 12 F 8 9 F (,) S 50 J ( etc.  If you want) S 
  1720. 2160 4288 P (these to have different types, you may redeclare them in the declarations section of the) S 
  1721. 2160 4528 P (YAY input.  This is done with a statement of the form) S 
  1722. 2880 4948 P 0 12 F 0 9 F (%union) S 108 J ( {) S 
  1723. 2880 5168 P (     /* possible types for "yylval" and) S 
  1724. 2880 5388 P (      * $$, $1, $2, etc.  */) S 
  1725. 2880 5608 P (}) S 
  1726. 2160 6048 P 0 12 F 8 9 F (For) S 50 J ( example, suppose "yylval" can be either integer or floating point.  You might write) S 
  1727. 2880 6468 P 0 12 F 0 9 F (%union) S 108 J ( {) S 
  1728. 2880 6688 P (     int intval;) S 
  1729. 2880 6908 P (     float realval;) S 
  1730. 2880 7128 P (}) S 
  1731. 2160 7568 P 0 12 F 8 9 F (in) S 50 J ( the declarations section of the YAY input.  YAY converts the ) S 0 12 F 0 9 F (%union) S 0 12 F 8 9 F () S 50 J ( statement into the) S 
  1732. 2160 7808 P (following C source.) S 
  1733. 2880 8228 P 0 12 F 0 9 F (typedef) S 108 J ( union {) S 
  1734. 2880 8448 P (    int intval;) S 
  1735. 2880 8668 P (    float realval;) S 
  1736. 2880 8888 P (} YYSTYPE;) S 
  1737. 2160 9328 P ("yylval") S 0 12 F 8 9 F () S 50 J ( is always declared to have type ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F (.) S 50 J (  If no ) S 0 12 F 0 9 F (%union) S 0 12 F 8 9 F () S 50 J ( statement is given in) S 
  1738. 2160 9568 P (the YAY input, it will use) S 
  1739. 2880 9988 P 0 12 F 0 9 F (#define) S 108 J ( YYSTYPE int) S 
  1740. 2160 10428 P 0 12 F 8 9 F (Once) S 50 J ( ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F () S 50 J ( has been defined as a union, you may specify a particular interpretation of) S 
  1741. 2160 10668 P (the union by including a statement of the form) S 
  1742. 2880 11088 P 0 12 F 0 9 F (%type) S 108 J ( <interpretation> SYMBOL) S 
  1743. 2160 11528 P 0 12 F 8 9 F (in) S 50 J ( the declarations section of the YAY input.  The "interpretation" enclosed in the angle) S 
  1744. 2160 11768 P (brackets is the name of the interpretation of the union variable that you want to use.  The) S 
  1745. 2160 12008 P 0 12 F 0 9 F (SYMBOL) S 0 12 F 8 9 F () S 50 J ( name is the name of a non-terminal symbol defined in the grammar rules.  For) S 
  1746. 2160 12248 P (example, you might write) S 
  1747. 2880 12668 P 0 12 F 0 9 F (%type) S 108 J ( <intval> intexp) S 
  1748. 2880 12888 P (%type <realval> realexp) S 
  1749. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1750. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 42) S 0 12 F 
  1751. PE 
  1752. 2880 1968 P 8 9 F (to) S 50 J ( indicate that an integer expression has an integer value and a real expression has a) S 
  1753. 2880 2208 P (floating point value.) S 
  1754. 2880 2648 P (Tokens may also be declared to have types.  This is done in the ) S 0 12 F 0 9 F (%token) S 0 12 F 8 9 F () S 50 J ( statement in the) S 
  1755. 2880 2888 P (declaration section, and again shows the union interpretation in angle brackets, e.g.) S 
  1756. 3600 3308 P 0 12 F 0 9 F (%token) S 108 J ( <realval> floatnum) S 
  1757. 2880 3748 P 0 12 F 8 9 F (If) S 50 J ( you use types in your YAY input, YAY will enforce compatibility of types in all) S 
  1758. 2880 3988 P (expressions.  For example, if you write) S 
  1759. 3600 4408 P 0 12 F 0 9 F ($$) S 108 J ( = $2) S 
  1760. 2880 4848 P 0 12 F 8 9 F (in) S 50 J ( an action, YAY will demand that the two corresponding tokens have the same type;) S 
  1761. 2880 5088 P (otherwise, the assignment will be marked as invalid.  The reason for this is that YAY must) S 
  1762. 2880 5328 P (always know what interpretation of the union is being used in order to generate correct) S 
  1763. 2880 5568 P (code.) S 
  1764. 2880 6388 P 0 12 F 8 12 F B (The) S 67 J ( Default Action) S E 
  1765. 2880 7108 P 0 12 F 8 9 F (The) S 50 J ( default action associated with any rule can be written as) S 
  1766. 3600 7528 P 0 12 F 0 9 F ($$) S 108 J ( = $1) S 
  1767. 2880 7968 P 0 12 F 8 9 F (which) S 50 J ( means that the value of associated with ) S 0 12 F 0 9 F ($1) S 0 12 F 8 9 F () S 50 J ( on the value stack is assigned to ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( on) S 
  1768. 2880 8208 P (the value stack when the rule is reduced.  If, for example, ) S 0 12 F 0 9 F ($1) S 0 12 F 8 9 F () S 50 J ( is an integer, then ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( will be) S 
  1769. 2880 8448 P (the same integer after the reduction occurs.) S 
  1770. 2880 8888 P (On the other hand, suppose that the recognition action associated with a rule explicitly) S 
  1771. 2880 9128 P (states) S 
  1772. 3600 9548 P 0 12 F 0 9 F ($$) S 108 J ( = $1) S 
  1773. 2880 9988 P 0 12 F 8 9 F (This) S 50 J ( explicit assignment may not have the same effect as the implicit assignment.  For) S 
  1774. 2880 10228 P (example, suppose that you define) S 
  1775. 3600 10648 P 0 12 F 0 9 F (%union) S 108 J ( {) S 
  1776. 3600 10868 P (    float floatval;) S 
  1777. 3600 11088 P (    int intval;) S 
  1778. 3600 11308 P (}) S 
  1779. 2880 11748 P 0 12 F 8 9 F (Also) S 50 J ( suppose that the type associated with ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( is ) S 0 12 F 0 9 F ("floatval") S 0 12 F 8 9 F () S 50 J ( and the type associated) S 
  1780. 2880 11988 P (with ) S 0 12 F 0 9 F ($1) S 0 12 F 8 9 F () S 50 J ( is ) S 0 12 F 0 9 F ("intval") S 0 12 F 8 9 F (.) S 50 J (  Then the explicit statement) S 
  1781. 3600 12408 P 0 12 F 0 9 F ($$) S 108 J ( = $1) S 
  1782. 2880 12848 P 0 12 F 8 9 F (performs) S 50 J ( an integer to floating point conversion when the value of ) S 0 12 F 0 9 F ($1) S 0 12 F 8 9 F () S 50 J ( is assigned to ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F (,) S 
  1783. 2880 13088 P (whereas) S 50 J ( the implicit statement did an integer to integer assignment and did ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( perform) S 
  1784. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1785. 2880 14800 P 0 12 F 24 10 F (43) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1786. PE 
  1787. 2160 1968 P 8 9 F (this) S 50 J ( conversion.  You must therefore be careful and think about the effects of implicit vs.) S 
  1788. 2160 2208 P (explicit assignments.) S 
  1789. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1790. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 44) S 0 12 F 
  1791. PE 
  1792. 7620 2448 P 8 18 F B (8.) S 100 J ( Ambiguities) S E 
  1793. 2880 4048 P 0 12 F 8 9 F (Suppose) S 50 J ( we have a grammar with the rule) S 
  1794. 3600 4468 P 0 12 F 0 9 F (expr) S 108 J ( : expr '-' expr ;) S 
  1795. 2880 4908 P 0 12 F 8 9 F (and) S 50 J ( the parser is reading an expression of the form) S 
  1796. 3600 5328 P 0 12 F 0 9 F (expr) S 108 J ( - expr - expr) S 
  1797. 2880 5768 P 0 12 F 8 9 F (The) S 50 J ( parser reads this token by token, of course, so after three tokens it will have) S 
  1798. 3600 6188 P 0 12 F 0 9 F (expr) S 108 J ( - expr) S 
  1799. 2880 6628 P 0 12 F 8 9 F (The) S 50 J ( parser recognizes this form.  In fact, the parser could reduce this right away into a) S 
  1800. 2880 6868 P (single ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( according to the given grammar rule.) S 
  1801. 2880 7308 P (However, the parser has a problem.  At this point, the parser doesn't know what comes) S 
  1802. 2880 7548 P (next, and perhaps the entire line will be something like) S 
  1803. 3600 7968 P 0 12 F 0 9 F (expr) S 108 J ( - expr * expr) S 
  1804. 2880 8408 P 0 12 F 8 9 F (If) S 50 J ( it is, the precedence rules say that the multiplication should be performed before the) S 
  1805. 2880 8648 P (subtraction, so handling the subtraction first is incorrect.  The parser must therefore read) S 
  1806. 2880 8888 P (another token to see if it is really all right to deal with the subtraction now, or if the correct) S 
  1807. 2880 9128 P (action is to skip the subtraction for the moment and deal with whatever follows the second) S 
  1808. 2880 9368 P 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 
  1809. 2880 9808 P (In) S 50 J ( terms of parser states, this problem boils down to a choice between ) S 0 12 F 8 9 F I (reducing) S E 0 12 F 8 9 F () S 50 J ( the) S 
  1810. 2880 10048 P (expression) S 
  1811. 3600 10468 P 0 12 F 0 9 F (expr) S 108 J ( - expr) S 
  1812. 2880 10908 P 0 12 F 8 9 F (or) S 50 J ( ) S 0 12 F 8 9 F I (shifting) S E 0 12 F 8 9 F () S 50 J ( and acquiring more input before making a reduction.  This is known as a) S 
  1813. 2880 11148 P 0 12 F 8 9 F I (shift/reduce) S 50 J ( conflict.) S E 0 12 F 8 9 F () S 50 J (  Sometimes a parser must also choose between two possible) S 
  1814. 2880 11388 P (reductions.  This kind of situation is called a ) S 0 12 F 8 9 F I (reduce/reduce) S 50 J ( conflict.) S E 
  1815. 2880 11828 P 0 12 F 8 9 F (In) S 50 J ( case you are curious, there is no such thing as a shift/shift conflict.  To see why this is) S 
  1816. 2880 12068 P (impossible, suppose that we have the following definitions.) S 
  1817. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1818. 2880 14800 P 0 12 F 24 10 F (45) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1819. PE 
  1820. 2880 1948 P 0 9 F (thing) S 108 J ( : a b) S 
  1821. 2880 2168 P (      | a c) S 
  1822. 2880 2388 P (      ;) S 
  1823. 2880 2608 P (b : T rest_of_b;) S 
  1824. 2880 2828 P (c : T rest_of_c;) S 
  1825. 2160 3268 P 0 12 F 8 9 F (If) S 50 J ( the parser is in the state where it has seen ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F (,) S 50 J ( you would have the diagram) S 
  1826. 2880 3688 P 0 12 F 0 9 F (thing) S 108 J ( : a.b) S 
  1827. 2880 3908 P (thing : a.c) S 
  1828. 2160 4348 P 0 12 F 8 9 F (You) S 50 J ( might think that if the lookahead symbol was the token ) S 0 12 F 0 9 F (T) S 0 12 F 8 9 F (,) S 50 J ( the parser would be) S 
  1829. 2160 4588 P (confused, since ) S 0 12 F 0 9 F (T) S 0 12 F 8 9 F () S 50 J ( is the first token of both ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("c") S 0 12 F 8 9 F (.) S 50 J (  However, there is no confusion) S 
  1830. 2160 4828 P (at all.  The parser just Shifts to a state that we could diagram as) S 
  1831. 2880 5248 P 0 12 F 0 9 F (b) S 108 J ( : T.rest_of_b) S 
  1832. 2880 5468 P (c : T.rest_of_c) S 
  1833. 2160 6288 P 0 12 F 8 12 F B (8.1) S 67 J (  Resolving Conflicts by Precedence) S E 
  1834. 2160 7008 P 0 12 F 8 9 F (The) S 50 J ( precedence directives \() S 0 12 F 0 9 F (%left) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (%right) S 0 12 F 8 9 F (,) S 50 J ( and ) S 0 12 F 0 9 F (%nonassoc) S 0 12 F 8 9 F (\)) S 50 J ( let YAY-produced parsers) S 
  1835. 2160 7248 P (resolve shift/reduce conflicts in an obvious way:) S 
  1836. 2160 7688 P (\(a\)          The precedence of a Shift operation is defined to be the precedence of the token) S 
  1837. 2880 7928 P (on which the Shift takes place.) S 
  1838. 2160 8368 P (\(b\)          The precedence of a Reduce operation is defined to be the precedence of the) S 
  1839. 2880 8608 P (grammar rule that the Reduce operation uses.) S 
  1840. 2160 9048 P (If you have a shift/reduce conflict, and the Shift and Reduce operations both have a) S 
  1841. 2160 9288 P (precedence, the parser chooses the operation with the higher precedence.) S 
  1842. 2160 10108 P 0 12 F 8 12 F B (8.2) S 67 J (  Disambiguating Rules) S E 
  1843. 2160 10828 P 0 12 F 8 9 F (Precedence) S 50 J ( cannot resolve conflicts if one or both conflicting operations have no) S 
  1844. 2160 11068 P (precedence.  For example, consider the following.) S 
  1845. 2880 11488 P 0 12 F 0 9 F (statmt:) S 108 J (  IF '\(' cond '\)' statmt) S 
  1846. 2880 11708 P (    |    IF '\(' cond '\)' statmt ELSE statmt ;) S 
  1847. 2160 12148 P 0 12 F 8 9 F (Given) S 50 J ( this rule, how should the parser interpret the input) S 
  1848. 2880 12568 P 0 12 F 0 9 F (IF) S 108 J ( \( cond1 \) IF \( cond2 \) statmt1 ELSE statmt2) S 
  1849. 2160 13008 P 0 12 F 8 9 F (There) S 50 J ( are two equally valid interpretations of this input:) S 
  1850. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1851. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 46) S 0 12 F 
  1852. PE 
  1853. 3600 1948 P 0 9 F (IF) S 108 J ( \( cond1 \) {) S 
  1854. 3600 2168 P (     IF \( cond2 \) statmt1) S 
  1855. 3600 2388 P (     ELSE statmt2) S 
  1856. 3600 2608 P (}) S 
  1857. 2880 3048 P 0 12 F 8 9 F (and) S 
  1858. 3600 3468 P 0 12 F 0 9 F (IF) S 108 J ( \( cond1 \) {) S 
  1859. 3600 3688 P (     IF \( cond2 \) statmt1) S 
  1860. 3600 3908 P (}) S 
  1861. 3600 4128 P (ELSE statmt2) S 
  1862. 2880 4568 P 0 12 F 8 9 F (In) S 50 J ( a typical grammar, the ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (IF-ELSE) S 0 12 F 8 9 F () S 50 J ( statements would not have a precedence, so) S 
  1863. 2880 4808 P (precedence could not resolve the conflict.  Thus consider what happens at the point when) S 
  1864. 2880 5048 P (the parser has read) S 
  1865. 3600 5468 P 0 12 F 0 9 F (IF) S 108 J ( \( cond1 \) IF \( cond2 \) statmt1) S 
  1866. 2880 5908 P 0 12 F 8 9 F (and) S 50 J ( has just picked up ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F () S 50 J ( as the lookahead symbol.) S 
  1867. 2880 6348 P (\(1\)          It can immediately Reduce the) S 
  1868. 3600 6768 P 0 12 F 0 9 F (IF) S 108 J ( \( cond2 \) statmt1) S 
  1869. 2880 7208 P 0 12 F 8 9 F () S 720 J ( using) S 50 J ( the first definition of ) S 0 12 F 0 9 F ("statmt") S 0 12 F 8 9 F () S 50 J ( and obtain) S 
  1870. 3600 7628 P 0 12 F 0 9 F (IF) S 108 J ( \( cond1 \) statmt ELSE ...) S 
  1871. 2880 8068 P 0 12 F 8 9 F () S 720 J ( thereby) S 50 J ( associating the ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F () S 50 J ( with the first ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F (.) S 
  1872. 2880 8508 P (\(2\)) S 500 J ( It) S 50 J ( can Shift, which means ignoring the first part \(the ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( with ) S 0 12 F 0 9 F ("cond1") S 0 12 F 8 9 F (\)) S 50 J ( and going) S 
  1873. 3600 8748 P (on to handle the second part, thereby associating the ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F () S 50 J ( with the second ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F (.) S 
  1874. 2880 9188 P (In) S 50 J ( this case, most programming languages choose to associate the ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F () S 50 J ( with the second) S 
  1875. 2880 9428 P 0 12 F 0 9 F (IF) S 0 12 F 8 9 F (,) S 50 J ( i.e. they want the parser to Shift instead of Reduce. Because of this \(and other similar) S 
  1876. 2880 9668 P (situations\), YAY-produced parsers are designed to use the following rule to resolve) S 
  1877. 2880 9908 P (shift/reduce conflicts.) S 
  1878. 2880 10308 P 0 12 F 8 10 F B (Disambiguating) S 56 J ( Rule 1:) S E 
  1879. 3600 10548 P 0 12 F 8 9 F (If) S 50 J ( there is a shift/reduce conflict in situations where no precedence rules have) S 
  1880. 3600 10788 P (been created to resolve the conflict, the default action is to Shift. The conflict will) S 
  1881. 3600 11028 P (also be reported in the YAY output so you can check that Shifting is actually what) S 
  1882. 3600 11268 P (you want.  If it isn't what you want, the grammar rules will have to be rewritten.) S 
  1883. 2880 11708 P (This is known as a disambiguating rule because it helps YAY-produced parsers resolve) S 
  1884. 2880 11948 P (ambiguities.  The rule is only used in situations where precedence rules cannot resolve) S 
  1885. 2880 12188 P (the conflict.  If both the Shift operation and the Reduce operation have an assigned) S 
  1886. 2880 12428 P (precedence, the parser can compare precedences and decide which operation to perform) S 
  1887. 2880 12668 P (first.  Even if the precedences are equal, the precedences must have originated from) S 
  1888. 2880 12908 P (either ) S 0 12 F 0 9 F (%left) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (%right) S 0 12 F 8 9 F (,) S 50 J ( or ) S 0 12 F 0 9 F (%nonassoc) S 0 12 F 8 9 F (,) S 50 J ( so the parser knows how to handle the situation.) S 
  1889. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1890. 2880 14800 P 0 12 F 24 10 F (47) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1891. PE 
  1892. 2160 1968 P 8 9 F (The) S 50 J ( only time the disambiguating rule is needed is when one or both of the Shift or) S 
  1893. 2160 2208 P (Reduce operations does not have an assigned precedence.) S 
  1894. 2160 2648 P (In a similar vein, YAY-produced parsers use the following rule to resolve reduce/reduce) S 
  1895. 2160 2888 P (conflicts.) S 
  1896. 2160 3288 P 0 12 F 8 10 F B (Disambiguating) S 56 J ( Rule 2:) S E 
  1897. 2880 3528 P 0 12 F 8 9 F (If) S 50 J ( there is a reduce/reduce conflict, the parser will always Reduce by the rule that) S 
  1898. 2880 3768 P (was given ) S 0 12 F 8 9 F I (first) S E 0 12 F 8 9 F () S 50 J ( in the rules section of the YAY input.  Again, the conflict will be) S 
  1899. 2880 4008 P (reported in the YAY output so that users may ensure that the choice of Reduction) S 
  1900. 2880 4248 P (is correct.) S 
  1901. 2160 4688 P (Note that precedence is ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( consulted in reduce/reduce conflicts.  YAY always Reduces) S 
  1902. 2160 4928 P (by the earliest grammar rule, regardless of precedence.) S 
  1903. 2160 5368 P (Finally, YAY-produced parsers use a third disambiguating rule to prevent excessive errors.) S 
  1904. 2160 5768 P 0 12 F 8 10 F B (Disambiguating) S 56 J ( Rule 3:) S E 
  1905. 2880 6008 P 0 12 F 8 9 F (If) S 50 J ( the parser is asked to choose between shifting on ) S 0 12 F 0 9 F B (error) S E 0 12 F 8 9 F () S 50 J ( or on any other item,) S 
  1906. 2880 6248 P (it will choose the non-error item.) S 
  1907. 2160 6688 P (The disambiguating rules are simple to state, but they can have complex repercussions if) S 
  1908. 2160 6928 P (the grammar is non-trivial.  If the grammar is sufficiently complicated, these simple rules) S 
  1909. 2160 7168 P (for resolving conflicts may not be capable of handling all the necessary intricacies in the) S 
  1910. 2160 7408 P (way you want.  You should pay close attention to all conflicts noted in the parsing table) S 
  1911. 2160 7648 P (report produced by YAY and should ensure that the default actions taken by the parser) S 
  1912. 2160 7888 P (are the desired ones.) S 
  1913. 2160 8328 P 0 12 F 8 9 F B (Note:) S E 0 12 F 8 9 F () S 50 J ( the conflict between the rules) S 
  1914. 2880 8748 P 0 12 F 0 9 F (statmt:) S 108 J (  IF '\(' cond '\)' statmt) S 
  1915. 2880 8968 P (    |    IF '\(' cond '\)' ELSE statmt ;) S 
  1916. 2160 9408 P 0 12 F 8 9 F (can) S 50 J ( be resolved by adding) S 
  1917. 2880 9828 P 0 12 F 0 9 F (%left) S 108 J ( ELSE) S 
  1918. 2160 10268 P 0 12 F 8 9 F (to) S 50 J ( the declarations section of the YAY input.  This puts a precedence on the ) S 0 12 F 0 9 F (ELSE) S 0 12 F 8 9 F () S 50 J ( action) S 
  1919. 2160 10508 P (and says that it is left-associative.  This is another example of using a precedence to) S 
  1920. 2160 10748 P (resolve an ambiguity.) S 
  1921. 2160 11568 P 0 12 F 8 12 F B (8.3) S 67 J (  Conflicts in YAY Output) S E 
  1922. 2160 12288 P 0 12 F 8 9 F (If) S 50 J ( your grammar has shift/reduce or reduce/reduce conflicts, you will also see a table of) S 
  1923. 2160 12528 P (conflicts in the statistics section of the Parser Description.  For example, if we change the) S 
  1924. 2160 12768 P (rules section of our sample grammar to) S 
  1925. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1926. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 48) S 0 12 F 
  1927. PE 
  1928. 3600 1948 P 0 9 F (stmt) S 108 J ( : IF stmt ELSE stmt) S 
  1929. 3600 2168 P (     | IF stmt) S 
  1930. 3600 2388 P (     | stmt stmt) S 
  1931. 3600 2608 P (     | A ;) S 
  1932. 2880 3048 P 0 12 F 8 9 F (we) S 50 J ( get the following conflict report.) S 
  1933. 3600 3468 P 0 12 F 0 9 F (Conflicts:) S 
  1934. 3600 3688 P () S 108 J (    State  Token      Action) S 
  1935. 3600 3908 P (        5  IF         shift 2) S 
  1936. 3600 4128 P (        5  IF         reduce \(3\)) S 
  1937. 3600 4348 P (        5  A          shift 1) S 
  1938. 3600 4568 P (        5  A          reduce \(3\)) S 
  1939. 2880 5008 P 0 12 F 8 9 F (This) S 50 J ( shows that State 5 has two shift/reduce conflicts.  If the parser is in State 5 and) S 
  1940. 2880 5248 P (encounters an IF token, it can shift to state 2 or reduce using rule 3.  If the parser) S 
  1941. 2880 5488 P (encounters an A token, it can shift to state 1 or reduce using rule 3.  This is summarized in) S 
  1942. 2880 5728 P (the final statistics with the line) S 
  1943. 3600 6148 P 0 12 F 0 9 F (2) S 108 J ( shift/reduce conflicts) S 
  1944. 2880 6588 P 0 12 F 8 9 F (Reading) S 50 J ( the conflict report shows you what action the parser takes in case of a conflict --) S 
  1945. 2880 6828 P (the parser always takes the ) S 0 12 F 8 9 F I (first) S E 0 12 F 8 9 F () S 50 J ( action shown in the report.  This action will be chosen in) S 
  1946. 2880 7068 P (accordance with the two disambiguating rules.) S 
  1947. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1948. 2880 14800 P 0 12 F 24 10 F (49) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  1949. PE 
  1950. 5640 2448 P 8 18 F B (9.) S 100 J ( Advanced Features) S E 
  1951. 2160 4048 P 0 12 F 8 9 F (In) S 50 J ( this chapter, we describe more specialized features of YAY.) S 
  1952. 2160 4868 P 0 12 F 8 12 F B (9.1) S 67 J (  LALR\(2\) Grammars) S E 
  1953. 2160 5588 P 0 12 F 8 9 F (An) S 50 J ( LALR\(2\) grammar has one more level of "lookahead" than an LALR\(1\) grammar.) S 
  1954. 2160 5828 P (When trying to decide how to parse a given input, an LALR\(1\) parser sometimes looks at) S 
  1955. 2160 6068 P (the next input token to see if that makes a difference.  In the same situation, an LALR\(2\)) S 
  1956. 2160 6308 P (parser can look at the next ) S 0 12 F 8 9 F I (two) S E 0 12 F 8 9 F () S 50 J ( tokens.) S 
  1957. 2160 6748 P (LALR\(2\) grammars are described in the same way as LALR\(1\) grammars. To indicate that) S 
  1958. 2160 6988 P (you want an LALR\(2\) parser, you must put the option ) S 0 12 F 0 9 F (+LR2) S 0 12 F 8 9 F () S 50 J ( on the command line that) S 
  1959. 2160 7228 P (invokes YAY.) S 
  1960. 2160 7668 P (An LALR\(2\) parser can perform a ) S 0 12 F 8 9 F I (lookahead) S E 0 12 F 8 9 F () S 50 J ( action as well as Shift, Reduce, Goto,) S 
  1961. 2160 7908 P (Accept, and Error.  For example, in a state diagram you might see) S 
  1962. 2880 8328 P 0 12 F 0 9 F (A) S 108 J (    shift 1) S 
  1963. 2880 8548 P (B    reduce \(2\)) S 
  1964. 2880 8768 P (C    lookahead) S 
  1965. 2160 9208 P 0 12 F 8 9 F (This) S 50 J ( means that if token ) S 0 12 F 0 9 F (A) S 0 12 F 8 9 F () S 50 J ( is encountered in this state, the parser will shift to State 1; if) S 
  1966. 2160 9448 P (token ) S 0 12 F 0 9 F (B) S 0 12 F 8 9 F () S 50 J ( is encountered, it will reduce using Rule \(2\); and if token ) S 0 12 F 0 9 F (C) S 0 12 F 8 9 F () S 50 J ( is encountered, it will) S 
  1967. 2160 9688 P (lookahead.) S 
  1968. 2160 10808 P 0 12 F 8 12 F I (9.1.1) S 67 J (  The Lookahead Action) S E 
  1969. 2160 11528 P 0 12 F 8 9 F (A) S 50 J ( state that has a Lookahead action has a list of possible states the parser can enter next.) S 
  1970. 2160 11768 P (These states conflict with each other -- the Lookahead action isn't needed if there is no) S 
  1971. 2160 12008 P (conflict.  The parser attempts to resolve the conflict by reading one additional token.  If the) S 
  1972. 2160 12248 P (grammar is set up properly, this token will be valid in only one of the possible contexts, so) S 
  1973. 2160 12488 P (the parser can choose that rule instead of the other possibilities.) S 
  1974. 2160 12928 P (Thus the Lookahead action tests all the possibilities in the list. It begins by making a) S 
  1975. 2160 13168 P (private copy of the state stack.  \(Actually, it just sets things up so that it looks like it has a) S 
  1976. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  1977. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 50) S 0 12 F 
  1978. PE 
  1979. 2880 1968 P 8 9 F (separate) S 50 J ( copy of the state stack -- it doesn't really make a copy.\)  Next, it calls on a) S 
  1980. 2880 2208 P (routine named ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( \(described later\) to obtain a second lookahead token.) S 
  1981. 2880 2648 P (The Lookahead action then begins going through the possible rules on its list.  Some of) S 
  1982. 2880 2888 P (these rules may be Shifts, while others are Reduces -- the reductions are what make it) S 
  1983. 2880 3128 P (necessary to simulate a copy of the state stack, because you don't want to play with the) S 
  1984. 2880 3368 P (true stack.) S 
  1985. 2880 3808 P (The Lookahead action takes the action associated with each possibility in the list, entering) S 
  1986. 2880 4048 P (new states through Shifts or Reduces.  It then sees if the second lookahead token causes) S 
  1987. 2880 4288 P (an error in this new state.  If an error occurs, the parser pops back to the original) S 
  1988. 2880 4528 P (Lookahead state and checks the next possibility on the list.) S 
  1989. 2880 4968 P (When it finally finds a rule where the second lookahead symbol doesn't cause an error, it) S 
  1990. 2880 5208 P (pops back to the original Lookahead state one last time.  It gets rid of the stack set-up that) S 
  1991. 2880 5448 P (the Lookahead action was using and returns to the old state stack.  It then takes the action) S 
  1992. 2880 5688 P (that it has discovered in the list of possibilities.) S 
  1993. 2880 6128 P (Note that the Lookahead action takes the first possible rule where the second lookahead) S 
  1994. 2880 6368 P (symbol is valid.  It is, of course, possible that there are other valid possibilities in the list.) S 
  1995. 2880 6608 P (The order of the list of possibilities is based on the standard disambiguating rules: a shift) S 
  1996. 2880 6848 P (comes first, followed by reductions in the order in which the corresponding grammar rules) S 
  1997. 2880 7088 P (were given.) S 
  1998. 2880 8208 P 0 12 F 8 12 F I (9.1.2) S 67 J (  The yy2lex Routine) S E 
  1999. 2880 8928 P 0 12 F 8 9 F (In) S 50 J ( order to perform the lookahead, ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( calls a routine called ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F (.) S 50 J (  This is a) S 
  2000. 2880 9168 P (user-written lexical analyzer, just as ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( is.  It returns the same kind of token value) S 
  2001. 2880 9408 P (that ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( does.  However, ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( should not set the ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F () S 50 J ( value.) S 
  2002. 2880 9848 P (For some applications, ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( could even be the same routine as ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (.) S 50 J (  There) S 
  2003. 2880 10088 P (are good reasons why the two should be separate, however.  Suppose, for the sake of) S 
  2004. 2880 10328 P (argument, that ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( called ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( for all input.  ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( might call ) S 0 12 F 0 9 F ("yylex") S 
  2005. 2880 10568 P 0 12 F 8 9 F (for) S 50 J ( the next token, then immediately call ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( again for a lookahead.  This second call) S 
  2006. 2880 10808 P (could overwrite important values like ) S 0 12 F 0 9 F ("yylval") S 0 12 F 8 9 F () S 50 J ( before they had been used, thereby) S 
  2007. 2880 11048 P (confusing things greatly.  For such reasons, ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( sometimes have to) S 
  2008. 2880 11288 P (be different routines.) S 
  2009. 2880 11728 P (In practice, parsers rarely call ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( -- the routine is only needed in special) S 
  2010. 2880 11968 P (circumstances.  This means that ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( usually can be much simpler than ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (:) S 
  2011. 2880 12208 P 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( must be able to handle all possible input tokens, while ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( is only called) S 
  2012. 2880 12448 P (in a few special cases.  To find out the tokens that ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( must be able to handle, run) S 
  2013. 2880 12688 P (your grammar through YAY and get a list of the states where the parser performs a) S 
  2014. 2880 12928 P (Lookahead instead of a Shift or Reduce.  These instances are the only ones where the) S 
  2015. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2016. 2880 14800 P 0 12 F 24 10 F (51) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2017. PE 
  2018. 2160 1968 P 8 9 F (parser) S 50 J ( will call ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F (,) S 50 J ( so the associated tokens are the only ones that the routine has) S 
  2019. 2160 2208 P (to handle.) S 
  2020. 2160 2648 P (The values obtained by ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( are thrown away once the parser has used them in its) S 
  2021. 2160 2888 P (lookahead.  What this means is that the parser doesn't remember what ) S 0 12 F 0 9 F ("yy2lex") S 
  2022. 2160 3128 P 0 12 F 8 9 F (returned,) S 50 J ( so it will call on ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( to re-read the token for normal parsing.  This means) S 
  2023. 2160 3368 P (one of two things:) S 
  2024. 2160 3808 P (\(a\)          ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( can duplicate the processing that ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( does, then leave the) S 
  2025. 2880 4048 P (pertinent information around for ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( to obtain.  This means that ) S 0 12 F 0 9 F ("yylex") S 
  2026. 2880 4288 P 0 12 F 8 9 F (must) S 50 J ( have a way of knowing when ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( has already read the next token) S 
  2027. 2880 4528 P (\(e.g. ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( can set a flag\).) S 
  2028. 2160 4968 P (\(b\)          ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( can cheat and only do minimal processing.  For example, ) S 0 12 F 0 9 F ("yy2lex") S 
  2029. 2880 5208 P 0 12 F 8 9 F (may) S 50 J ( only have to look at the first character of the next token to figure out what is) S 
  2030. 2880 5448 P (coming next.  ) S 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F () S 50 J ( can then ) S 0 12 F 0 9 F ("ungetc") S 0 12 F 8 9 F () S 50 J ( that character and return an) S 
  2031. 2880 5688 P (appropriate token value.  When ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( is called, it reads the full token in the) S 
  2032. 2880 5928 P (usual manner.) S 
  2033. 2160 6368 P (The second approach is sufficient for most grammars.  It simplifies both ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( and) S 
  2034. 2160 6608 P 0 12 F 0 9 F ("yy2lex") S 0 12 F 8 9 F (.) S 
  2035. 2160 7728 P 0 12 F 8 12 F I (9.1.3) S 67 J (  Conflicts) S E 
  2036. 2160 8448 P 0 12 F 8 9 F (With) S 50 J ( an additional level of lookahead, there is the potential for a staggering number of) S 
  2037. 2160 8688 P (conflicts.  For example, you may lookahead to a new state to resolve one conflict, only to) S 
  2038. 2160 8928 P (find that the new state also has a lookahead to resolve a conflict.) S 
  2039. 2160 9368 P (If an LALR\(2\) parser is performing a lookahead and enters a state where the secondary) S 
  2040. 2160 9608 P (lookahead token invokes another Lookahead action, the parser ruthlessly resolves the) S 
  2041. 2160 9848 P (second Lookahead action by choosing the first possibility on the second Lookahead list.) S 
  2042. 2160 10088 P (This is not very elegant, so you should avoid this double lookahead situation.) S 
  2043. 2160 10528 P (Conflicts of this nature are reported in the usual conflict table at the end of the State) S 
  2044. 2160 10768 P (Description output.) S 
  2045. 2160 11588 P 0 12 F 8 12 F B (9.2) S 67 J (  Multiple Actions) S E 
  2046. 2160 12308 P 0 12 F 8 9 F (A) S 50 J ( rule can have more than one action.  For example, you might have) S 
  2047. 2880 12728 P 0 12 F 0 9 F (a) S 108 J ( : A1 {action1} A2 {action2} A3 {action3};) S 
  2048. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2049. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 52) S 0 12 F 
  2050. PE 
  2051. 2880 1968 P 8 9 F (The) S 50 J ( non-terminal symbol ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F () S 50 J ( consists of symbols ) S 0 12 F 0 9 F (A1) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (A2) S 0 12 F 8 9 F (,) S 50 J ( and ) S 0 12 F 0 9 F (A3) S 0 12 F 8 9 F (.) S 50 J (  When ) S 0 12 F 0 9 F (A1) S 0 12 F 8 9 F () S 50 J ( is) S 
  2052. 2880 2208 P (recognized, ) S 0 12 F 0 9 F ("action1") S 0 12 F 8 9 F () S 50 J ( is invoked; when ) S 0 12 F 0 9 F (A2) S 0 12 F 8 9 F () S 50 J ( is recognized, ) S 0 12 F 0 9 F ("action2") S 0 12 F 8 9 F () S 50 J ( is invoked; and) S 
  2053. 2880 2448 P (when ) S 0 12 F 0 9 F (A3) S 0 12 F 8 9 F () S 50 J ( is recognized \(and therefore the entire symbol ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F (\),) S 50 J ( ) S 0 12 F 0 9 F ("action3") S 0 12 F 8 9 F () S 50 J ( is invoked.  In) S 
  2054. 2880 2688 P (this case,) S 
  2055. 3600 3108 P 0 12 F 0 9 F ($1) S 108 J (   -- ) S 0 12 F 8 9 F (is) S 50 J ( the value of) S 0 12 F 0 9 F () S 108 J ( A1) S 
  2056. 3600 3328 P ($2   -- ) S 0 12 F 8 9 F (is) S 50 J ( the value of) S 0 12 F 0 9 F () S 108 J ( $$) S 0 12 F 8 9 F () S 50 J ( in) S 0 12 F 0 9 F () S 108 J ( action1) S 
  2057. 3600 3548 P ($3   -- ) S 0 12 F 8 9 F (is) S 50 J ( the value of) S 0 12 F 0 9 F () S 108 J ( A2) S 
  2058. 3600 3768 P ($4   -- ) S 0 12 F 8 9 F (is) S 50 J ( the value of) S 0 12 F 0 9 F () S 108 J ( $$) S 0 12 F 8 9 F () S 50 J ( in) S 0 12 F 0 9 F () S 108 J ( action2) S 
  2059. 3600 3988 P ($5   -- ) S 0 12 F 8 9 F (is) S 50 J ( the value of) S 0 12 F 0 9 F () S 108 J ( A3) S 
  2060. 2880 4428 P 0 12 F 8 9 F (If) S 50 J ( types are involved, multiple actions become more complicated.  If ) S 0 12 F 0 9 F ("action1") S 0 12 F 8 9 F () S 50 J ( mentions) S 
  2061. 2880 4668 P 0 12 F 0 9 F ($$) S 0 12 F 8 9 F (,) S 50 J ( there is no way for YAY to guess what type ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( has, since it is not really associated) S 
  2062. 2880 4908 P (with a token or non-terminal symbol.  You must therefore state it explicitly by specifying) S 
  2063. 2880 5148 P (the appropriate type name in angle brackets between the two ) S 0 12 F 0 9 F ($) S 0 12 F 8 9 F () S 50 J ( signs.  If we had) S 
  2064. 3600 5568 P 0 12 F 0 9 F (%union) S 108 J ( {) S 
  2065. 3600 5788 P (    int intval;) S 
  2066. 3600 6008 P (    float realval;) S 
  2067. 3600 6228 P (}) S 
  2068. 2880 6668 P 0 12 F 8 9 F (you) S 50 J ( might say) S 
  2069. 3600 7088 P 0 12 F 0 9 F ($<realval>$) S 
  2070. 2880 7528 P 0 12 F 8 9 F (in) S 50 J ( place of ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( in the action, to show that the result had type ) S 0 12 F 0 9 F B (float) S E 0 12 F 8 9 F (.) S 50 J (  In the same way, if) S 
  2071. 2880 7768 P 0 12 F 0 9 F ("action2") S 0 12 F 8 9 F () S 50 J ( refers to ) S 0 12 F 0 9 F ($2) S 0 12 F 8 9 F () S 50 J ( \(the result of ) S 0 12 F 0 9 F (action1) S 0 12 F 8 9 F (\),) S 50 J ( you might say) S 
  2072. 3600 8188 P 0 12 F 0 9 F ($<realval>2) S 
  2073. 2880 8628 P 0 12 F 8 9 F (To) S 50 J ( deal with multiple actions, YAY changes the form of the given grammar rule and) S 
  2074. 2880 8868 P (creates grammar rules for dummy symbols.  The dummy symbols have names made up of) S 
  2075. 2880 9108 P (a ) S 0 12 F 0 9 F ($) S 0 12 F 8 9 F () S 50 J ( followed by the rule number.  For example,) S 
  2076. 3600 9528 P 0 12 F 0 9 F (a) S 108 J ( : A1 {action1} A2 {action2} A3 {action3};) S 
  2077. 2880 9968 P 0 12 F 8 9 F (might) S 50 J ( be changed to the rules) S 
  2078. 3600 10388 P 0 12 F 0 9 F ($21) S 108 J ( : /* null */ {action1} ;) S 
  2079. 3600 10608 P ($22 : /* null */ {action2} ;) S 
  2080. 3600 10828 P (a : A1 $21 A2 $22 A3 {action3};) S 
  2081. 2880 11268 P 0 12 F 8 9 F (These) S 50 J ( rules will be shown in the Rules Summary of the Parser Description report.) S 
  2082. 2880 11708 P (Note that this technique can introduce conflicts.  For example, suppose you have the) S 
  2083. 2880 11948 P (definitions) S 
  2084. 3600 12368 P 0 12 F 0 9 F (a) S 108 J ( : A1 {action1} A2 X;) S 
  2085. 3600 12588 P (b : A1 A2 Y;) S 
  2086. 2880 13028 P 0 12 F 8 9 F (These) S 50 J ( are changed to) S 
  2087. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2088. 2880 14800 P 0 12 F 24 10 F (53) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2089. PE 
  2090. 2880 1948 P 0 9 F ($50) S 108 J ( : /* null */ {action1};) S 
  2091. 2880 2168 P (a : A1 $50 A2 X;) S 
  2092. 2880 2388 P (b : A1 A2 Y;) S 
  2093. 2160 2828 P 0 12 F 8 9 F (The) S 50 J ( definitions of ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( give a shift/reduce conflict because the parser can't tell) S 
  2094. 2160 3068 P (whether ) S 0 12 F 0 9 F (A1) S 0 12 F 8 9 F () S 50 J ( followed by ) S 0 12 F 0 9 F (A2) S 0 12 F 8 9 F () S 50 J ( has the null string for ) S 0 12 F 0 9 F ($50) S 0 12 F 8 9 F () S 50 J ( in the middle.  It has to decide) S 
  2095. 2160 3308 P (whether to Reduce ) S 0 12 F 0 9 F ($50) S 0 12 F 8 9 F () S 50 J ( or to Shift to a state diagrammed by) S 
  2096. 2880 3728 P 0 12 F 0 9 F (b) S 108 J ( : A1 A2.Y) S 
  2097. 2160 4168 P 0 12 F 8 9 F (This) S 50 J ( particular conflict could be resolved by using an LALR\(2\) parser instead of LALR\(1\).) S 
  2098. 2160 4408 P (However, there are more complicated examples in which this is not possible.) S 
  2099. 2160 4848 P (There is another situation to watch for.  Consider the grammar) S 
  2100. 2880 5268 P 0 12 F 0 9 F (a) S 108 J ( : A1 c A2 X ;) S 
  2101. 2880 5488 P (b : A1 c A2 Y ;) S 
  2102. 2880 5708 P (c : /* nothing */ {action} ;) S 
  2103. 2160 6148 P 0 12 F 8 9 F (You) S 50 J ( might think that this is equivalent to) S 
  2104. 2880 6568 P 0 12 F 0 9 F (a) S 108 J ( : A1 {action} A2 X;) S 
  2105. 2880 6788 P (b : A1 {action} A2 Y;) S 
  2106. 2160 7228 P 0 12 F 8 9 F (but) S 50 J ( it is not.  The first will not produce a conflict, but the second one will.  The second is) S 
  2107. 2160 7468 P (converted into) S 
  2108. 2880 7888 P 0 12 F 0 9 F (a) S 108 J ( : A1 $50 A2 X;) S 
  2109. 2880 8108 P (b : A1 $51 A2 Y;) S 
  2110. 2880 8328 P ($50 : {action} ;) S 
  2111. 2880 8548 P ($51 : {action} ;) S 
  2112. 2160 8988 P 0 12 F 8 9 F (even) S 50 J ( when the action is the same for both ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F (.) S 50 J (  If the parser finds an ) S 0 12 F 0 9 F (A1) S 0 12 F 8 9 F () S 50 J ( followed) S 
  2113. 2160 9228 P (by a null string followed by ) S 0 12 F 0 9 F (A2) S 0 12 F 8 9 F (,) S 50 J ( it doesn't know if it should interpret the null string as ) S 0 12 F 0 9 F ($50) S 0 12 F 8 9 F () S 50 J ( or) S 
  2114. 2160 9468 P 0 12 F 0 9 F ($51) S 0 12 F 8 9 F (;) S 50 J ( therefore, it gets a conflict.  Obviously, it is better to use the first format, where the) S 
  2115. 2160 9708 P (identical actions are associated with a separate rule.) S 
  2116. 2160 10528 P 0 12 F 8 12 F B (9.3) S 67 J (  Selection Preference) S E 
  2117. 2160 11248 P 0 12 F 8 9 F (A) S 50 J ( ) S 0 12 F 8 9 F I (selection) S 50 J ( preference) S E 0 12 F 8 9 F () S 50 J ( can be added to a grammar rule to help resolve conflicts.  The) S 
  2118. 2160 11488 P (following input shows a simple example of how a selection preference can resolve) S 
  2119. 2160 11728 P (conflicts between two rules.) S 
  2120. 2880 12148 P 0 12 F 0 9 F (a1) S 108 J ( : a b ['+' '-']) S 
  2121. 2880 12368 P (     { /* Action 1 */ } ;) S 
  2122. 2880 12588 P (a2 : a b) S 
  2123. 2880 12808 P (     { /* Action 2 */ } ;) S 
  2124. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2125. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 54) S 0 12 F 
  2126. PE 
  2127. 2880 1968 P 8 9 F (The) S 50 J ( selection preference is indicated by zero or more ) S 0 12 F 8 9 F I (tokens) S E 0 12 F 8 9 F () S 50 J ( inside square brackets.  If) S 
  2128. 2880 2208 P (the token that follows the ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( is one of the tokens inside the square brackets, the parser) S 
  2129. 2880 2448 P (will use the grammar rule for ) S 0 12 F 0 9 F ("a1") S 0 12 F 8 9 F (.) S 50 J (  If the token that follows the ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( is not one of the) S 
  2130. 2880 2688 P (given tokens, the parser will use the rule for ) S 0 12 F 0 9 F ("a2") S 0 12 F 8 9 F (.) S 50 J (  In this way, the conflict between the) S 
  2131. 2880 2928 P (two rules is resolved -- the preference tells which one to select, depending on the value of) S 
  2132. 2880 3168 P (the lookahead token.) S 
  2133. 2880 3608 P (Notice that a selection preference states that a rule ) S 0 12 F 8 9 F I (should) S E 0 12 F 8 9 F () S 50 J ( be used when the next token is) S 
  2134. 2880 3848 P (one of the ones listed in the brackets and should ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( be used if it is not in the brackets.) S 
  2135. 2880 4288 P (The lookahead token is merely used to determine which rule to select.  It is ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( part of the) S 
  2136. 2880 4528 P (rule itself.  For example, suppose you have) S 
  2137. 3600 4948 P 0 12 F 0 9 F (a1) S 108 J ( : a b ['+' '-'] ;) S 
  2138. 3600 5168 P (a2 : a b ;) S 
  2139. 3600 5388 P (xx : a1 op expr ;) S 
  2140. 2880 5828 P 0 12 F 8 9 F (and) S 50 J ( suppose you have an ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F (,) S 50 J ( a ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F (,) S 50 J ( and ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( as the lookahead token.  The ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( indicates) S 
  2141. 2880 6068 P (that the ) S 0 12 F 0 9 F ("a") S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( should be reduced to ) S 0 12 F 0 9 F ("a1") S 0 12 F 8 9 F (.) S 50 J (  The parser does this and finds that the) S 
  2142. 2880 6308 P 0 12 F 0 9 F ("a1") S 0 12 F 8 9 F () S 50 J ( is part of the ) S 0 12 F 0 9 F ("xx") S 0 12 F 8 9 F () S 50 J ( rule.  The ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( lookahead token will be associated with the ) S 0 12 F 0 9 F ("op") S 
  2143. 2880 6548 P 0 12 F 8 9 F (symbol) S 50 J ( in the ) S 0 12 F 0 9 F ("xx") S 0 12 F 8 9 F () S 50 J ( rule.  In other words, a selection preference does not "use up" an input) S 
  2144. 2880 6788 P (token; it just looks at the token value to help resolve a conflict.) S 
  2145. 2880 7228 P (The ) S 0 12 F 0 9 F ($end) S 0 12 F 8 9 F () S 50 J ( symbol may be used inside square brackets to indicate end-of-file in the input) S 
  2146. 2880 7468 P (being parsed.  For example,) S 
  2147. 3600 7888 P 0 12 F 0 9 F (statement) S 108 J ( : line ['\\n' $end]) S 
  2148. 2880 8328 P 0 12 F 8 9 F (shows) S 50 J ( that this rule is preferred if a ) S 0 12 F 0 9 F ("line") S 0 12 F 8 9 F () S 50 J ( is followed by a new-line character or the end) S 
  2149. 2880 8568 P (of the file.) S 
  2150. 2880 9008 P (The square brackets of a selection preference may contain no tokens, as in) S 
  2151. 3600 9428 P 0 12 F 0 9 F (x) S 108 J ( : y z [];) S 
  2152. 2880 9868 P 0 12 F 8 9 F (This) S 50 J ( says that the parser should never use this rule unless it cannot be avoided.) S 
  2153. 2880 10308 P (When there are many selection preferences in the same state, the parser must compare) S 
  2154. 2880 10548 P (them to check for conflicts.  To do this, YAY chooses the most likely rule \(based on) S 
  2155. 2880 10788 P (preference\) and compares this to the other possible rules.  In order to understand what we) S 
  2156. 2880 11028 P (mean by "most likely", an example will help.  Consider the grammar) S 
  2157. 3600 11448 P 0 12 F 0 9 F (a) S 108 J ( : b [ 'x' ]) S 
  2158. 3600 11668 P (  | b [ 'y' ]) S 
  2159. 3600 11888 P (  | b [ ]) S 
  2160. 3600 12108 P (  ;) S 
  2161. 2880 12548 P 0 12 F 8 9 F (YAY) S 50 J ( must consider what happens when a ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( symbol has been encountered.  If the ) S 0 12 F 0 9 F ("b") S 
  2162. 2880 12788 P 0 12 F 8 9 F (is) S 50 J ( followed by an ) S 0 12 F 0 9 F ('x') S 0 12 F 8 9 F (,) S 50 J ( the most likely rule is) S 
  2163. 3600 13208 P 0 12 F 0 9 F (a) S 108 J ( : b [ 'x' ]) S 
  2164. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2165. 2880 14800 P 0 12 F 24 10 F (55) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2166. PE 
  2167. 2160 2168 P 8 9 F (If) S 50 J ( the ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( is followed by a ) S 0 12 F 0 9 F ('y') S 0 12 F 8 9 F (,) S 50 J ( the most likely rule is) S 
  2168. 2880 2588 P 0 12 F 0 9 F (a) S 108 J ( : b [ 'y' ]) S 
  2169. 2160 3028 P 0 12 F 8 9 F (If) S 50 J ( the ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( is followed by any other token, the most likely rule is) S 
  2170. 2880 3448 P 0 12 F 0 9 F (a) S 108 J ( : b [ ]) S 
  2171. 2160 3888 P 0 12 F 8 9 F (Once) S 50 J ( the most likely rule has been chosen, it will be compared to the other rules in the set) S 
  2172. 2160 4128 P (to make sure that there are no conflicts.  \(In a previous release, YAY would compare) S 
  2173. 2160 4368 P (every pair of rules, without choosing a most likely one.  In this case, the rules) S 
  2174. 2880 4788 P 0 12 F 0 9 F (a) S 108 J ( : b [ 'x' ]) S 
  2175. 2880 5008 P (a : b [ 'y' ]) S 
  2176. 2160 5448 P 0 12 F 8 9 F (would) S 50 J ( conflict with each other, because there was no way to choose between the two if) S 
  2177. 2160 5688 P (the next token was not ) S 0 12 F 0 9 F ('x') S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F ('y') S 0 12 F 8 9 F (.) S 50 J (  In this release, YAY will compare the most likely rule) S 
  2178. 2160 5928 P (to all the others, but will not compare all the possible pairs.\)) S 
  2179. 2160 6368 P (Selection preferences can also be stated using the construct) S 
  2180. 2880 6788 P 0 12 F 0 9 F ([^) S 108 J ( T1 T2 T3 ...]) S 
  2181. 2160 7228 P 0 12 F 8 9 F (where) S 50 J ( the first character is a caret \() S 0 12 F 0 9 F (^) S 0 12 F 8 9 F (\)) S 50 J ( and ) S 0 12 F 0 9 F (T1) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (T2) S 0 12 F 8 9 F (,) S 50 J ( etc. are tokens.  When this is put on the) S 
  2182. 2160 7468 P (end of a rule, it indicates that the rule should be used if the lookahead token is ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( one of) S 
  2183. 2160 7708 P (the listed tokens.  For example,) S 
  2184. 2880 8128 P 0 12 F 0 9 F (a1) S 108 J ( : a b) S 
  2185. 2880 8348 P (   { /* Action 1 */ } ;) S 
  2186. 2880 8568 P (a2 : a b [^ '+' '-']) S 
  2187. 2880 8788 P (   { /* Action 2 */ } ;) S 
  2188. 2160 9228 P 0 12 F 8 9 F (says) S 50 J ( that rule ) S 0 12 F 0 9 F ("a2") S 0 12 F 8 9 F () S 50 J ( should be used if the token after the ) S 0 12 F 0 9 F ("b") S 0 12 F 8 9 F () S 50 J ( is ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F (.) S 50 J (  If the token is) S 
  2189. 2160 9468 P 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ("a2") S 0 12 F 8 9 F () S 50 J ( should not be used \(so ) S 0 12 F 0 9 F ("a1") S 0 12 F 8 9 F () S 50 J ( will be\).) S 
  2190. 2160 9908 P (The construct ) S 0 12 F 0 9 F ([^]) S 0 12 F 8 9 F () S 50 J ( is the reverse of ) S 0 12 F 0 9 F ([]) S 0 12 F 8 9 F (.) S 50 J (  It is used to indicate a rule that should ) S 0 12 F 8 9 F I (always) S E 0 12 F 8 9 F () S 50 J ( be) S 
  2191. 2160 10148 P (taken unless there is another rule that must be taken because of a selection preference.) S 
  2192. 2160 10588 P (Selection preference constructs can be put in the middle of rules as well as on the end.) S 
  2193. 2160 10828 P (For example, we could write) S 
  2194. 2880 11248 P 0 12 F 0 9 F (expr) S 108 J ( : expr ['+' '-'] op expr) S 
  2195. 2880 11468 P (       { /* Action 1 */ }) S 
  2196. 2880 11688 P (     | expr op expr) S 
  2197. 2880 11908 P (       { /* Action 2 */ } ;) S 
  2198. 2160 12348 P 0 12 F 8 9 F (This) S 50 J ( states that if the first ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F () S 50 J ( is followed by ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F () S 50 J ( you want to use the first rule;) S 
  2199. 2160 12588 P (otherwise, you want to use the second.  Note that the preference does not use up the ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( or) S 
  2200. 2160 12828 P 0 12 F 0 9 F (-) S 0 12 F 8 9 F () S 50 J ( token: you still need a symbol \() S 0 12 F 0 9 F ("op") S 0 12 F 8 9 F (\)) S 50 J ( to represent such tokens.) S 
  2201. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2202. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 56) S 0 12 F 
  2203. PE 
  2204. 2880 1968 P 8 9 F (Selection) S 50 J ( preferences that appear in the middle of a rule are implemented in the same) S 
  2205. 2880 2208 P (way as multiple actions, using dummy rules.  The above example would result in) S 
  2206. 2880 2448 P (something like) S 
  2207. 3600 2868 P 0 12 F 0 9 F ($23) S 108 J ( : ['+' '-'] ;) S 
  2208. 3600 3088 P (expr : expr $23 op expr) S 
  2209. 3600 3308 P (       { /* Action 1 */ }) S 
  2210. 3600 3528 P (     | expr op expr) S 
  2211. 3600 3748 P (       { /* Action 2 */ } ;) S 
  2212. 2880 4188 P 0 12 F 8 9 F (\(where) S 50 J ( the ) S 0 12 F 0 9 F (23) S 0 12 F 8 9 F () S 50 J ( in ) S 0 12 F 0 9 F ($23) S 0 12 F 8 9 F () S 50 J ( is just a number we chose at random\).  The dummy rule that is) S 
  2213. 2880 4428 P (created is a null string with the selection preference on the end.  The first token for ) S 0 12 F 0 9 F ("op") S 
  2214. 2880 4668 P 0 12 F 8 9 F (will) S 50 J ( be the ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (-) S 0 12 F 8 9 F () S 50 J ( that was the lookahead token in rule ) S 0 12 F 0 9 F ($23) S 0 12 F 8 9 F (.) S 
  2215. 2880 5108 P (If) S 50 J ( a selection preference in the middle of a rule is immediately followed by an action, only) S 
  2216. 2880 5348 P (one dummy rule is created to handle both the action and the preference.) S 
  2217. 2880 5788 P (In most cases, a selection preference counts as a ) S 0 12 F 0 9 F ($N) S 0 12 F 8 9 F () S 50 J ( symbol, but it has no associated) S 
  2218. 2880 6028 P (value.  For example, in) S 
  2219. 3600 6448 P 0 12 F 0 9 F (expr) S 108 J ( : expr ['+' '-'] op expr) S 
  2220. 2880 6888 P 0 12 F 8 9 F (we) S 50 J ( have) S 
  2221. 3600 7308 P 0 12 F 0 9 F ($1) S 108 J ( -- ) S 0 12 F 8 9 F (first) S 0 12 F 0 9 F () S 108 J ( "expr") S 
  2222. 3600 7528 P ($2 -- ) S 0 12 F 8 9 F (no) S 50 J ( value) S 
  2223. 3600 7748 P 0 12 F 0 9 F ($3) S 108 J ( -- "op") S 
  2224. 3600 7968 P ($4 -- ) S 0 12 F 8 9 F (second) S 0 12 F 0 9 F () S 108 J ( "expr") S 
  2225. 2880 8408 P 0 12 F 8 9 F (If) S 50 J ( the preference is followed by an action, the preference and the action count as a single) S 
  2226. 2880 8648 P 0 12 F 0 9 F ($N) S 0 12 F 8 9 F () S 50 J ( symbol whose value is equal to the ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( value of the action.  For example, in) S 
  2227. 3600 9068 P 0 12 F 0 9 F (expr) S 108 J ( : expr ['+' '-'] {action} op expr) S 
  2228. 2880 9508 P 0 12 F 8 9 F (we) S 50 J ( have) S 
  2229. 3600 9928 P 0 12 F 0 9 F ($1) S 108 J ( -- ) S 0 12 F 8 9 F (first) S 0 12 F 0 9 F () S 108 J ( "expr") S 
  2230. 3600 10148 P ($2 -- $$) S 0 12 F 8 9 F () S 50 J ( of) S 0 12 F 0 9 F () S 108 J ( action) S 
  2231. 3600 10368 P ($3 -- op) S 
  2232. 3600 10588 P ($4 -- ) S 0 12 F 8 9 F (second) S 0 12 F 0 9 F () S 108 J ( "expr") S 
  2233. 2880 11028 P 0 12 F 8 9 F (The) S 50 J ( ) S 0 12 F 0 9 F B (%prec) S E 0 12 F 8 9 F () S 50 J ( construct is incompatible with rules that contain selection preferences,) S 
  2234. 2880 11268 P (because the preference is all that is needed to resolve conflicts.  For this reason, YAY) S 
  2235. 2880 11508 P (issues an error message if a rule contains both a preference and the ) S 0 12 F 0 9 F B (%prec) S E 0 12 F 8 9 F () S 50 J ( construct.) S 
  2236. 2880 11948 P (Selection preferences can be used to resolve most conflicts.  Indeed, there may be cases) S 
  2237. 2880 12188 P (where the most practical course of action is to write a number of conflicting rules that) S 
  2238. 2880 12428 P (contain selection preferences to resolve the conflicts, as in) S 
  2239. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2240. 2880 14800 P 0 12 F 24 10 F (57) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2241. PE 
  2242. 2880 1948 P 0 9 F (expr) S 108 J ( : expr ['+' '-'] op expr) S 
  2243. 2880 2168 P (     | expr ['*' '/' '%'] op expr) S 
  2244. 2880 2388 P (     | expr ['&' '|'] op expr) S 
  2245. 2880 2608 P (              ...) S 
  2246. 2160 3048 P 0 12 F 0 9 F B (Note:) S E 0 12 F 8 9 F () S 50 J ( selection preferences of the form) S 
  2247. 2880 3468 P 0 12 F 0 9 F ([error]) S 
  2248. 2880 3688 P ([^) S 108 J ( error]) S 
  2249. 2160 4128 P 0 12 F 8 9 F (are) S 50 J ( not useful.  Selection preferences are implemented through \(dummy\) Reduce actions,) S 
  2250. 2160 4368 P (but the parser's error-handling routines always look for Shift actions and ignore) S 
  2251. 2160 4608 P (Reductions.) S 
  2252. 2160 5428 P 0 12 F 8 12 F B (9.4) S 67 J (  Negative Numbers in $N Constructs) S E 
  2253. 2160 6148 P 0 12 F 8 9 F (YAY) S 50 J ( lets you use constructs like ) S 0 12 F 0 9 F ($0) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ($-1) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ($-2) S 0 12 F 8 9 F (,) S 50 J ( and so on in recognition actions.  These) S 
  2254. 2160 6388 P (were once important, but the techniques for specifying multiple actions have made them) S 
  2255. 2160 6628 P (obsolete.  YAY only supports the constructs for compatibility with older grammars.) S 
  2256. 2160 7068 P (To understand what these constructs mean, it is important to think in terms of the state) S 
  2257. 2160 7308 P (stack.  Each ) S 0 12 F 0 9 F ($N) S 0 12 F 8 9 F () S 50 J ( construct is associated with a state on the stack; the value of ) S 0 12 F 0 9 F ($N) S 0 12 F 8 9 F () S 50 J ( is the) S 
  2258. 2160 7548 P (value of the token or non-terminal symbol associated with the state at the time of a) S 
  2259. 2160 7788 P (Reduce operation.  \(Recall that recognition actions are executed when the appropriate) S 
  2260. 2160 8028 P (Reduce action takes place.\)) S 
  2261. 2160 8468 P 0 12 F 0 9 F ($1) S 0 12 F 8 9 F () S 50 J ( is the value associated with the state that found the first component of the grammar) S 
  2262. 2160 8708 P (rule; ) S 0 12 F 0 9 F ($2) S 0 12 F 8 9 F () S 50 J ( is the value associated with the second state, and so on.) S 
  2263. 2160 9148 P 0 12 F 0 9 F ($0) S 0 12 F 8 9 F () S 50 J ( is the value associated with the state that was on top of the stack before the first) S 
  2264. 2160 9388 P (component of the grammar rule was found.) S 
  2265. 2160 9828 P 0 12 F 0 9 F ($-1) S 0 12 F 8 9 F () S 50 J ( is the value associated with the state before that, and so on. All of these states are) S 
  2266. 2160 10068 P (still on the stack, and their value can be obtained in this way.) S 
  2267. 2160 10508 P (As an artificial example, suppose that a grammar has the rules) S 
  2268. 2880 10928 P 0 12 F 0 9 F (stmt) S 108 J ( : IF condition stmt) S 
  2269. 2880 11148 P (     | WHILE condition stmt) S 
  2270. 2880 11368 P (condition : /* something */) S 
  2271. 2880 11588 P (          { /* action */ }) S 
  2272. 2160 12028 P 0 12 F 8 9 F (The) S 50 J ( action associated with the condition can use the ) S 0 12 F 0 9 F ($-1) S 0 12 F 8 9 F () S 50 J ( construct to find out if the) S 
  2273. 2160 12268 P (preceding token was ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (WHILE) S 0 12 F 8 9 F (.) S 50 J (  \(Of course, this assumes that the only items that can) S 
  2274. 2160 12508 P (precede a condition are the ) S 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (WHILE) S 0 12 F 8 9 F () S 50 J ( tokens.\)  There are occasionally times when) S 
  2275. 2160 12748 P (this sort of information is needed.) S 
  2276. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2277. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 58) S 0 12 F 
  2278. PE 
  2279. 2880 2308 P 8 12 F B (9.5) S 67 J (  Lists and Handling Null Strings) S E 
  2280. 2880 3028 P 0 12 F 8 9 F (Grammars) S 50 J ( often define lists of items.  There are two common ways to do this:) S 
  2281. 3600 3448 P 0 12 F 0 9 F (list) S 108 J ( : item) S 
  2282. 3600 3668 P (     | list item ;) S 
  2283. 2880 4108 P 0 12 F 8 9 F (or) S 
  2284. 3600 4528 P 0 12 F 0 9 F (list) S 108 J ( : /* null */) S 
  2285. 3600 4748 P (     | list item ;) S 
  2286. 2880 5188 P 0 12 F 8 9 F (The) S 50 J ( first definition means that every "list" has at least one item.  The second allows zero-) S 
  2287. 2880 5428 P (length lists.) S 
  2288. 2880 5868 P (Using the second definition is sometimes necessary or convenient, but it can lead to) S 
  2289. 2880 6108 P (difficulties.  To understand why, consider a grammar with) S 
  2290. 3600 6528 P 0 12 F 0 9 F (list1) S 108 J ( : /* null */) S 
  2291. 3600 6748 P (      | list1 item1 ;) S 
  2292. 3600 6968 P (list2 : /* null */) S 
  2293. 3600 7188 P (      | list2 item2 ;) S 
  2294. 3600 7408 P (list  : list1) S 
  2295. 3600 7628 P (      | list2 ;) S 
  2296. 2880 8068 P 0 12 F 8 9 F (When) S 50 J ( the parser is in a position to look for a ) S 0 12 F 0 9 F ("list") S 0 12 F 8 9 F (,) S 50 J ( it automatically finds a null string,) S 
  2297. 2880 8308 P (then gets a conflict because it can't decide if the null string is an instance of ) S 0 12 F 0 9 F ("list1") S 0 12 F 8 9 F () S 50 J ( or) S 
  2298. 2880 8548 P 0 12 F 0 9 F ("list2") S 0 12 F 8 9 F (.) S 50 J (  This problem is less likely to happen if you define) S 
  2299. 3600 8968 P 0 12 F 0 9 F (list1) S 108 J ( : item1) S 
  2300. 3600 9188 P (      | list1 item1 ;) S 
  2301. 3600 9408 P (list2 : item2) S 
  2302. 3600 9628 P (      | list2 item2 ;) S 
  2303. 3600 9848 P (list  : /* null */) S 
  2304. 3600 10068 P (      | list1) S 
  2305. 3600 10288 P (      | list2) S 
  2306. 3600 10508 P (      ;) S 
  2307. 2880 10948 P 0 12 F 8 9 F (The) S 50 J ( parser can determine if it has a ) S 0 12 F 0 9 F ("list1") S 0 12 F 8 9 F () S 50 J ( or a ) S 0 12 F 0 9 F ("list2") S 0 12 F 8 9 F () S 50 J ( by seeing if the list starts with) S 
  2308. 2880 11188 P 0 12 F 0 9 F ("item1") S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F ("item2") S 0 12 F 8 9 F (.) S 
  2309. 2880 11628 P (A) S 50 J ( YAY-produced parser avoids infinite recursions that might result from matching the) S 
  2310. 2880 11868 P (same null string over and over again.  If the parser matches a null string in a particular) S 
  2311. 2880 12108 P (state, goes through a few more states and shifts once more into the state where the null) S 
  2312. 2880 12348 P (string was matched, it will not match the null string again.  Without this behaviour, you get) S 
  2313. 2880 12588 P (infinite recursions on null strings.  However, the behaviour occasionally gets in the way if) S 
  2314. 2880 12828 P (you ) S 0 12 F 8 9 F I (want) S E 0 12 F 8 9 F () S 50 J ( to match more than one null string in a row.  For example, consider how you) S 
  2315. 2880 13068 P (might write the grammar rules for types that may be used in a C cast operation, as in) S 
  2316. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2317. 2880 14800 P 0 12 F 24 10 F (59) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2318. PE 
  2319. 2880 2148 P 0 9 F (char_ptr) S 108 J ( = \(char *\) float_ptr;) S 
  2320. 2160 2588 P 0 12 F 8 9 F (The) S 50 J ( rules for the parenthesized cast expression might be written as) S 
  2321. 2880 3008 P 0 12 F 0 9 F (cast) S 108 J ( : '\(' basic_type opt_abstract '\)' ;) S 
  2322. 2880 3228 P (opt_abstract : /* null */) S 
  2323. 2880 3448 P (             | abstract;) S 
  2324. 2880 3668 P (abstract : '\(' abstract '\)') S 
  2325. 2880 3888 P (         | opt_abstract '[' ']') S 
  2326. 2880 4108 P (         | opt_abstract '\(' '\)') S 
  2327. 2880 4328 P (         | '*' opt_abstract) S 
  2328. 2880 4548 P (         ;) S 
  2329. 2160 4988 P 0 12 F 8 9 F (Consider) S 50 J ( what happens with a cast like) S 
  2330. 2880 5408 P 0 12 F 0 9 F (\(int) S 108 J ( *[]\)) S 
  2331. 2160 5848 P 0 12 F 8 9 F (This) S 50 J ( will be interpreted as ) S 0 12 F 0 9 F (*) S 0 12 F 8 9 F () S 50 J ( followed by a null ) S 0 12 F 0 9 F ("opt_abstract") S 0 12 F 8 9 F () S 50 J ( followed by a null) S 
  2332. 2160 6088 P 0 12 F 0 9 F ("opt_abstract") S 0 12 F 8 9 F () S 50 J ( followed by square brackets.  However, the parser will ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( accept two) S 
  2333. 2160 6328 P (null ) S 0 12 F 0 9 F ("opt_abstracts") S 0 12 F 8 9 F () S 50 J ( in a row, and will take some other course of action.) S 
  2334. 2160 6768 P (To correct this problem, you must rewrite the grammar rules.  Instead of using the) S 
  2335. 2160 7008 P 0 12 F 0 9 F ("opt_abstract") S 0 12 F 8 9 F () S 50 J ( rules, have rules with and without an ) S 0 12 F 0 9 F ("abstract") S 0 12 F 8 9 F (.) S 
  2336. 2880 7428 P 0 12 F 0 9 F (cast) S 108 J ( : '\(' basic_type abstract '\)' ;) S 
  2337. 2880 7648 P (abstract : /* null */) S 
  2338. 2880 7868 P (         | abstract '[' ']') S 
  2339. 2880 8088 P (         | '[' ']') S 
  2340. 2880 8308 P (         | abstract '\(' '\)') S 
  2341. 2880 8528 P (         | '\(' '\)') S 
  2342. 2880 8748 P (         | '*' abstract) S 
  2343. 2880 8968 P (         | '*') S 
  2344. 2880 9188 P (         ;) S 
  2345. 2160 10008 P 0 12 F 8 12 F B (9.6) S 67 J (  Right vs. Left Recursion) S E 
  2346. 2160 10728 P 0 12 F 8 9 F (Chapter) S 50 J ( 3 mentioned left and right recursion.  For example, if a program consists of a) S 
  2347. 2160 10968 P (number of statements separated by semicolons, we might define it with right recursion as) S 
  2348. 2880 11388 P 0 12 F 0 9 F (program) S 108 J ( : statement) S 
  2349. 2880 11608 P (        | statement ';' program ;) S 
  2350. 2160 12048 P 0 12 F 8 9 F (or) S 50 J ( with left recursion as) S 
  2351. 2880 12468 P 0 12 F 0 9 F (program) S 108 J ( : statement) S 
  2352. 2880 12688 P (        | program ';' statement ;) S 
  2353. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2354. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 60) S 0 12 F 
  2355. PE 
  2356. 2880 1968 P 8 9 F (If) S 50 J ( you think about the way that the state stack works, you will see that the second way is) S 
  2357. 2880 2208 P (much to be preferred.  Consider, for example, the way something like) S 
  2358. 3600 2628 P 0 12 F 0 9 F (S1) S 108 J ( ; S2 ; S3 ; S4) S 
  2359. 2880 3068 P 0 12 F 8 9 F (would) S 50 J ( be handled \(where all the ) S 0 12 F 0 9 F (Sn) S 0 12 F 8 9 F ('s) S 50 J ( are statements\).) S 
  2360. 2880 3508 P (With right recursion, the parser would gather ) S 0 12 F 0 9 F ("S1;") S 0 12 F 8 9 F () S 50 J ( and then go looking for a program.) S 
  2361. 2880 3748 P (To gather this program, it would gather ) S 0 12 F 0 9 F (S2) S 0 12 F 8 9 F (.) S 50 J (  It would then look at the lookahead symbol ) S 0 12 F 0 9 F (;) S 
  2362. 2880 3988 P 0 12 F 8 9 F (and) S 50 J ( see that this program had the form) S 
  2363. 3600 4408 P 0 12 F 0 9 F (statement) S 108 J ( ';' program) S 
  2364. 2880 4848 P 0 12 F 8 9 F (The) S 50 J ( parser would then go ahead and gather the program after the semicolon.  But after) S 
  2365. 2880 5088 P 0 12 F 0 9 F (S3) S 0 12 F 8 9 F (,) S 50 J ( it would find another semicolon, so would begin gathering yet another program.  If you) S 
  2366. 2880 5328 P (work the process through, you will find that the state stack grows to seven entries \(one for) S 
  2367. 2880 5568 P (each ) S 0 12 F 0 9 F (Sn) S 0 12 F 8 9 F () S 50 J ( and one for each ) S 0 12 F 0 9 F (;) S 0 12 F 8 9 F (\)) S 50 J ( before the first Reduce takes place.) S 
  2368. 2880 6008 P (On the other hand, if you have the left recursion) S 
  2369. 3600 6428 P 0 12 F 0 9 F (program) S 108 J ( : program ';' statement) S 
  2370. 2880 6868 P 0 12 F 8 9 F (and) S 50 J ( the same input, the parser will perform a Reduce as soon as it sees) S 
  2371. 3600 7288 P 0 12 F 0 9 F (S1) S 108 J ( ; S2) S 
  2372. 2880 7728 P 0 12 F 8 9 F (This) S 50 J ( is Reduced to a single state corresponding to the non-terminal symbol ) S 0 12 F 0 9 F ("program") S 0 12 F 8 9 F (.) S 
  2373. 2880 7968 P (The) S 50 J ( parser reads ) S 0 12 F 0 9 F (";S3") S 0 12 F 8 9 F () S 50 J ( and Reduces) S 
  2374. 3600 8388 P 0 12 F 0 9 F (program) S 108 J ( ; S3) S 
  2375. 2880 8828 P 0 12 F 8 9 F (to) S 50 J ( ) S 0 12 F 0 9 F ("program") S 0 12 F 8 9 F () S 50 J ( again.  The process repeats for the last statement.) S 
  2376. 2880 9268 P (If you follow this through, the state stack never grows longer than three states, as) S 
  2377. 2880 9508 P (compared to the seven that are required for the right recursive rule.  With right recursion,) S 
  2378. 2880 9748 P (no reduction takes place until the entire list of elements has been read; with left recursion,) S 
  2379. 2880 9988 P (a reduction takes place as each new list element is encountered.  Left recursion can) S 
  2380. 2880 10228 P (therefore save a lot of stack space.) S 
  2381. 2880 10668 P (The choice of left or right recursion can also affect the order in which recognition actions) S 
  2382. 2880 10908 P (are performed.  Suppose ) S 0 12 F 0 9 F (T) S 0 12 F 8 9 F () S 50 J ( is a token.  If we define) S 
  2383. 3600 11328 P 0 12 F 0 9 F (x) S 108 J ( : /* null */) S 
  2384. 3600 11548 P (  | y ',' x {a1} ;) S 
  2385. 3600 11768 P (y : T {a2} ;) S 
  2386. 2880 12208 P 0 12 F 8 9 F (then) S 50 J ( the input) S 
  2387. 3600 12628 P 0 12 F 0 9 F (T) S 108 J ( , T , T) S 
  2388. 2880 13068 P 0 12 F 8 9 F (would) S 50 J ( execute recognition actions in the order) S 
  2389. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2390. 2880 14800 P 0 12 F 24 10 F (61) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2391. PE 
  2392. 2880 2148 P 0 9 F ({a2}) S 108 J ( {a2} {a2} {a1} {a1} {a1}) S 
  2393. 2160 2588 P 0 12 F 8 9 F (The) S 50 J ( ) S 0 12 F 0 9 F ({a2}) S 0 12 F 8 9 F () S 50 J ( actions are performed each time a ) S 0 12 F 0 9 F (T) S 0 12 F 8 9 F () S 50 J ( is Reduced to ) S 0 12 F 0 9 F ("y") S 0 12 F 8 9 F (.) S 50 J (  The ) S 0 12 F 0 9 F ({a1}) S 0 12 F 8 9 F () S 50 J ( actions) S 
  2394. 2160 2828 P (don't happen until the entire list has been read, because right recursion reads the entire) S 
  2395. 2160 3068 P (list before any Reduce actions take place.) S 
  2396. 2160 3508 P (On the other hand, if you define) S 
  2397. 2880 3928 P 0 12 F 0 9 F (x) S 108 J ( : /* null */) S 
  2398. 2880 4148 P (  | x ',' y {a1} ;) S 
  2399. 2880 4368 P (y : T {a2};) S 
  2400. 2160 4808 P 0 12 F 8 9 F (the) S 50 J ( recognition actions for the same input will take place in the order) S 
  2401. 2880 5228 P 0 12 F 0 9 F ({a2}) S 108 J ( {a1} {a2} {a1} {a2} {a1}) S 
  2402. 2160 5668 P 0 12 F 8 9 F (With) S 50 J ( left recursion, Reduce actions take place every time a new element is read in for the) S 
  2403. 2160 5908 P (list.) S 
  2404. 2160 6348 P (This means that if you want the action order) S 
  2405. 2880 6768 P 0 12 F 0 9 F ({a2}) S 108 J ( {a2} {a2} {a1} {a1} {a1}) S 
  2406. 2160 7208 P 0 12 F 8 9 F (you) S 50 J ( must use right recursion even though it takes more stack space.) S 
  2407. 2160 8028 P 0 12 F 8 12 F B (9.7) S 67 J (  YYDEBUG) S E 
  2408. 2160 8748 P 0 12 F 8 9 F (If) S 50 J ( you ) S 0 12 F 0 9 F B (#define) S E 0 12 F 8 9 F () S 50 J ( a symbol named ) S 0 12 F 0 9 F (YYDEBUG) S 0 12 F 8 9 F () S 50 J ( in the declarations section and set the variable) S 
  2409. 2160 8988 P 0 12 F 0 9 F ("yydebug") S 0 12 F 8 9 F () S 50 J ( to a non-zero value, your parser will print a good deal of debugging) S 
  2410. 2160 9228 P (information as it parses input.  In this description, we will describe the output you may see.) S 
  2411. 2160 9668 P (Every time ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( obtains a token, the parser prints) S 
  2412. 2880 10088 P 0 12 F 0 9 F (read) S 108 J ( T \(VALUE\)) S 
  2413. 2160 10528 P (T) S 0 12 F 8 9 F () S 50 J ( is the name of the token and ) S 0 12 F 0 9 F (VALUE) S 0 12 F 8 9 F () S 50 J ( is the numeric value.  Thus if ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( has read an) S 
  2414. 2160 10768 P 0 12 F 0 9 F (IF) S 0 12 F 8 9 F () S 50 J ( token, you might see) S 
  2415. 2880 11188 P 0 12 F 0 9 F (read) S 108 J ( IF \(257\)) S 
  2416. 2160 11628 P 0 12 F 8 9 F (Every) S 50 J ( time the parser enters a state, it will print out) S 
  2417. 2880 12048 P 0 12 F 0 9 F (state) S 108 J ( N \(X\), char \(C\)) S 
  2418. 2160 12488 P 0 12 F 8 9 F (where) S 50 J ( ) S 0 12 F 0 9 F (N) S 0 12 F 8 9 F () S 50 J ( is the state number as given in the State Description report, and ) S 0 12 F 0 9 F (X) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (C) S 0 12 F 8 9 F () S 50 J ( are) S 
  2419. 2160 12728 P (other integers.  ) S 0 12 F 0 9 F (X) S 0 12 F 8 9 F () S 50 J ( is another number for the state -- YAY actually renumbers the states and) S 
  2420. 2160 12968 P (grammar rules after it generates the State Description report in order to improve the) S 
  2421. 2160 13208 P (parser's efficiency, and ) S 0 12 F 0 9 F (X) S 0 12 F 8 9 F () S 50 J ( gives the state number after renumbering.  ) S 0 12 F 0 9 F (C) S 0 12 F 8 9 F () S 50 J ( is the token type of) S 
  2422. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2423. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 62) S 0 12 F 
  2424. PE 
  2425. 2880 1968 P 8 9 F (the) S 50 J ( lookahead symbol if the symbol is a token.  If the symbol is not a token, or if there is) S 
  2426. 2880 2208 P (no lookahead symbol at the moment, ) S 0 12 F 0 9 F (C) S 0 12 F 8 9 F () S 50 J ( is ) S 0 12 F 0 9 F (-1) S 0 12 F 8 9 F (.) S 50 J (  As an example,) S 
  2427. 3600 2628 P 0 12 F 0 9 F (state) S 108 J ( 6 \(22\), char \(-1\)) S 
  2428. 2880 3068 P 0 12 F 8 9 F (indicates) S 50 J ( that the parser has entered State 6 on the State Description Report \(State 22) S 
  2429. 2880 3308 P (after renumbering\) and that the current lookahead symbol is not a token.) S 
  2430. 2880 3748 P (Every time the parser performs a Shift action, it prints) S 
  2431. 3600 4168 P 0 12 F 0 9 F (shift) S 108 J ( N \(X\)) S 
  2432. 2880 4608 P 0 12 F 8 9 F (where) S 50 J ( ) S 0 12 F 0 9 F (N) S 0 12 F 8 9 F () S 50 J ( is the number of the state to which the parser is shifting and ) S 0 12 F 0 9 F (X) S 0 12 F 8 9 F () S 50 J ( is the number of) S 
  2433. 2880 4848 P (the same state after renumbering.) S 
  2434. 2880 5288 P (Every time the parser performs a Reduce action, it prints) S 
  2435. 3600 5708 P 0 12 F 0 9 F (reduce) S 108 J ( N \(X\), pops M \(Y\)) S 
  2436. 2880 6148 P 0 12 F 8 9 F (This) S 50 J ( says that the parser has Reduced by grammar rule ) S 0 12 F 0 9 F (N) S 0 12 F 8 9 F () S 50 J ( \(renumbered to ) S 0 12 F 0 9 F (X) S 0 12 F 8 9 F (\).) S 50 J (  After the) S 
  2437. 2880 6388 P (reduction, the state on top of the state stack was State ) S 0 12 F 0 9 F (M) S 0 12 F 8 9 F () S 50 J ( \(renumbered to ) S 0 12 F 0 9 F (Y) S 0 12 F 8 9 F (\).) S 
  2438. 2880 7208 P 0 12 F 8 12 F B (9.8) S 67 J (  Important Symbols) S E 
  2439. 2880 7928 P 0 12 F 8 9 F (Debugging) S 50 J ( a parser produced by YAY can be a very difficult task, since the code is only) S 
  2440. 2880 8168 P (partly produced by user input.  The remaining code is standard software produced by YAY) S 
  2441. 2880 8408 P (itself.  The situation is aggravated by another problem: the state and rule numbers shown) S 
  2442. 2880 8648 P (in the State Description report are not the same as the numbers used when the parser) S 
  2443. 2880 8888 P (actually runs.  In the interests of optimization, the parser sorts the states into a more) S 
  2444. 2880 9128 P (convenient order.  Thus the ) S 0 12 F 8 9 F I (internal) S E 0 12 F 8 9 F () S 50 J ( state number used by the program is usually not the) S 
  2445. 2880 9368 P (same as the ) S 0 12 F 8 9 F I (external) S E 0 12 F 8 9 F () S 50 J ( state number known to the user.) S 
  2446. 2880 9808 P (To help those who are examining parser code using a symbolic debugger, here are a few) S 
  2447. 2880 10048 P (of the important variables that the parser uses.) S 
  2448. 2880 10488 P 0 12 F 0 9 F (yyval) S 
  2449. 3600 10728 P 0 12 F 8 9 F (holds) S 50 J ( the value ) S 0 12 F 0 9 F ($$) S 0 12 F 8 9 F () S 50 J ( at the time of a reduction.  This has the type ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F (.) S 
  2450. 2880 11168 P 0 12 F 0 9 F (yychar) S 
  2451. 3600 11408 P 0 12 F 8 9 F (holds) S 50 J ( the most recent token value returned by ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F (.) S 
  2452. 2880 11848 P 0 12 F 0 9 F (yystate) S 
  2453. 3600 12088 P 0 12 F 8 9 F (is) S 50 J ( the ) S 0 12 F 8 9 F I (internal) S E 0 12 F 8 9 F () S 50 J ( number of the current state.) S 
  2454. 2880 12528 P 0 12 F 0 9 F (yyps) S 
  2455. 3600 12768 P 0 12 F 8 9 F (points) S 50 J ( to the current top of the state stack.  Thus ) S 0 12 F 0 9 F (yyps[0]) S 0 12 F 8 9 F () S 50 J ( is the internal number) S 
  2456. 3600 13008 P (of the current state, ) S 0 12 F 0 9 F (yyps[-1]) S 0 12 F 8 9 F () S 50 J ( is the internal number of the previous state, and) S 
  2457. 3600 13248 P (so on.) S 
  2458. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2459. 2880 14800 P 0 12 F 24 10 F (63) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2460. PE 
  2461. 2160 2168 P 0 9 F (yypv) S 
  2462. 2880 2408 P 0 12 F 8 9 F (points) S 50 J ( to the top of the current value stack.  The entries in this stack have the) S 
  2463. 2880 2648 P (type ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F (.) S 50 J (  When a Reduce operation executes a recognition action, this) S 
  2464. 2880 2888 P (pointer is moved down the stack to the point where) S 
  2465. 2880 3308 P 0 12 F 0 9 F (yypv[1]) S 108 J ( = $1) S 
  2466. 2880 3528 P (yypv[2] = $2) S 
  2467. 2880 3748 P (    etc.) S 
  2468. 2160 4188 P (yyi) S 
  2469. 2880 4428 P 0 12 F 8 9 F (is) S 50 J ( the internal number of the rule being reduced by a Reduce action.) S 
  2470. 2160 4868 P 0 12 F 0 9 F (yyrmap) S 
  2471. 2880 5108 P 0 12 F 8 9 F (is) S 50 J ( an array present only when ) S 0 12 F 0 9 F (YYDEBUG) S 0 12 F 8 9 F () S 50 J ( is defined.  It is used to convert internal) S 
  2472. 2880 5348 P (rule numbers to external ones.  For example,) S 
  2473. 2880 5768 P 0 12 F 0 9 F (yyrmap[yyi]) S 
  2474. 2880 6208 P 0 12 F 8 9 F (is) S 50 J ( the external number of the rule being reduced by a Reduce action.) S 
  2475. 2160 6648 P 0 12 F 0 9 F (yysmap) S 
  2476. 2880 6888 P 0 12 F 8 9 F (is) S 50 J ( an array present only when ) S 0 12 F 0 9 F (YYDEBUG) S 0 12 F 8 9 F () S 50 J ( is defined.  It is used to convert internal) S 
  2477. 2880 7128 P (state numbers to external ones.  For example,) S 
  2478. 2880 7548 P 0 12 F 0 9 F (yysmap[yystate]) S 
  2479. 2880 7988 P 0 12 F 8 9 F (is) S 50 J ( the external number of the current state.) S 
  2480. 2160 8808 P 0 12 F 8 12 F B (9.9) S 67 J (  How YYERROR May Be Used) S E 
  2481. 2160 9528 P 0 12 F 8 9 F (The) S 50 J ( ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( macro creates an artificial error condition.  To show how this can be useful,) S 
  2482. 2160 9768 P (suppose we have a line-by-line desk calculator that allows parenthesization of expressions) S 
  2483. 2160 10008 P (and suppose we have a variable named ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F () S 50 J ( that keeps track of how deeply) S 
  2484. 2160 10248 P (parentheses are nested.  Every time the parser finds an opening parenthesis, it adds 1 to) S 
  2485. 2160 10488 P 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F (.) S 50 J (  Every time it finds a closing parenthesis, it subtracts 1.) S 
  2486. 2160 10928 P (Consider how the following definitions will work.) S 
  2487. 2880 11348 P 0 12 F 0 9 F (expr) S 108 J ( : lp expr '\)') S 
  2488. 2880 11568 P (          {depth--;}) S 
  2489. 2880 11788 P (     | lp error) S 
  2490. 2880 12008 P (          {depth--;}) S 
  2491. 2880 12228 P (     ;) S 
  2492. 2880 12448 P (lp : '\(' {depth++;};) S 
  2493. 2160 12888 P 0 12 F 8 9 F (If) S 50 J ( no error occurs, the ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F () S 50 J ( variable is incremented and decremented correctly.  If an) S 
  2494. 2160 13128 P (error does occur, however, what happens?  Your ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( routine is called on to) S 
  2495. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2496. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 64) S 0 12 F 
  2497. PE 
  2498. 2880 1968 P 8 9 F (recover) S 50 J ( from the error in the middle of an expression.  Often, it is more reasonable to) S 
  2499. 2880 2208 P (postpone this recovery until you reach a point where you have a whole expression.) S 
  2500. 2880 2448 P (Therefore, you might use the following alternate definition.) S 
  2501. 3600 2868 P 0 12 F 0 9 F (expr) S 108 J ( : lp error) S 
  2502. 3600 3088 P (          {depth--; YYERROR;}) S 
  2503. 3600 3308 P (     ;) S 
  2504. 3600 3528 P (line : error '\\n' prompt line) S 
  2505. 3600 3748 P (       { $$ = $4; } ;) S 
  2506. 3600 3968 P (prompt : /* null token */) S 
  2507. 3600 4188 P (       {printf\("Please re-enter line.\\n"\);};) S 
  2508. 2880 4628 P 0 12 F 8 9 F (Now,) S 50 J ( what happens when the grammar is asked to parse a line like) S 
  2509. 3600 5048 P 0 12 F 0 9 F (1) S 108 J ( + \(\( a +) S 
  2510. 2880 5488 P 0 12 F 8 9 F (When) S 50 J ( the end of the line is encountered, the parser recognizes an error has occurred.) S 
  2511. 2880 5728 P (Going up the stack, the first state ready to handle the error is) S 
  2512. 3600 6148 P 0 12 F 0 9 F (expr) S 108 J ( : lp error ;) S 
  2513. 2880 6588 P 0 12 F 8 9 F (At) S 50 J ( this point, the parser will Reduce the input) S 
  2514. 3600 7008 P 0 12 F 0 9 F (\() S 108 J ( a +) S 
  2515. 2880 7448 P 0 12 F 8 9 F (into) S 50 J ( an ) S 0 12 F 0 9 F ("expr") S 0 12 F 8 9 F (.) S 50 J (  The Reduction executes the recognition action: it decrements ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F (,) S 
  2516. 2880 7688 P (then) S 50 J ( signals that an error has taken place.  The Error action begins popping the stack) S 
  2517. 2880 7928 P (again.  It will find the previous opening parenthesis, recognize another) S 
  2518. 3600 8348 P 0 12 F 0 9 F (lp) S 108 J ( error) S 
  2519. 2880 8788 P 0 12 F 8 9 F (construct) S 50 J ( and perform another reduction.  The parenthesis count is again decremented,) S 
  2520. 2880 9028 P (and another error condition generated.) S 
  2521. 2880 9468 P (This time, the grammar rule that deals with the error is the definition of ) S 0 12 F 0 9 F ("line") S 0 12 F 8 9 F (.) S 50 J (  An error) S 
  2522. 2880 9708 P (message is issued and a new line is requested.  In this way, the parser has worked its way) S 
  2523. 2880 9948 P (back to error-handling code that can deal with the situation.  Along the way, the parser) S 
  2524. 2880 10188 P (correctly decremented the ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F () S 50 J ( variable to account for the missing parentheses.) S 
  2525. 2880 10628 P (This method of dealing with errors decrements ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F () S 50 J ( for every unbalanced opening) S 
  2526. 2880 10868 P (parenthesis on the line.  This corrects the ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F () S 50 J ( count properly.  Our first definition) S 
  2527. 2880 11108 P (\(without the ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( call\) would only have decremented ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F () S 50 J ( once.) S 
  2528. 2880 11548 P (This example is somewhat contrived, of course -- you could always just set ) S 0 12 F 0 9 F ("depth") S 0 12 F 8 9 F () S 50 J ( to) S 
  2529. 2880 11788 P (zero whenever you started a new line of input.  The usefulness of the technique is more) S 
  2530. 2880 12028 P (apparent in situations where you obtain memory with ) S 0 12 F 0 9 F ("malloc") S 0 12 F 8 9 F () S 50 J ( whenever you get an) S 
  2531. 2880 12268 P (opening delimiter and free the memory with ) S 0 12 F 0 9 F ("free") S 0 12 F 8 9 F () S 50 J ( whenever you get a closing delimiter.) S 
  2532. 2880 12508 P (In this case, it is obvious that you need to do precisely as many ) S 0 12 F 0 9 F ("free") S 0 12 F 8 9 F () S 50 J ( operations as) S 
  2533. 2880 12748 P 0 12 F 0 9 F ("malloc") S 0 12 F 8 9 F () S 50 J ( operations, so you must raise the error condition for each unbalanced opening) S 
  2534. 2880 12988 P (delimiter.) S 
  2535. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2536. 2880 14800 P 0 12 F 24 10 F (65) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2537. PE 
  2538. 2160 1968 P 8 9 F (You) S 50 J ( might think that the symbol ) S 0 12 F 0 9 F ("lp") S 0 12 F 8 9 F () S 50 J ( is unnecessary, and you could just define) S 
  2539. 2880 2388 P 0 12 F 0 9 F (expr) S 108 J ( : '\(' {depth++;} expr '\)' {depth--;}) S 
  2540. 2880 2608 P (     | '\(' error {depth--;} ;) S 
  2541. 2160 3048 P 0 12 F 8 9 F (However,) S 50 J ( this would not work in general.  There is no guarantee that the action) S 
  2542. 2880 3468 P 0 12 F 0 9 F ({depth++;}) S 
  2543. 2160 3908 P 0 12 F 8 9 F (would) S 50 J ( be executed in all cases, particularly if the token after the ) S 0 12 F 0 9 F ('\(') S 0 12 F 8 9 F () S 50 J ( was one that could) S 
  2544. 2160 4148 P (not start an expression.) S 
  2545. 2160 4588 P (As an interesting example of another way to use ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F (,) S 50 J ( consider the following \(taken) S 
  2546. 2160 4828 P (from a parser for the Pascal programming language\).) S 
  2547. 2160 5248 P 0 12 F 0 10 F (label_list) S 120 J ( : label_list ',' label) S 
  2548. 2160 5468 P (           | label) S 
  2549. 2160 5688 P (           | error) S 
  2550. 2160 5908 P (           | error [LABEL CONST VAR PROC FUNC BEGIN]) S 
  2551. 2160 6128 P (                {YYERROR; /* more code */};) S 
  2552. 2160 6568 P 0 12 F 8 9 F (This) S 50 J ( deals with errors in two different ways:) S 
  2553. 2160 7008 P (\(a\)          If an error is followed by one of the tokens ) S 0 12 F 0 9 F (LABEL) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (CONST) S 0 12 F 8 9 F (,) S 50 J ( etc. \(representing the) S 
  2554. 2880 7248 P (beginning of new declaration sections in Pascal\), the input is reduced to a) S 
  2555. 2880 7488 P (complete ) S 0 12 F 0 9 F ("label_list") S 0 12 F 8 9 F () S 50 J ( input is Reduced to a complete ) S 0 12 F 0 9 F ("label_list") S 0 12 F 8 9 F () S 50 J ( and) S 
  2556. 2880 7728 P (an appropriate action is taken.  This action uses ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( to raise the error) S 
  2557. 2880 7968 P (condition, but only ) S 0 12 F 8 9 F I (after) S E 0 12 F 8 9 F () S 50 J ( the reduction has taken place.) S 
  2558. 2160 8408 P (\(b\)          The other rule is used when the parser finds an error which is not followed by one) S 
  2559. 2880 8648 P (of the listed tokens.  This corresponds to an error in the middle of a label list and) S 
  2560. 2880 8888 P (requires a different sort of handling.  In this case, error-handling is allowed to) S 
  2561. 2880 9128 P (take place immediately, without reduction, because there may be more) S 
  2562. 2880 9368 P 0 12 F 0 9 F ("label_list") S 0 12 F 8 9 F () S 50 J ( to come.) S 
  2563. 2160 9808 P (This kind of approach can be used to distinguish different kinds of errors that may take) S 
  2564. 2160 10048 P (place in a particular situation.) S 
  2565. 2160 10868 P 0 12 F 8 12 F B (9.10) S 67 J (  The Default Action) S E 
  2566. 2160 11588 P 0 12 F 8 9 F (The) S 50 J ( default action is the one that is taken when the parser finds a token which has no) S 
  2567. 2160 11828 P (specified effect in the current state.  Understanding how default actions work will help you) S 
  2568. 2160 12068 P (understand what is going on when a YAY-produced parser encounters an error.) S 
  2569. 2160 12508 P (In a state diagram, the default action is marked with a ) S 0 12 F 0 9 F (".") S 0 12 F 8 9 F (.) S 50 J ( The default will always be a) S 
  2570. 2160 12748 P (Reduce or Error action, chosen according to the following rules.) S 
  2571. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2572. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 66) S 0 12 F 
  2573. PE 
  2574. 2880 1968 P 8 9 F (\(a\)) S 500 J ( If) S 50 J ( the state has no Shift actions and only one Reduce, the default will be the) S 
  2575. 3600 2208 P (Reduce action.) S 
  2576. 2880 2648 P (\(b\)          Apart from \(a\), an empty rule will never have Reduce as a default.) S 
  2577. 2880 3088 P (\(c\)) S 510 J ( If) S 50 J ( a state has more than one Reduce action, the parser examines the "popularity") S 
  2578. 3600 3328 P (of each Reduce.  For example, if Reduction A is used with any of three different) S 
  2579. 3600 3568 P (input tokens and Reduction B is used with only one input token, Reduction A is) S 
  2580. 3600 3808 P (three times as "popular" as B.  If one Reduce action is more than twice as) S 
  2581. 3600 4048 P (popular as its closest contender \(i.e. if it is taken on more than twice as many) S 
  2582. 3600 4288 P (input tokens\), and if that Reduce action is associated with a rule that contains) S 
  2583. 3600 4528 P (reductions on at least ) S 0 12 F 8 9 F I (five) S E 0 12 F 8 9 F () S 50 J ( tokens, the popular Reduce action is made the default.) S 
  2584. 2880 4968 P (\(d\)          In all other cases, the default action will be an Error action.  For example, Error is) S 
  2585. 3600 5208 P (chosen when a rule has more than one Reduce action, and there is no Reduce) S 
  2586. 3600 5448 P (that is more than twice as popular as all the other contenders.) S 
  2587. 2880 5888 P (Note: YAY's predecessor YACC always chooses the most popular Reduce action as) S 
  2588. 2880 6128 P (default \(if there is one\).  It does not use the same requirements as \(c\) above.  As a result) S 
  2589. 2880 6368 P (of this difference YAY's parser tables are about 20% larger than YACC's, but a YAY-) S 
  2590. 2880 6608 P (generated parser usually detects errors much earlier than a parser generated by YACC.) S 
  2591. 2880 7048 P (Because of the way default actions are treated, a YAY-produced parser will sometimes) S 
  2592. 2880 7288 P (begin reducing when it encounters an error.  Several reductions may take place before the) S 
  2593. 2880 7528 P (error state is finally triggered.  Thus your grammar may need some way to determine what) S 
  2594. 2880 7768 P (actions have taken place between the time the erroneous token was read in and the time) S 
  2595. 2880 8008 P (that the error was actually triggered.) S 
  2596. 2880 8828 P 0 12 F 8 12 F B (9.11) S 67 J (  Invalid Tokens) S E 
  2597. 2880 9548 P 0 12 F 8 9 F (It) S 50 J ( is invalid to say either) S 
  2598. 3600 9968 P 0 12 F 0 9 F (%token) S 108 J ( X 0) S 
  2599. 3600 10188 P (    or) S 
  2600. 3600 10408 P (%token X 256) S 
  2601. 2880 10848 P 0 12 F 8 9 F (The) S 50 J ( value 0 is reserved for the end marker and 256 is reserved for ) S 0 12 F 0 9 F ("error") S 0 12 F 8 9 F (.) S 
  2602. 2880 11668 P 0 12 F 8 12 F B (9.12) S 67 J (  Dynamic Stack Allocation) S E 
  2603. 2880 12388 P 0 12 F 8 9 F (The) S 50 J ( manifest ) S 0 12 F 0 9 F (YYSSIZE) S 0 12 F 8 9 F () S 50 J ( is used to determine the size of the state and value stacks used by) S 
  2604. 2880 12628 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F (.) S 50 J (  ) S 0 12 F 0 9 F (YYSSIZE) S 0 12 F 8 9 F () S 50 J ( gives the maximum number of elements that these stacks will be) S 
  2605. 2880 12868 P (expected to hold; the size of each value element is dictated by the ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F () S 50 J ( type and the) S 
  2606. 2880 13108 P (size of each state element is determined by YAY.  The default value of ) S 0 12 F 0 9 F (YYSSIZE) S 0 12 F 8 9 F () S 50 J ( is 150.) S 
  2607. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2608. 2880 14800 P 0 12 F 24 10 F (67) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2609. PE 
  2610. 2160 1968 P 8 9 F (By) S 50 J ( increasing the value of ) S 0 12 F 0 9 F (YYSSIZE) S 0 12 F 8 9 F (,) S 50 J ( you can allow for grammars with a larger number of) S 
  2611. 2160 2208 P (pending states.) S 
  2612. 2160 2648 P (If you ) S 0 12 F 0 9 F B (#define) S E 0 12 F 8 9 F () S 50 J ( ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F () S 50 J ( in the declarations section, the state and value stacks used by) S 
  2613. 2160 2888 P 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( will be allocated dynamically via ) S 0 12 F 0 9 F ("malloc") S 0 12 F 8 9 F () S 50 J ( and freed before ) S 0 12 F 0 9 F ("yyparse") S 
  2614. 2160 3128 P 0 12 F 8 9 F (returns.) S 50 J (  What this effectively means is that ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( makes itself re-entrant by saving) S 
  2615. 2160 3368 P (a number of externals when it begins execution and restoring them upon completion.  The) S 
  2616. 2160 3608 P (externals involved are) S 
  2617. 2880 4028 P 0 12 F 0 9 F (yylval) S 108 J (   yyval   yypvt) S 
  2618. 2880 4248 P (yynerrs  yychar  yyerrflag) S 
  2619. 2160 4688 P 0 12 F 8 9 F (If) S 50 J ( you ) S 0 12 F 0 9 F ("longjmp") S 0 12 F 8 9 F () S 50 J ( out of ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( \(due to an action\), the externals are ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( restored,) S 
  2620. 2160 4928 P (and ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( will not be re-entrant.) S 
  2621. 2160 5368 P (If you use ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( will be called if ) S 0 12 F 0 9 F ("malloc") S 0 12 F 8 9 F () S 50 J ( fails to allocate space for the) S 
  2622. 2160 5608 P (state and value stacks.) S 
  2623. 2160 6048 P (If you ) S 0 12 F 0 9 F B (#define) S E 0 12 F 8 9 F () S 50 J ( ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F () S 50 J ( with a value greater than 10, the parser allocates the state and) S 
  2624. 2160 6288 P (value stacks dynamically, beginning with a size of ) S 0 12 F 0 9 F (YYSSIZE) S 0 12 F 8 9 F (.) S 50 J (  If this is not big enough to) S 
  2625. 2160 6528 P (hold the two stacks, ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( attempts to use ) S 0 12 F 0 9 F ("realloc") S 0 12 F 8 9 F () S 50 J ( to grow the stacks by the) S 
  2626. 2160 6768 P (amount given by ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F (.) S 50 J (  For example, if ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F () S 50 J ( is 20, ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( tries to grow the) S 
  2627. 2160 7008 P (stacks to a size that will allow 20 additional elements \(whenever ) S 0 12 F 0 9 F ("yyparse") S 0 12 F 8 9 F () S 50 J ( needs more) S 
  2628. 2160 7248 P (space for the stacks\).  ) S 0 12 F 0 9 F ("yyerror") S 0 12 F 8 9 F () S 50 J ( is called if the call to ) S 0 12 F 0 9 F ("realloc") S 0 12 F 8 9 F () S 50 J ( fails to allocate) S 
  2629. 2160 7488 P (additional space.) S 
  2630. 2160 7928 P (If you set up your parser in such a way that it may grow the stacks, you must be careful) S 
  2631. 2160 8168 P (not to take a pointer into a stack in one action and use that pointer inside a different) S 
  2632. 2160 8408 P (action.  The reason is that the stack may be grown using ) S 0 12 F 0 9 F ("realloc") S 0 12 F 8 9 F () S 50 J ( in between the two) S 
  2633. 2160 8648 P (actions.  Since ) S 0 12 F 0 9 F ("realloc") S 0 12 F 8 9 F () S 50 J ( may actually move the entire stack, the pointer will no longer) S 
  2634. 2160 8888 P (be valid.  Thus you should not create pointers with expressions like) S 
  2635. 2880 9308 P 0 12 F 0 9 F (&\($1\)) S 
  2636. 2160 9748 P 0 12 F 8 9 F (and) S 50 J ( expect those pointers to be valid in other actions.  Within the code of a single action,) S 
  2637. 2160 9988 P (however, such pointers ) S 0 12 F 0 9 F B (will) S E 0 12 F 8 9 F () S 50 J ( remain valid.) S 
  2638. 2160 10428 P (If you ) S 0 12 F 0 9 F B (#define) S E 0 12 F 8 9 F () S 50 J ( ) S 0 12 F 0 9 F (YYSTATIC) S 0 12 F 8 9 F (,) S 50 J ( both the state and value stacks will be static.  Otherwise, the) S 
  2639. 2160 10668 P (state stack will be "auto" \(allocated on the program stack\) and the value stack will be) S 
  2640. 2160 10908 P (static.  Defining ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F () S 50 J ( saves both stack space and static space; defining ) S 0 12 F 0 9 F (YYSTATIC) S 
  2641. 2160 11148 P 0 12 F 8 9 F (saves) S 50 J ( stack space.) S 
  2642. 2160 11968 P 0 12 F 8 12 F B (9.13) S 67 J (  Synchronizing the Lookahead) S E 
  2643. 2160 12688 P 0 12 F 8 9 F (If) S 50 J ( you ) S 0 12 F 0 9 F B (#define) S E 0 12 F 8 9 F () S 50 J ( ) S 0 12 F 0 9 F (YYSYNC) S 0 12 F 8 9 F (,) S 50 J ( the parser will always have a lookahead token when it performs) S 
  2644. 2160 12928 P (a shift or reduce action.  If the symbol is not defined, the parser will only obtain a) S 
  2645. 2160 13168 P (lookahead token if the value of the token is needed.) S 
  2646. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2647. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 68) S 0 12 F 
  2648. PE 
  2649. 2880 2168 P 8 9 F (You) S 50 J ( would define ) S 0 12 F 0 9 F (YYSYNC) S 0 12 F 8 9 F () S 50 J ( in situations where you wanted to keep track of the line number) S 
  2650. 2880 2408 P (on which various situations occurred \(e.g. errors\).  If ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( ) S 0 12 F 8 9 F I (always) S E 0 12 F 8 9 F () S 50 J ( does a lookahead,) S 
  2651. 2880 2648 P (you know that the line number of the token you are working with is the line number of the) S 
  2652. 2880 2888 P (second last token read.  If ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( sometimes does not do a lookahead, you don't know) S 
  2653. 2880 3128 P (if the current line number in ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( is the line number for the current token or for a) S 
  2654. 2880 3368 P (lookahead token.) S 
  2655. 2880 3808 P (You would avoid defining ) S 0 12 F 0 9 F (YYSYNC) S 0 12 F 8 9 F () S 50 J ( in situations where some actions do their own reading.) S 
  2656. 2880 4048 P (For example, suppose that ) S 0 12 F 0 9 F (/*) S 0 12 F 8 9 F () S 50 J ( is a token that indicates the beginning of a comment.  You) S 
  2657. 2880 4288 P (could create an action for that token which reads all input up to a closing ) S 0 12 F 0 9 F (*/) S 0 12 F 8 9 F (.) S 50 J (  With this) S 
  2658. 2880 4528 P (kind of action, you would not want ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( to read a lookahead token, since that token) S 
  2659. 2880 4768 P (would be the first token inside the comment, not the first token after the comment.) S 
  2660. 2880 5588 P 0 12 F 8 12 F B (9.14) S 67 J (  YYSHIFT) S E 
  2661. 2880 6308 P 0 12 F 8 9 F (The) S 50 J ( generated parser program invokes a macro named ) S 0 12 F 0 9 F (YYSHIFT) S 0 12 F 8 9 F () S 50 J ( whenever the parser) S 
  2662. 2880 6548 P (performs a shift action in response to a token.  The macro is invoked without arguments.) S 
  2663. 2880 6788 P (By default, ) S 0 12 F 0 9 F (YYSHIFT) S 0 12 F 8 9 F () S 50 J ( is defined to do nothing; however, users can redefine ) S 0 12 F 0 9 F (YYSHIFT) S 0 12 F 8 9 F () S 50 J ( if) S 
  2664. 2880 7028 P (desired, in the token definition part of the YAY input.) S 
  2665. 2880 7468 P (As an example of how you might use ) S 0 12 F 0 9 F (YYSHIFT) S 0 12 F 8 9 F (,) S 50 J ( consider a situation where input is) S 
  2666. 2880 7708 P (freeform and may be split over many lines of text, including the insertion of blank lines in) S 
  2667. 2880 7948 P (the input.  You may want to keep a count of the number of lines you've read as you parse) S 
  2668. 2880 8188 P (the input so that you can provide error messages like "Line 12: Syntax error".) S 
  2669. 2880 8628 P (When the parser finishes reading a line, it often has to read ahead to the next token before) S 
  2670. 2880 8868 P (it can decide whether to reduce what it already has or keep on reading additional input.) S 
  2671. 2880 9108 P (Since there may be blank lines in the input, this means that the parser may actually read) S 
  2672. 2880 9348 P (ahead several lines before finding the next token.  When it sees the next token, the parser) S 
  2673. 2880 9588 P (may decide to reduce what it has seen already before shifting in response to the token.) S 
  2674. 2880 10028 P (While the reduction is happening, you want your line count to reflect the last line of input.) S 
  2675. 2880 10268 P (You do not want the line count to reflect the line where the parser found the new token,) S 
  2676. 2880 10508 P (because the parser isn't really using that token yet; it's working with older input.  You only) S 
  2677. 2880 10748 P (want to update the line count when the parser is ready to shift on the new token.) S 
  2678. 2880 11188 P (That's where ) S 0 12 F 0 9 F (YYSHIFT) S 0 12 F 8 9 F () S 50 J ( comes in.  You can define the ) S 0 12 F 0 9 F (YYSHIFT) S 0 12 F 8 9 F () S 50 J ( macro to update the line) S 
  2679. 2880 11428 P (count at the point when the token is actually used, not when it is first read.) S 
  2680. 2880 11868 P 0 12 F 0 9 F (YYSHIFT) S 0 12 F 8 9 F () S 50 J ( is ) S 0 12 F 8 9 F I (not) S E 0 12 F 8 9 F () S 50 J ( invoked if a token is discarded \(because of error handling or some other) S 
  2681. 2880 12108 P (reason\).  It is only invoked when the parser shifts on a token.) S 
  2682. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2683. 2880 14800 P 0 12 F 24 10 F (69) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2684. PE 
  2685. 7520 1968 P 8 18 F (Appendix) S 100 J ( A) S 
  2686. 7300 2448 P 0 12 F 8 18 F B (An) S 100 J ( Example) S E 
  2687. 2160 4048 P 0 12 F 8 9 F (This) S 50 J ( appendix gives a simple example of YAY input.  We have omitted the recognition) S 
  2688. 2160 4288 P (actions of the grammar rules in order to keep the example as simple as possible.) S 
  2689. 2160 4728 P (The parser implements a simple string manipulation language.  It has two types of objects:) S 
  2690. 2160 4968 P (strings and variables.  Strings can have a maximum of 100 characters and are enclosed in) S 
  2691. 2160 5208 P (double quotes.  Variable names are a maximum of eight characters long.) S 
  2692. 2160 5648 P (There are three operations:) S 
  2693. 2160 6088 P (\(a\)          ) S 0 12 F 0 9 F (=) S 0 12 F 8 9 F () S 50 J ( assigns a string to a variable;) S 
  2694. 2160 6528 P (\(b\)          ) S 0 12 F 0 9 F (JOIN) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (+) S 0 12 F 8 9 F () S 50 J ( concatenates strings or the contents of variables;) S 
  2695. 2160 6968 P (\(c\)) S 510 J ( ) S 0 12 F 0 9 F (PRINT) S 0 12 F 8 9 F () S 50 J ( outputs strings or the contents of variables.) S 
  2696. 2160 7408 P (Every statement is a single input line and blanks are used to separate tokens on the line.) S 
  2697. 2160 7648 P (Multiple ) S 0 12 F 0 9 F (=) S 0 12 F 8 9 F () S 50 J ( assignments are permitted as in) S 
  2698. 2880 8068 P 0 12 F 0 9 F (A) S 108 J ( = B = "hello") S 
  2699. 2160 8508 P 0 12 F 8 9 F (The) S 50 J ( keyword ) S 0 12 F 0 9 F (PRINT) S 0 12 F 8 9 F () S 50 J ( can only appear once on the line.) S 
  2700. 2160 8948 P (If a line does not contain an assignment, the value of the expression on the line is merely) S 
  2701. 2160 9188 P (printed out.  This means that it is valid to have a line that only contains a string or a) S 
  2702. 2160 9428 P (variable name.  The end of the input file marks the end of input.) S 
  2703. 2160 9868 P (Here are the declarations section of the YAY input and the ) S 0 12 F 0 9 F ("yylex") S 0 12 F 8 9 F () S 50 J ( routine \(both written) S 
  2704. 2160 10108 P (in C\).) S 
  2705. 2160 10528 P 0 12 F 0 10 F (%{) S 120 J (   /* declarations */) S 
  2706. 2160 10748 P (#include <stdio.h>) S 
  2707. 2160 10968 P (#define MAXSTRING 100) S 
  2708. 2160 11188 P (char str[MAXSTRING];) S 
  2709. 2160 11408 P (#define MAXVAR 8) S 
  2710. 2160 11628 P (char var[MAXVAR];) S 
  2711. 2160 11848 P (%}) S 
  2712. 2160 12268 P (%token VARIABLE STRING) S 
  2713. 2160 12488 P (%nonassoc PRINT) S 
  2714. 2160 12708 P (%right '=') S 
  2715. 2160 12928 P (%left JOIN) S 
  2716. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2717. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 70) S 0 12 F 
  2718. PE 
  2719. 2880 1948 P 0 10 F (%union) S 120 J ( {) S 
  2720. 2880 2168 P (     char *cstr;) S 
  2721. 2880 2388 P (}) S 
  2722. 2880 2608 P (%%) S 
  2723. 2880 3028 P (program : stat) S 
  2724. 2880 3248 P (        | program stat) S 
  2725. 2880 3468 P (        ;) S 
  2726. 2880 3688 P (stat : printexpr '\\n') S 
  2727. 2880 3908 P (     | expr '\\n') S 
  2728. 2880 4128 P (     ;) S 
  2729. 2880 4348 P (printexpr : PRINT expr ;) S 
  2730. 2880 4568 P (expr : VARIABLE '=' expr) S 
  2731. 2880 4788 P (     | JOIN expr expr) S 
  2732. 2880 5008 P (     | STRING) S 
  2733. 2880 5228 P (     | VARIABLE) S 
  2734. 2880 5448 P (     ;) S 
  2735. 2880 5668 P (%%) S 
  2736. 2880 6088 P (int yylex\(\)) S 
  2737. 2880 6308 P ({) S 
  2738. 2880 6528 P (    char c, *stringet\(\), *wordget\(\);) S 
  2739. 2880 6748 P (    extern YYSTYPE yylval;) S 
  2740. 2880 6968 P (    while \( \(c=getchar\(\)\) == ' ' \)) S 
  2741. 2880 7188 P (           /* skip blanks */;) S 
  2742. 2880 7408 P (    switch\(c\) {) S 
  2743. 2880 7628 P (      case '\\n':    /* end of line */) S 
  2744. 2880 7848 P (          return\('\\n'\);) S 
  2745. 2880 8068 P (      case EOF:     /* end of file */) S 
  2746. 2880 8288 P (          return\(0\);) S 
  2747. 2880 8508 P (      case '+':     /* same as JOIN */) S 
  2748. 2880 8728 P (          return\(JOIN\);) S 
  2749. 2880 8948 P (      case '"':     /* start of string */) S 
  2750. 2880 9168 P (          yylval.cstr = stringet\(\);) S 
  2751. 2880 9388 P (          return\(STRING\);) S 
  2752. 2880 9608 P (      default:      /* keyword or variable */) S 
  2753. 2880 9828 P (          yylval.cstr = wordget\(c\);) S 
  2754. 2880 10048 P (          if \( !strcmp\("JOIN",yylval.cstr\) \)) S 
  2755. 2880 10268 P (              return\(JOIN\);) S 
  2756. 2880 10488 P (          else if \( !strcmp\("PRINT",yylval.cstr\) \)) S 
  2757. 2880 10708 P (              return\(PRINT\);) S 
  2758. 2880 10928 P (          else return\(VARIABLE\);) S 
  2759. 2880 11148 P (    }) S 
  2760. 2880 11368 P (}) S 
  2761. 2880 11788 P (char *stringet\(\)) S 
  2762. 2880 12008 P ({) S 
  2763. 2880 12228 P (    extern char str[];) S 
  2764. 2880 12448 P (    int i;) S 
  2765. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2766. 2880 14800 P 0 12 F 24 10 F (71) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2767. PE 
  2768. 2160 1948 P 0 10 F () S 120 J (    for \( i=0; i < MAXSTRING; i++ \) {) S 
  2769. 2160 2168 P (        str[i] = getchar\(\);) S 
  2770. 2160 2388 P (        if \( \(str[i]=='"'\) || \(str[i]=='\\n'\) \)) S 
  2771. 2160 2608 P (            break;) S 
  2772. 2160 2828 P (    }) S 
  2773. 2160 3048 P (    str[i] = '\\0';  /* mark end of string */) S 
  2774. 2160 3268 P (    return\(str\);) S 
  2775. 2160 3488 P (}) S 
  2776. 2160 3908 P (char *wordget\(char c\)) S 
  2777. 2160 4128 P ({) S 
  2778. 2160 4348 P (    extern char var[];) S 
  2779. 2160 4568 P (    int i;) S 
  2780. 2160 4788 P (    var[0] = c;  /* first letter obtained already */) S 
  2781. 2160 5008 P (    for \( i=1; i < MAXVAR; i++ \) {) S 
  2782. 2160 5228 P (        var[i] = getchar\(\);) S 
  2783. 2160 5448 P (        if \( \(var[i]==' '\) || \(var[i]=='\\n'\) \)) S 
  2784. 2160 5668 P (            break;) S 
  2785. 2160 5888 P (    }) S 
  2786. 2160 6108 P (    var[i] = '\\0';) S 
  2787. 2160 6328 P (    return\(var\);) S 
  2788. 2160 6548 P (}) S 
  2789. 2160 6968 P (void yyerror\(char *s\)) S 
  2790. 2160 7188 P ({) S 
  2791. 2160 7408 P (    fprintf\(stderr,s\);) S 
  2792. 2160 7628 P (}) S 
  2793. 2160 8068 P 0 12 F 8 9 F (Note) S 50 J ( that the lexical analyzer always flags the keywords ) S 0 12 F 0 9 F (JOIN) S 0 12 F 8 9 F () S 50 J ( and ) S 0 12 F 0 9 F (PRINT) S 0 12 F 8 9 F () S 50 J ( as operations.) S 
  2794. 2160 8308 P (This means that you cannot use ) S 0 12 F 0 9 F (JOIN) S 0 12 F 8 9 F () S 50 J ( or ) S 0 12 F 0 9 F (PRINT) S 0 12 F 8 9 F () S 50 J ( as variable names.  In fact, this is a) S 
  2795. 2160 8548 P (general limitation of LALR\(1\) parsers.  It is very difficult to have names that are keywords) S 
  2796. 2160 8788 P (in some contexts and variable names in others, without a great deal of fiddling.  Therefore,) S 
  2797. 2160 9028 P (we recommend that you resign yourself to having ) S 0 12 F 8 9 F I (reserved) S E 0 12 F 8 9 F () S 50 J ( keywords, i.e. keywords) S 
  2798. 2160 9268 P (forbidden for use as variable names.) S 
  2799. 2160 9708 P (The above example omitted recognition actions in the Rules Section to make things easier) S 
  2800. 2160 9948 P (to read.) S 
  2801. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2802. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 72) S 0 12 F 
  2803. PE 
  2804. 8240 1968 P 8 18 F (Appendix) S 100 J ( B) S 
  2805. 7620 2448 P 0 12 F 8 18 F B (YAY) S 100 J ( vs. YACC) S E 
  2806. 2880 4048 P 0 12 F 8 9 F (YAY) S 50 J ( differs from its predecessor YACC in a number of respects. These are summarized) S 
  2807. 2880 4288 P (below.) S 
  2808. 2880 4728 P (\(a\)          YACC does not support the following.) S 
  2809. 3600 5168 P (-- all the LALR\(2\) features described in 9.1) S 
  2810. 3600 5408 P (-- selection preferences, as described in 9.3) S 
  2811. 3600 5648 P (-- the use of ) S 0 12 F 0 9 F (YYSTATIC) S 0 12 F 8 9 F (,) S 50 J ( ) S 0 12 F 0 9 F (YYSYNC) S 0 12 F 8 9 F (,) S 50 J ( or ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F () S 50 J ( \(9.12\)) S 
  2812. 2880 6088 P (\(b\)          If a state has several Reduce action, YACC always chooses the most popular of) S 
  2813. 3600 6328 P (these as the default action.  YAY's rules for choosing a default are given in 9.10.) S 
  2814. 3600 6568 P (In general, YAY's approach will detect errors more quickly \(sooner after they) S 
  2815. 3600 6808 P (actually occur\).) S 
  2816. 2880 7248 P (\(c\)) S 510 J ( The) S 50 J ( two programs handle ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( differently.  YAY always reduces and pops) S 
  2817. 3600 7488 P (the current state off the stack before generating the artificial error condition.) S 
  2818. 3600 7728 P (YACC doesn't do this.  With YACC, you cannot use ) S 0 12 F 0 9 F (YYERROR) S 0 12 F 8 9 F () S 50 J ( inside a rule with) S 
  2819. 3600 7968 P ("error" in it; YAY, however, will resolve the current rule and then trigger error) S 
  2820. 3600 8208 P (handling.) S 
  2821. 2880 8648 P (\(d\)          Output from the two programs differs slightly.) S 
  2822. 2880 9088 P (As a rule of thumb, YAY accepts any YACC grammar and creates a parser that behaves) S 
  2823. 2880 9328 P (the same for correct input.  However, the YAY version usually detects errors earlier than) S 
  2824. 2880 9568 P (the YACC parser, and has more Error actions in the state tables.) S 
  2825. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2826. 2880 14800 P 0 12 F 24 10 F (73) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2827. PE 
  2828. 7500 1968 P 8 18 F (Appendix) S 100 J ( C) S 
  2829. 5120 2448 P 0 12 F 8 18 F B (The) S 100 J ( YAY Command Line) S E 
  2830. 2160 4008 P 0 12 F 8 10 F B (Syntax:) S E 
  2831. 2880 4228 P 0 12 F 0 9 F (yay) S 108 J ( sourcefile Parser=outfile [option]*) S 
  2832. 2880 4648 P (\(+|-\)LR2 \(-\)            \(+|-\)Verbose \(-\)) S 
  2833. 2880 4868 P (\(+|-\)Warnings \(+\)       Description=file) S 
  2834. 2880 5088 P (Header=file             INSTallation=file) S 
  2835. 2880 5308 P (Language=C|C++ \(C\)      Parser=file) S 
  2836. 2160 5708 P 0 12 F 8 10 F B (Examples:) S E 
  2837. 2880 5928 P 0 12 F 0 9 F (yay) S 108 J ( cgram.y parse=myparse.c) S 
  2838. 2880 6148 P (c myparse.c) S 
  2839. 2880 6568 P (yay ccgram.y lang=c++ pars=myparse.cpp) S 
  2840. 2160 6968 P 0 12 F 8 10 F B (Options:) S E 
  2841. 2160 7208 P 0 12 F 0 9 F (sourcefile) S 
  2842. 2880 7448 P 0 12 F 8 9 F (is) S 50 J ( a file containing YAY input.) S 
  2843. 2160 7888 P 0 12 F 0 9 F (Language=C) S 
  2844. 2880 8128 P 0 12 F 8 9 F (produces) S 50 J ( parsing tables in the C programming language.  This is the default.) S 
  2845. 2160 8568 P 0 12 F 0 9 F (Language=C++) S 
  2846. 2880 8808 P 0 12 F 8 9 F (produces) S 50 J ( parsing tables in the C++ programming language.  Note that YAY only) S 
  2847. 2880 9048 P (produces the tables; the routines that use the tables to parse input are) S 
  2848. 2880 9288 P (predefined.) S 
  2849. 2160 9728 P 0 12 F 0 9 F (+LR2) S 
  2850. 2880 9968 P 0 12 F 8 9 F (says) S 50 J ( that the YAY input describes an LALR\(2\) grammar.  Without ) S 0 12 F 0 9 F (+LR2) S 0 12 F 8 9 F (,) S 50 J ( YAY) S 
  2851. 2880 10208 P (assumes that the grammar is LALR\(1\).  The manual describes modifications that) S 
  2852. 2880 10448 P (need to be made for LALR\(2\) grammars.) S 
  2853. 2160 10888 P 0 12 F 0 9 F (Description=file) S 
  2854. 2880 11128 P 0 12 F 8 9 F (translates) S 50 J ( the parsing tables into a format that humans can read, and writes this) S 
  2855. 2880 11368 P (output into the given file.) S 
  2856. 2160 11808 P 0 12 F 0 9 F (Header=file) S 
  2857. 2880 12048 P 0 12 F 8 9 F (writes) S 50 J ( token definitions and other information necessary for separate compilation,) S 
  2858. 2880 12288 P (to the named file.) S 
  2859. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2860. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 74) S 0 12 F 
  2861. PE 
  2862. 2880 1968 P 0 9 F (INSTallation=file) S 
  2863. 3600 2208 P 0 12 F 8 9 F (tells) S 50 J ( YAY where to find the installation file.  The installation file tells where various) S 
  2864. 3600 2448 P (software components have been installed.  For more information, see the section) S 
  2865. 3600 2688 P (on ) S 0 12 F 8 9 F I (Installation) S 50 J ( Files) S E 0 12 F 8 9 F () S 50 J ( below.) S 
  2866. 3600 3128 P (If you do not specify an ) S 0 12 F 0 9 F (INSTallation=) S 0 12 F 8 9 F () S 50 J ( option on the command line, YAY) S 
  2867. 3600 3368 P (checks for an environment variable named ) S 0 12 F 0 9 F (YAY_INST) S 0 12 F 8 9 F () S 50 J ( and uses its value as the) S 
  2868. 3600 3608 P (name of the installation file.  If this environment variable does not exist, YAY uses) S 
  2869. 3600 3848 P (the default installation file.) S 
  2870. 2880 4288 P 0 12 F 0 9 F (Parser=file) S 
  2871. 3600 4528 P 0 12 F 8 9 F (writes) S 50 J ( the resulting source code for the parser into the named file.  If this option is) S 
  2872. 3600 4768 P (omitted, YAY just checks the syntax of your input.) S 
  2873. 2880 5208 P 0 12 F 0 9 F (+Verbose) S 
  2874. 3600 5448 P 0 12 F 8 9 F (produces) S 50 J ( verbose output -- everything that can be flagged is flagged.) S 
  2875. 2880 5888 P 0 12 F 0 9 F (-Warnings) S 
  2876. 3600 6128 P 0 12 F 8 9 F (suppresses) S 50 J ( a number of warning messages that YAY normally issues.) S 
  2877. 2880 6528 P 0 12 F 8 10 F B (Description:) S E 
  2878. 2880 6768 P 0 12 F 8 9 F (YAY) S 50 J ( converts your context-free grammar into a C or C++ program that is written to the file) S 
  2879. 2880 7008 P (specified by the ) S 0 12 F 0 9 F (Parser=) S 0 12 F 8 9 F () S 50 J ( option.) S 
  2880. 2880 7448 P (If you use the ) S 0 12 F 0 9 F (Description=) S 0 12 F 8 9 F () S 50 J ( option, YAY writes a full description of the grammar to the) S 
  2881. 2880 7688 P (specified file.  YAY only displays a brief message on the standard output, summarizing) S 
  2882. 2880 7928 P (conflicts \(and other information if you specify ) S 0 12 F 0 9 F (+Verbose) S 0 12 F 8 9 F (\).) S 50 J (  On the other hand, if you do) S 
  2883. 2880 8168 P (not use the ) S 0 12 F 0 9 F (Description=) S 0 12 F 8 9 F () S 50 J ( option, YAY writes more information to standard output,) S 
  2884. 2880 8408 P (including descriptions of the states where conflicts occur.  In this case, YAY actually) S 
  2885. 2880 8648 P (provides additional information to help you identify the source of the conflicts; if you ask for) S 
  2886. 2880 8888 P (a description file, YAY outputs less information when reporting the conflicts because it) S 
  2887. 2880 9128 P (assumes you can track down additional information by looking at the description file.  For) S 
  2888. 2880 9368 P (this reason, you can sometimes get a quicker idea of what has gone wrong if you do not) S 
  2889. 2880 9608 P (ask for a description file.) S 
  2890. 2880 10008 P 0 12 F 8 10 F B (C++) S 56 J ( Parsers) S E 
  2891. 2880 10248 P 0 12 F 8 9 F (In) S 50 J ( general, you only need to use ) S 0 12 F 0 9 F (Language=C++) S 0 12 F 8 9 F () S 50 J ( if you intend ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F () S 50 J ( to contain a C++) S 
  2892. 2880 10488 P (object with constructors.  If you intend to compile the parser with C++ but the ) S 0 12 F 0 9 F (%union) S 
  2893. 2880 10728 P 0 12 F 8 9 F (statement) S 50 J ( does not have any elements that need constructors,  it's best to use) S 
  2894. 2880 10968 P 0 12 F 0 9 F (Language=C) S 0 12 F 8 9 F () S 50 J ( to get more efficient C code.) S 
  2895. 2880 11408 P (If ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F () S 50 J ( does contain elements that need constructors, you need to define an) S 
  2896. 2880 11648 P (appropriate constructor-like function for the ) S 0 12 F 0 9 F (YYSTYPE) S 0 12 F 8 9 F () S 50 J ( type.  This function should have the) S 
  2897. 2880 11888 P (prototype) S 
  2898. 3600 12308 P 0 12 F 0 9 F (void) S 108 J ( name\(YYSTYPE *p\)) S 
  2899. 2880 12748 P 0 12 F 8 9 F (where) S 50 J ( ) S 0 12 F 0 9 F ("name") S 0 12 F 8 9 F () S 50 J ( can be any valid name.  In the declarations section of the grammar, you) S 
  2900. 2880 12988 P (must then add the statement) S 
  2901. 2880 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2902. 2880 14800 P 0 12 F 24 10 F (75) S 4238 J ( Thinkage) S 50 J ( YAY Reference Manual) S 0 12 F 
  2903. PE 
  2904. 2880 1948 P 0 9 F (#define) S 108 J ( YYSTYPE_INIT name) S 
  2905. 2160 2388 P 0 12 F 8 9 F (where) S 50 J ( ) S 0 12 F 0 9 F ("name") S 0 12 F 8 9 F () S 50 J ( is the name of the constructor-like function.) S 
  2906. 2160 2828 P (With ) S 0 12 F 0 9 F (Language=C++) S 0 12 F 8 9 F (,) S 50 J ( the ) S 0 12 F 0 9 F (%union) S 0 12 F 8 9 F () S 50 J ( statement generates a structure type rather than a) S 
  2907. 2160 3068 P (union, since C++ does not allow objects with constructors to belong to unions.) S 
  2908. 2160 3508 P (In many cases, the same grammar may be processed with either ) S 0 12 F 0 9 F (Language=C) S 0 12 F 8 9 F () S 50 J ( or) S 
  2909. 2160 3748 P 0 12 F 0 9 F (Language=C++) S 0 12 F 8 9 F (.) S 
  2910. 2160 4148 P 0 12 F 8 10 F B (Installation) S 56 J ( Files:) S E 
  2911. 2160 4388 P 0 12 F 8 9 F (An) S 50 J ( installation file specifies the pathnames for software and data files used by YAY.) S 
  2912. 2160 4628 P (Installation files are text files made up of comment lines and option lines.) S 
  2913. 2160 5088 P (Comment lines:) S 
  2914. 2880 5328 P (Any line whose first non-blank character is ) S 0 12 F 0 9 F (#) S 0 12 F 8 9 F () S 50 J ( will be taken as a comment.  Blank) S 
  2915. 2880 5568 P (lines are also considered comments.) S 
  2916. 2160 6028 P (Option lines:) S 
  2917. 2880 6268 P (Option lines have the format) S 
  2918. 2880 6688 P 0 12 F 0 9 F (Keyword=pathname) S 
  2919. 2880 7128 P 0 12 F 8 9 F (In) S 50 J ( this documentation, keywords are written with some letters in upper case and) S 
  2920. 2880 7368 P (some in lower case.  You may abbreviate keywords by omitting any or all of the) S 
  2921. 2880 7608 P (letters shown in lower case.  The remaining letters may be entered in either) S 
  2922. 2880 7848 P (upper or lower case; the documentation simply uses upper case to show which) S 
  2923. 2880 8088 P (characters may not be omitted.) S 
  2924. 2160 8528 P (In this version of YAY, there is only one valid option line:) S 
  2925. 2880 8948 P 0 12 F 0 9 F (Library=pathname) S 
  2926. 2160 9388 P 0 12 F 8 9 F (The) S 50 J ( pathname should be the directory containing the YAY parser template files \(e.g.) S 
  2927. 2160 9628 P 0 12 F 0 9 F (yyparse.c) S 0 12 F 8 9 F (\).) S 
  2928. 2160 10028 P 0 12 F 8 10 F B (Notes:) S E 
  2929. 2160 10268 P 0 12 F 8 9 F (If) S 50 J ( you define ) S 0 12 F 0 9 F (YYALLOC) S 0 12 F 8 9 F (,) S 50 J ( the parser allocates its state and value stacks dynamically via) S 
  2930. 2160 10508 P (malloc and free.  This shrinks your parser and helps prevent stack overflows.) S 
  2931. 2160 10948 P (Copyright 1995, Thinkage Ltd.) S 
  2932. 2160 14520 P 0 12 F 57 12 F (DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD) S 
  2933. 2160 14800 P 0 12 F 24 10 F (Thinkage) S 50 J ( YAY Reference Manual) S 4238 J ( 76) S 0 12 F 
  2934. PE PSe
  2935. %%Trailer
  2936.  
  2937.