402 \end{tabular} |
402 \end{tabular} |
403 \end{center} |
403 \end{center} |
404 |
404 |
405 \noindent In essence we need to apply in this case |
405 \noindent In essence we need to apply in this case |
406 the appropriate rectification function to the inner part |
406 the appropriate rectification function to the inner part |
407 of the value $v$, wherevy $v$ can only be of the form |
407 of the value $v$, whereby $v$ can only be of the form |
408 $Right(\_)$ or $Left(\_)$. |
408 $Right(\_)$ or $Left(\_)$. |
|
409 |
|
410 The other interesting case with simplification is the |
|
411 sequence case. Here the main simplification function |
|
412 is as follows |
|
413 |
|
414 \begin{center} |
|
415 \begin{tabular}{l} |
|
416 $simp(r)$:\qquad\qquad (continued)\\ |
|
417 \quad case $r = r_1 \cdot r_2$\\ |
|
418 \qquad let $(r_{1s}, f_{1s}) = simp(r_1)$\\ |
|
419 \qquad \phantom{let} $(r_{2s}, f_{2s}) = simp(r_2)$\smallskip\\ |
|
420 \qquad case $r_{1s} = \varnothing$: |
|
421 return $(\varnothing, f_{error})$\\ |
|
422 \qquad case $r_{2s} = \varnothing$: |
|
423 return $(\varnothing, f_{error})$\\ |
|
424 \qquad case $r_{1s} = \epsilon$: |
|
425 return $(r_{2s}, \lambda v. \,Seq(f_{1s}(Empty), f_{2s}(v)))$\\ |
|
426 \qquad case $r_{2s} = \epsilon$: |
|
427 return $(r_{1s}, \lambda v. \,Seq(f_{1s}(v), f_{2s}(Empty)))$\\ |
|
428 \qquad otherwise: |
|
429 return $(r_{1s} \cdot r_{2s}, f_{seq}(f_{1s}, f_{2s}))$\\ |
|
430 \end{tabular} |
|
431 \end{center} |
|
432 |
|
433 \noindent whereby $f_{seq}$ is again pushing the two |
|
434 rectification functions into the two components of |
|
435 the Seq-value: |
|
436 |
|
437 \begin{center} |
|
438 \begin{tabular}{l@{\hspace{1mm}}l} |
|
439 $f_{seq}(f_1, f_2) \dn$\\ |
|
440 \qquad $\lambda v.\,$ case $v = Seq(v_1, v_2)$: |
|
441 & return $Seq(f_1(v_1), f_2(v_2))$\\ |
|
442 \end{tabular} |
|
443 \end{center} |
|
444 |
|
445 \noindent Note that in the case of $r_{1s}$ (similarly $r_{2s}$) |
|
446 we use the function $f_{error}$ for rectification. If you |
|
447 think carefully, then you will see that this function will |
|
448 actually never been called. Because a sequence with |
|
449 $\varnothing$ will never recognise any string and therefore |
|
450 the second phase of the algorithm would never been called. |
|
451 The simplification function still expects us to give a |
|
452 function. So in my own implementation I just returned |
|
453 a function which raises an error. |
|
454 |
|
455 |
409 |
456 |
410 \subsubsection*{Records and Tokenisation} |
457 \subsubsection*{Records and Tokenisation} |
411 |
458 |
412 \newpage |
459 \newpage |
413 Algorithm by Sulzmann, Lexing |
460 Algorithm by Sulzmann, Lexing |