/usr/share/doc/frown-doc/html/Manual006.html is in frown-doc 0.6.1-14.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="hevea 2.06">
<link rel="stylesheet" type="text/css" href="Manual.css">
<title>Reference manual</title>
</head>
<body >
<a href="Manual005.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="Manual007.html"><img src="next_motif.gif" alt="Next"></a>
<hr>
<h1 id="sec41" class="chapter">Chapter 5 Reference manual</h1>
<h2 id="sec42" class="section">5.1 Lexical syntax of <span style="font-family:sans-serif">Frown</span></h2>
<p>⟨<span style="font-weight:bold">To do:</span> that of Haskell including comments.⟩</p><p>⟨<span style="font-weight:bold">To do:</span> Literate grammar file (Bird tracks)⟩.</p>
<h2 id="sec43" class="section">5.2 Syntax of <span style="font-family:sans-serif">Frown</span></h2>
<p>Grammar file.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> file : many "not special",</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> "%{",</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many decl;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> "}%",</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many "not special";
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Note that <span style="font-family:monospace">"not special"</span> matches every token except the special curly
braces <span style="font-family:monospace">"%{"</span> and <span style="font-family:monospace">"}%"</span>.</p><p>Declaration.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> decl : terminals;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | nonterminals;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | fixity;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | signature;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | productions;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Terminal declaration.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> terminals : "Terminal", "=", sepBy term "|", ";";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> term : opt "*", assoc, terminal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | opt "*", assoc, literal, "=", terminal; </span>-- deprecated</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | opt "*", assoc, terminal, "as", literal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | opt "*", assoc, "guard", haskell, "as", literal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> assoc : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "left", </span><span style="font-family:monospace"><span style="font-style:italic">Numeral</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "right", </span><span style="font-family:monospace"><span style="font-style:italic">Numeral</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "nonassoc", </span><span style="font-family:monospace"><span style="font-style:italic">Numeral</span></span><span style="font-family:monospace">;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Nonterminal declaration.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> nonterminals : "Nonterminal", "=", sepBy nonterm "|", ";";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> nonterm : opt "*", nonterminal;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Fixity declaration.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> fixity : "left", </span><span style="font-family:monospace"><span style="font-style:italic">Numeral</span></span><span style="font-family:monospace">, terminal, ";";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "right", </span><span style="font-family:monospace"><span style="font-style:italic">Numeral</span></span><span style="font-family:monospace">, terminal, ";";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "nonassoc", </span><span style="font-family:monospace"><span style="font-style:italic">Numeral</span></span><span style="font-family:monospace">, terminal, ";";
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Type signature.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> signature : "::", nonterminal, premise, ";"; </span>-- deprecated</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | nonterminal, premise, ";";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "::", "*", nonterminal, ";"; </span>-- deprecated</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "*", nonterminal, ";";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> premise : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "<-", sepBy1 nonterminal ",";
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Productions.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> productions : nonterminal, ":", sepBy symbol ",", ";", alts;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> alts : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | attributes, "|", sepBy symbol ",", ";", alts;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> symbol : "insert", terminal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "delete", terminal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "prec", terminal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | terminal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | nonterminal;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Nonterminal symbols (<span style="font-family:monospace">expr0</span> is a variant of <span style="font-family:monospace">expr</span> lacking the
embedded Haskell production).
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> nonterminal : expr0, attributes;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> expr0 : </span><span style="font-family:monospace"><span style="font-style:italic">Varid</span></span><span style="font-family:monospace">, many aexpr0;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> aexpr0 : </span><span style="font-family:monospace"><span style="font-style:italic">Varid</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | </span><span style="font-family:monospace"><span style="font-style:italic">Conid</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | literal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "(", sepBy expr ",", ")";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "[", sepBy expr ",", "]";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> expr : aexpr;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | </span><span style="font-family:monospace"><span style="font-style:italic">Varid</span></span><span style="font-family:monospace">, many1 aexpr;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | </span><span style="font-family:monospace"><span style="font-style:italic">Conid</span></span><span style="font-family:monospace">, many1 aexpr;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> aexpr : </span><span style="font-family:monospace"><span style="font-style:italic">Varid</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | </span><span style="font-family:monospace"><span style="font-style:italic">Conid</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | literal;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "(", sepBy expr ",", ")";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "[", sepBy expr ",", "]";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | haskell; </span>-- embedded Haskell<span style="font-family:monospace">
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Terminal symbols.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> terminal : pat;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | literal, haskell, attributes; </span>-- shortcut</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> pat : apat;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | </span><span style="font-family:monospace"><span style="font-style:italic">Conid</span></span><span style="font-family:monospace">, many1 apat;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> apat : </span><span style="font-family:monospace"><span style="font-style:italic">Conid</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | literal; </span>-- either literal or shortcut</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "(", sepBy pat ",", ")";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "[", sepBy pat ",", "]";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | haskell;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> literal : </span><span style="font-family:monospace"><span style="font-style:italic">String</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | </span><span style="font-family:monospace"><span style="font-style:italic">Numeral</span></span><span style="font-family:monospace">;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | </span><span style="font-family:monospace"><span style="font-style:italic">Char</span></span><span style="font-family:monospace">;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Embedded Haskell (types, patterns, and expressions).
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> attributes : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | haskell, attributes;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> haskell : "{", many hs, "}";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> hs : "not brace";</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | "{", many hs, "}";
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Note that <span style="font-family:monospace">"not brace"</span> matches every token except the curly braces
<span style="font-family:monospace">"{"</span> and <span style="font-family:monospace">"}"</span>.
</p>
<h2 id="sec44" class="section">5.3 Predefined schemes</h2>
<p>
<a id="sec:stdenv"></a>
</p><p>Note that the predefined rules are left-recursive and ‘run’ using
constant stack space. Also note that we define rules for arity zero
and arity one (the arity specifies the number of attributes/semantic
values). The primed versions of the rules work on Hughes’s efficient
sequence type (a sequence of <span style="font-family:monospace">a</span>’s is represented by a function of
type <span style="font-family:monospace">[a] -> [a]</span>).</p>
<h3 id="sec45" class="subsection">5.3.1 Optional elements</h3>
<p>Arity zero.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> opt x <- x;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> opt x : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | x;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Arity one.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> opt x {</span><span style="font-family:monospace"><span style="font-style:italic">Maybe</span></span><span style="font-family:monospace"> a} <- x {a};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> opt x {</span><span style="font-family:monospace"><span style="font-style:italic">Nothing</span></span><span style="font-family:monospace">} : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {</span><span style="font-family:monospace"><span style="font-style:italic">Just</span></span><span style="font-family:monospace"> a} | x {a};
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
</p>
<h3 id="sec46" class="subsection">5.3.2 Repetition of elements</h3>
<p>Arity zero.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many x <- x;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many x : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | many x, x;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many1 x <- x;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many1 x : x, many x;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Arity one.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many x {[a]} <- x {a};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many x {s []} : many’ x {s};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many’ x {[a] -> [a]} <- x {a};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many’ x {\ as -> as} : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {\ as -> s (a : as)} | many’ x {s}, x {a};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many1 x {[a]} <- x {a};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> many1 x {a : as} : x {a}, many x {as};
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
</p>
<h3 id="sec47" class="subsection">5.3.3 Repetition of elements separated by a second element</h3>
<p>Arity zero.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy x sep <- x, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy x sep : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | sepBy1 x sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy1 x sep <- x, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy1 x sep : x;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | sepBy1 x sep, sep, x;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Arity one.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy x sep {[a]} <- x {a}, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy x sep {[]} : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {as} | sepBy1 x sep {as};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy1 x sep {[a]} <- x {a}, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy1 x sep {s []} : sepBy1’ x sep {s};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy1’ x sep {[a] -> [a]} <- x {a}, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> sepBy1’ x sep</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {\ as -> a : as} : x {a};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {\ as -> s (a : as)} | sepBy1’ x sep {s}, sep, x {a};
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
TODO: also versions where <span style="font-family:monospace">sep</span> has arity one.</p>
<h3 id="sec48" class="subsection">5.3.4 Repetition of possibly empty elements separated by a second element</h3>
<p>⟨<span style="font-weight:bold">To do:</span> better name.⟩</p><p>Arity zero.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> optSepBy x sep <- x, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> optSepBy x sep : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | x;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | optSepBy x sep, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> | optSepBy x sep, sep, x;
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
Arity one.
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
</p><table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> optSepBy x sep {[a]} <- x {a}, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> optSepBy x sep {s []} : optSepBy’ x sep {s};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> optSepBy’ x sep {[a] -> [a]} <- x {a}, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> optSepBy’ x sep</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {\ as -> as} : ;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {\ as -> a : as} | x {a};</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {\ as -> s as} | optSepBy’ x sep {s}, sep;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> {\ as -> s (a : as)} | optSepBy’ x sep {s}, sep, x {a};
</span></td></tr>
</table><p>
</TD></TR></TABLE><P>
</p>
<h2 id="sec49" class="section">5.4 Output formats</h2>
<p>
<a id="sec:formats"></a>
</p><p>⟨<span style="font-weight:bold">To do:</span> Used type names: <span style="font-family:monospace"><span style="font-style:italic">Result</span></span> and <span style="font-family:monospace"><span style="font-style:italic">Terminal</span></span>.⟩</p><p>⟨<span style="font-weight:bold">To do:</span> Used function names: <span style="font-family:monospace">frown</span>. For each start symbol a parser.⟩</p><p>The <span style="font-family:monospace">code=standard</span> format is due to Doaitse Swierstra [<a href="Manual007.html#DuS00Fun">1</a>].</p><p>The <span style="font-family:monospace">code=stackless</span> format is due to Ross Paterson [<a href="Manual007.html#HiP05Typ">2</a>].</p><p>The <span style="font-family:monospace">code=gvstack</span> format is also due to Ross Paterson.</p><blockquote class="figure"><div class="center"><hr style="width:80%;height:2"></div>
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
<table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">module</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-weight:bold">where</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">import</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Result</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span>{- frown :-( -}</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">data</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Stack</span></span><span style="font-family:monospace"> = </span><span style="font-family:monospace"><span style="font-style:italic">Empty</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">State</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Stack</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">data</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">State</span></span><span style="font-family:monospace"> = </span><span style="font-family:monospace"><span style="font-style:italic">S_1</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">S_2</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">S_3</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">S_4</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">S_5</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">S_6</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">data</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Nonterminal</span></span><span style="font-family:monospace"> = </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> paren tr = parse_1 tr </span><span style="font-family:monospace"><span style="font-style:italic">Empty</span></span><span style="font-family:monospace"> >>= (\ </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> -> return ())</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_1 ts st = reduce_2 ts </span><span style="font-family:monospace"><span style="font-style:italic">S_1</span></span><span style="font-family:monospace"> st</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_2 tr@[] st = parse_3 tr (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">S_2</span></span><span style="font-family:monospace"> st)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_2 (</span><span style="font-family:monospace">’(’</span><span style="font-family:monospace"> : tr) st = parse_5 tr (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">S_2</span></span><span style="font-family:monospace"> st)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_2 ts st = frown ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_3 ts st = reduce_1 ts st</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_4 (</span><span style="font-family:monospace">’(’</span><span style="font-family:monospace"> : tr) st = parse_5 tr (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">S_4</span></span><span style="font-family:monospace"> st)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_4 (</span><span style="font-family:monospace">’)’</span><span style="font-family:monospace"> : tr) st = parse_6 tr (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">S_4</span></span><span style="font-family:monospace"> st)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_4 ts st = frown ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_5 ts st = reduce_2 ts </span><span style="font-family:monospace"><span style="font-style:italic">S_5</span></span><span style="font-family:monospace"> st</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> parse_6 ts st = reduce_3 ts st</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_1 ts (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> _ (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> s st)) = return </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_2 ts s st = goto_5 s ts (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> s st)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_3 ts (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> _ (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> _ (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> _ (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> s st))))</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> = goto_5 s ts (</span><span style="font-family:monospace"><span style="font-style:italic">T_1</span></span><span style="font-family:monospace"> s st)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> goto_5 </span><span style="font-family:monospace"><span style="font-style:italic">S_1</span></span><span style="font-family:monospace"> = parse_2</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> goto_5 </span><span style="font-family:monospace"><span style="font-style:italic">S_5</span></span><span style="font-family:monospace"> = parse_4</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span>{- )-: frown -}</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> frown _ = fail "syntax error"</span></td></tr>
</table>
</TD></TR></TABLE><P>
<div class="caption"><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" >Figure 5.1: <a id="fig:ex1cc"></a><span style="font-family:monospace">frown --code=compact Paren.g</span>.</td></tr>
</table></div>
<div class="center"><hr style="width:80%;height:2"></div></blockquote><blockquote class="figure"><div class="center"><hr style="width:80%;height:2"></div>
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
<table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">module</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-weight:bold">where</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">import</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Result</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span>{- frown :-( -}</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> paren tr = state_1 (\ _ -> return ()) tr</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_1 k_1_0 ts = </span><span style="font-family:monospace"><span style="font-weight:bold">let</span></span><span style="font-family:monospace"> { goto_paren = state_2 k_1_0 (reduce_3 goto_paren) }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">in</span></span><span style="font-family:monospace"> reduce_2 goto_paren ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_2 k_1_1 k_3_1 ts = </span><span style="font-family:monospace"><span style="font-weight:bold">case</span></span><span style="font-family:monospace"> ts </span><span style="font-family:monospace"><span style="font-weight:bold">of</span></span><span style="font-family:monospace"> { tr@[] -> state_3 k_1_1 tr;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace">’(’</span><span style="font-family:monospace"> : tr -> state_5 k_3_1 tr;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> _ -> frown ts }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_3 k_1_2 ts = k_1_2 ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_4 k_3_1 k_3_3 ts = </span><span style="font-family:monospace"><span style="font-weight:bold">case</span></span><span style="font-family:monospace"> ts </span><span style="font-family:monospace"><span style="font-weight:bold">of</span></span><span style="font-family:monospace"> { </span><span style="font-family:monospace">’(’</span><span style="font-family:monospace"> : tr -> state_5 k_3_1 tr;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace">’)’</span><span style="font-family:monospace"> : tr -> state_6 k_3_3 tr;</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> _ -> frown ts }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_5 k_3_2 ts = </span><span style="font-family:monospace"><span style="font-weight:bold">let</span></span><span style="font-family:monospace"> { goto_paren = state_4 (reduce_3 goto_paren) k_3_2 }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">in</span></span><span style="font-family:monospace"> reduce_2 goto_paren ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_6 k_3_4 ts = k_3_4 ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_2 g ts = g ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_3 g ts = g ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span>{- )-: frown -}</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> frown _ = fail "syntax error"</span></td></tr>
</table>
</TD></TR></TABLE><P>
<div class="caption"><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" >Figure 5.2: <a id="fig:ex1cs"></a><span style="font-family:monospace">frown --code=stackless Paren.g</span>.</td></tr>
</table></div>
<div class="center"><hr style="width:80%;height:2"></div></blockquote><blockquote class="figure"><div class="center"><hr style="width:80%;height:2"></div>
<TABLE BORDER="2" BGCOLOR="#E0E0E0" WIDTH="100%"><TR><TD>
<table style="border:0;border-spacing:0" class="cellpadding0"><tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">module</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-weight:bold">where</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">import</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Result</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span>{- frown :-( -}</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">data</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Nonterminal</span></span><span style="font-family:monospace"> = </span><span style="font-family:monospace"><span style="font-style:italic">Paren’</span></span><span style="font-family:monospace"> | </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">type</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span><span style="font-family:monospace"> = [</span><span style="font-family:monospace"><span style="font-style:italic">Terminal</span></span><span style="font-family:monospace">] -> </span><span style="font-family:monospace"><span style="font-style:italic">Result</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Nonterminal</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace"><span style="font-weight:bold">type</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> vs v = ((vs, </span><span style="font-family:monospace"><span style="font-style:italic">Nonterminal</span></span><span style="font-family:monospace"> -> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span><span style="font-family:monospace">), v)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> paren tr = state_1 () tr >>= (\ </span><span style="font-family:monospace"><span style="font-style:italic">Paren’</span></span><span style="font-family:monospace"> -> return ())</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_1 :: vs -> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_1 = state action_1 goto_1</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> action_1 t = reduce_2</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> goto_1 </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> = goto state_2 ()</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_2 :: </span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> vs () -> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_2 = state action_2 undefined</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> action_2 t = </span><span style="font-family:monospace"><span style="font-weight:bold">case</span></span><span style="font-family:monospace"> t </span><span style="font-family:monospace"><span style="font-weight:bold">of</span></span><span style="font-family:monospace"> { </span><span style="font-family:monospace">’(’</span><span style="font-family:monospace"> -> shift state_5 ();</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace">’$’</span><span style="font-family:monospace"> -> shift state_3 ();</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> _ -> error }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_3 :: </span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> vs ()) () -> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_3 = state action_3 undefined</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> action_3 t = reduce_1</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_4 :: </span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> vs ()) ()) () -> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_4 = state action_4 undefined</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> action_4 t = </span><span style="font-family:monospace"><span style="font-weight:bold">case</span></span><span style="font-family:monospace"> t </span><span style="font-family:monospace"><span style="font-weight:bold">of</span></span><span style="font-family:monospace"> { </span><span style="font-family:monospace">’(’</span><span style="font-family:monospace"> -> shift state_5 ();</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span><span style="font-family:monospace">’)’</span><span style="font-family:monospace"> -> shift state_6 ();</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> _ -> error }</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_5 :: </span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> vs ()) () -> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_5 = state action_5 goto_5</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> action_5 t = reduce_2</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> goto_5 </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> = goto state_4 ()</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_6 :: </span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> (</span><span style="font-family:monospace"><span style="font-style:italic">VStack</span></span><span style="font-family:monospace"> vs ()) ()) ()) () -> </span><span style="font-family:monospace"><span style="font-style:italic">Parser</span></span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state_6 = state action_6 undefined</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> action_6 t = reduce_3</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_1 (((((_, g), ()), _), ()), _) ts </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> = accept </span><span style="font-family:monospace"><span style="font-style:italic">Paren’</span></span><span style="font-family:monospace"> ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_2 (_, g) ts = g </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> reduce_3 (((((((((_, g), ()), _), ()), _), ()), _), ()), _) ts </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> = g </span><span style="font-family:monospace"><span style="font-style:italic">Paren</span></span><span style="font-family:monospace"> ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> state action goto vs ts = </span><span style="font-family:monospace"><span style="font-weight:bold">let</span></span><span style="font-family:monospace"> { gs = (vs, g); g v = goto v gs } </span><span style="font-family:monospace"><span style="font-weight:bold">in</span></span><span style="font-family:monospace"> action (head ts) gs ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> shift state v vs ts = state (vs, v) (tail ts)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> shift’ state v vs ts = state (vs, v) ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> accept v _ = return v</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> goto state v vs = state (vs, v)</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> error gs ts = frown ts</span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span>{- )-: frown -}</td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> </span></td></tr>
<tr><td style="text-align:left;white-space:nowrap" ><span style="font-family:monospace">> frown _ = fail "syntax error"</span></td></tr>
</table>
</TD></TR></TABLE><P>
<div class="caption"><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" >Figure 5.3: <a id="fig:ex1cg"></a><span style="font-family:monospace">frown --code=gvstack Paren.g</span> (requires an explicit EOF symbol).</td></tr>
</table></div>
<div class="center"><hr style="width:80%;height:2"></div></blockquote>
<h2 id="sec50" class="section">5.5 Invocation and options</h2>
<p>
<a id="sec:options"></a>
</p><p><span style="font-family:monospace">Usage: frown [option ...] file.g ...</span></p><dl class="description"><dt class="dt-description">
<span style="font-weight:bold"><span style="font-family:monospace">-b</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--backtrack</span></span></dt><dd class="dd-description"> <br>
generate a backtracking parser (see Sec. <a href="Manual004.html#sec%3Abacktracking">3.2.5</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-cc</span></span><span style="font-weight:bold">, </span><span style="font-weight:bold"><span style="font-family:monospace">-ccompact</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--code=compact</span></span></dt><dd class="dd-description"> <br>
(see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a> and <a href="#sec%3Aformats">5.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-cg</span></span><span style="font-weight:bold">, </span><span style="font-weight:bold"><span style="font-family:monospace">-cgvstack</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--code=gvstack</span></span></dt><dd class="dd-description"> <br>
(see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a> and <a href="#sec%3Aformats">5.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-cs</span></span><span style="font-weight:bold">, </span><span style="font-weight:bold"><span style="font-family:monospace">-cstackless</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--code=stackless</span></span></dt><dd class="dd-description"> <br>
(see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a> and <a href="#sec%3Aformats">5.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-cstandard</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--code=standard</span></span></dt><dd class="dd-description"> <br>
(see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a> and <a href="#sec%3Aformats">5.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">--copying</span></span></dt><dd class="dd-description"> <br>
display details of copying</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-d</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--debug</span></span></dt><dd class="dd-description"> <br>
emit debugging information (see Sec. <a href="Manual004.html#sec%3Atracing">3.4.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-e</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--expected</span></span></dt><dd class="dd-description"> <br>
pass a list of expected terminals to ‘<span style="font-family:monospace">frown</span>’ (see Sec. <a href="Manual004.html#sec%3Aexpected">3.3.3</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-g</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--ghc</span></span></dt><dd class="dd-description"> <br>
use GHC extensions (see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-h</span></span><span style="font-weight:bold">, </span><span style="font-weight:bold"><span style="font-family:monospace">-?</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--help</span></span></dt><dd class="dd-description"> <br>
</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-i</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--info</span></span></dt><dd class="dd-description"> <br>
put additional information into generated file (see Sec. <a href="Manual004.html#sec%3Atracing">3.4.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-k[nat]</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--lookahead[=nat]</span></span></dt><dd class="dd-description"> <br>
use <span style="font-style:italic">k</span> tokens of look-ahead (see Sec. <a href="Manual004.html#sec%3Alook-ahead">3.4.3</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-l</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--lexer</span></span></dt><dd class="dd-description"> <br>
use a monadic lexer (<span style="font-family:monospace">get :: </span><span style="font-family:monospace"><span style="font-style:italic">M</span></span><span style="font-family:monospace"> </span><span style="font-family:monospace"><span style="font-style:italic">Terminal</span></span>) (see Sec. <a href="Manual004.html#sec%3Amlexer">3.3.1</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-n</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--noinline</span></span></dt><dd class="dd-description"> <br>
generate <span style="font-family:monospace">NOINLINE</span> pragmas (see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-O</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--optimize </span></span></dt><dd class="dd-description"> <br>
optimize parser (see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-p[nat]</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--pagewidth[=nat]</span></span></dt><dd class="dd-description"> <br>
use the specified pagewidth for pretty printing (see Sec. <a href="Manual004.html#sec%3Atracing">3.4.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">--prefix[=string]</span></span></dt><dd class="dd-description"> <br>
use prefix for <span style="font-family:sans-serif">Frown</span>-generated variables (see Sec. <a href="Manual004.html#sec%3Atracing">3.4.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-sm</span></span><span style="font-weight:bold">, </span><span style="font-weight:bold"><span style="font-family:monospace">-smono</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--signature=mono</span></span></dt><dd class="dd-description"> <br>
add monomorphic type signatures (see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-sp</span></span><span style="font-weight:bold">, </span><span style="font-weight:bold"><span style="font-family:monospace">-spoly</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--signature=poly</span></span></dt><dd class="dd-description"> <br>
add polymorphic type signatures (see Sec. <a href="Manual004.html#sec%3Aoptimizations">3.4.5</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">--suffix[=string]</span></span></dt><dd class="dd-description"> <br>
use suffix for frown generated variables (see Sec. <a href="Manual004.html#sec%3Atracing">3.4.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-t</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--trace</span></span></dt><dd class="dd-description"> <br>
insert calls to tracing routines (‘<span style="font-family:monospace">shift</span>’, ‘<span style="font-family:monospace">reduce</span>’ and ‘<span style="font-family:monospace">accept</span>’)
(see Sec. <a href="Manual004.html#sec%3Atracing">3.4.4</a>)</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">-v</span></span><span style="font-weight:bold"> or </span><span style="font-weight:bold"><span style="font-family:monospace">--verbose</span></span></dt><dd class="dd-description"> <br>
be verbose</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">--version</span></span></dt><dd class="dd-description"> <br>
print version information</dd><dt class="dt-description"><span style="font-weight:bold"><span style="font-family:monospace">--warranty</span></span></dt><dd class="dd-description"> <br>
display details of warranty
</dd></dl><hr>
<a href="Manual005.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="Manual007.html"><img src="next_motif.gif" alt="Next"></a>
</body>
</html>
|