1 \documentclass[dvipsnames,14pt,t]{beamer} |
1 \documentclass[dvipsnames,14pt,t]{beamer} |
2 \usepackage{beamerthemeplaincu} |
2 \usepackage{../slides} |
3 \usepackage[absolute,overlay]{textpos} |
3 \usepackage{../graphics} |
4 \usepackage{ifthen} |
|
5 \usepackage{tikz} |
|
6 \usepackage{pgf} |
|
7 \usepackage{calc} |
|
8 \usepackage{ulem} |
|
9 \usepackage{courier} |
|
10 \usepackage{listings} |
|
11 \renewcommand{\uline}[1]{#1} |
|
12 \usetikzlibrary{arrows} |
|
13 \usetikzlibrary{automata} |
|
14 \usetikzlibrary{shapes} |
|
15 \usetikzlibrary{shadows} |
|
16 \usetikzlibrary{positioning} |
|
17 \usetikzlibrary{calc} |
|
18 \usetikzlibrary{plotmarks} |
|
19 \usepackage{graphicx} |
|
20 \usepackage{../langs} |
4 \usepackage{../langs} |
21 \usepackage{../data} |
5 \usepackage{../data} |
22 |
6 \usepackage{../grammar} |
23 |
7 |
24 \makeatletter |
8 \hfuzz=220pt |
25 \lst@CCPutMacro\lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{-{}}} |
9 |
26 \@empty\z@\@empty |
10 \pgfplotsset{compat=1.11} |
27 \makeatother |
11 |
28 |
12 \newcommand{\bl}[1]{\textcolor{blue}{#1}} |
29 |
13 |
30 % beamer stuff |
14 % beamer stuff |
31 \renewcommand{\slidecaption}{AFL 06, King's College London, 30.~October 2013} |
15 \renewcommand{\slidecaption}{AFL 06, King's College London} |
32 \newcommand{\bl}[1]{\textcolor{blue}{#1}} |
|
33 \newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
34 |
16 |
35 \begin{document} |
17 \begin{document} |
36 |
18 |
|
19 |
|
20 |
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
38 \mode<presentation>{ |
22 \begin{frame}[t] |
39 \begin{frame}<1>[t] |
|
40 \frametitle{% |
23 \frametitle{% |
41 \begin{tabular}{@ {}c@ {}} |
24 \begin{tabular}{@ {}c@ {}} |
42 \\[-3mm] |
25 \\[-3mm] |
43 \LARGE Automata and \\[-2mm] |
26 \LARGE Automata and \\[-2mm] |
44 \LARGE Formal Languages (6)\\[3mm] |
27 \LARGE Formal Languages (6)\\[3mm] |
51 Office: & S1.27 (1st floor Strand Building)\\ |
34 Office: & S1.27 (1st floor Strand Building)\\ |
52 Slides: & KEATS (also home work is there)\\ |
35 Slides: & KEATS (also home work is there)\\ |
53 \end{tabular} |
36 \end{tabular} |
54 \end{center} |
37 \end{center} |
55 |
38 |
56 |
39 \end{frame} |
57 \end{frame}} |
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
41 |
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
60 \mode<presentation>{ |
43 \begin{frame}[c] |
61 \begin{frame}[c] |
44 \frametitle{Regular Languages} |
62 \frametitle{\begin{tabular}{c}Regular Languages\end{tabular}} |
45 |
63 |
46 While regular expressions are very useful for lexing, there is |
64 While regular expressions are very useful for lexing, |
47 no regular expression that can recognise the language |
65 there is no regular expression that can recognise the language \bl{$a^nb^n$}.\bigskip |
48 \bl{$a^nb^n$}.\bigskip |
66 |
49 |
67 \begin{center} |
50 \begin{center} |
68 \bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$} |
51 \bl{$(((()()))())$} \;\;vs.\;\; \bl{$(((()()))()))$} |
69 \end{center} |
52 \end{center}\bigskip\bigskip |
70 |
53 |
71 |
54 \small |
72 \end{frame}} |
55 \noindent So we cannot find out with regular expressions |
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
56 whether parentheses are matched or unmatched. |
74 |
57 |
75 |
58 \end{frame} |
76 \newcommand{\qq}{\mbox{\texttt{"}}} |
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
60 |
78 \mode<presentation>{ |
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
79 \begin{frame}[c] |
62 \begin{frame}[c] |
80 \frametitle{\begin{tabular}{c}Grammars\end{tabular}} |
63 \frametitle{Hierarchy of Languages} |
|
64 |
|
65 \begin{center} |
|
66 \begin{tikzpicture} |
|
67 [rect/.style={draw=black!50, |
|
68 top color=white, |
|
69 bottom color=black!20, |
|
70 rectangle, |
|
71 very thick, |
|
72 rounded corners}] |
|
73 |
|
74 \draw (0,0) node [rect, text depth=39mm, text width=68mm] {all languages}; |
|
75 \draw (0,-0.4) node [rect, text depth=28.5mm, text width=64mm] {decidable languages}; |
|
76 \draw (0,-0.85) node [rect, text depth=17mm] {context sensitive languages}; |
|
77 \draw (0,-1.14) node [rect, text depth=9mm, text width=50mm] {context-free languages}; |
|
78 \draw (0,-1.4) node [rect] {regular languages}; |
|
79 \end{tikzpicture} |
|
80 |
|
81 \end{center} |
|
82 |
|
83 \end{frame} |
|
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
85 |
|
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
87 \begin{frame}[c] |
|
88 \frametitle{Grammars} |
81 |
89 |
82 A (context-free) grammar \bl{$G$} consists of |
90 A (context-free) grammar \bl{$G$} consists of |
83 |
91 |
84 \begin{itemize} |
92 \begin{itemize} |
85 \item a finite set of nonterminal symbols (upper case) |
93 \item a finite set of nonterminal symbols (upper case) |
252 \item Once generated, terminals are ``permanent''. |
250 \item Once generated, terminals are ``permanent''. |
253 \item Terminals ought to be tokens of the language\\ |
251 \item Terminals ought to be tokens of the language\\ |
254 (but can also be strings). |
252 (but can also be strings). |
255 \end{itemize} |
253 \end{itemize} |
256 |
254 |
257 \end{frame}} |
255 \end{frame} |
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
259 |
257 |
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
261 \mode<presentation>{ |
259 \begin{frame}[c] |
262 \begin{frame}[c] |
260 \frametitle{Parse Trees} |
263 \frametitle{\begin{tabular}{c}Parse Trees\end{tabular}} |
|
264 |
261 |
265 \begin{center} |
262 \begin{center} |
266 \bl{\begin{tabular}{lcl} |
263 \bl{\begin{tabular}{lcl} |
267 $E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\ |
264 $E$ & $\rightarrow$ & $F \;|\; F \cdot * \cdot F$\\ |
268 $F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\ |
265 $F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\ |
319 \end{center}\pause\bigskip |
314 \end{center}\pause\bigskip |
320 |
315 |
321 A CFG is \alert{left-recursive} if it has a nonterminal \bl{$E$} such |
316 A CFG is \alert{left-recursive} if it has a nonterminal \bl{$E$} such |
322 that \bl{$E \rightarrow^+ E\cdot \ldots$} |
317 that \bl{$E \rightarrow^+ E\cdot \ldots$} |
323 |
318 |
324 \end{frame}} |
319 \end{frame} |
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
326 |
321 |
327 |
322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
323 \begin{frame}[c] |
329 \mode<presentation>{ |
324 \frametitle{Ambiguous Grammars} |
330 \begin{frame}[c] |
325 |
331 \frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}} |
326 A grammar is \alert{ambiguous} if there is a string that has |
332 |
327 at least two different parse trees. |
333 A grammar is \alert{ambiguous} if there is a string that has at least two different parse trees. |
|
334 |
328 |
335 |
329 |
336 \begin{center} |
330 \begin{center} |
337 \bl{\begin{tabular}{lcl} |
331 \bl{\begin{tabular}{lcl} |
338 $E$ & $\rightarrow$ & $num\_token$ \\ |
332 $E$ & $\rightarrow$ & $num\_token$ \\ |
381 $\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$ |
373 $\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$ |
382 \end{center} |
374 \end{center} |
383 \end{minipage}\bigskip |
375 \end{minipage}\bigskip |
384 |
376 |
385 \begin{itemize} |
377 \begin{itemize} |
|
378 \item atomic parsers |
386 \item sequencing |
379 \item sequencing |
387 \item alternative |
380 \item alternative |
388 \item semantic action |
381 \item semantic action |
389 \end{itemize} |
382 \end{itemize} |
390 |
383 |
391 \end{frame}} |
384 \end{frame} |
392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
393 |
386 |
394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
395 \mode<presentation>{ |
388 \begin{frame}[c] |
|
389 |
|
390 Atomic parsers, for example, number tokens |
|
391 |
|
392 \begin{center} |
|
393 \bl{$\texttt{Num(123)}::rest \;\Rightarrow\; \{(\texttt{Num(123)}, rest)\}$} |
|
394 \end{center}\bigskip |
|
395 |
|
396 \begin{itemize} |
|
397 \item you consume one or more token from the\\ |
|
398 input (stream) |
|
399 \item also works for characters and strings |
|
400 \end{itemize} |
|
401 \end{frame} |
|
402 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
403 |
|
404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
396 \begin{frame}[c] |
405 \begin{frame}[c] |
397 |
406 |
398 Alternative parser (code \bl{$p\;||\;q$})\bigskip |
407 Alternative parser (code \bl{$p\;||\;q$})\bigskip |
399 |
408 |
400 \begin{itemize} |
409 \begin{itemize} |
401 \item apply \bl{$p$} and also \bl{$q$}; then combine the outputs |
410 \item apply \bl{$p$} and also \bl{$q$}; then combine |
|
411 the outputs |
402 \end{itemize} |
412 \end{itemize} |
403 |
413 |
404 \begin{center} |
414 \begin{center} |
405 \large \bl{$p(\text{input}) \cup q(\text{input})$} |
415 \large \bl{$p(\text{input}) \cup q(\text{input})$} |
406 \end{center} |
416 \end{center} |
407 |
417 |
408 |
418 \end{frame} |
409 \end{frame}} |
|
410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
411 |
420 |
412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
413 \mode<presentation>{ |
422 \mode<presentation>{ |
414 \begin{frame}[c] |
423 \begin{frame}[c] |
515 |
527 |
516 \end{frame}} |
528 \end{frame}} |
517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
518 |
530 |
519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
520 \mode<presentation>{ |
532 \begin{frame}[c] |
521 \begin{frame}[c] |
533 \frametitle{Input Types of Parsers} |
522 \frametitle{\begin{tabular}{c}Input Types of Parsers\end{tabular}} |
534 |
523 |
535 \begin{itemize} |
524 \begin{itemize} |
536 \item input: \alert{token list} |
525 \item input: \alert{string} |
537 \item output: set of (output\_type, \alert{token list}) |
526 \item output: set of (output\_type, \alert{string}) |
|
527 \end{itemize}\bigskip\pause |
538 \end{itemize}\bigskip\pause |
528 |
539 |
529 actually it can be any input type as long as it is a kind of sequence |
540 actually it can be any input type as long as it is a kind of |
530 (for example a string) |
541 sequence (for example a string) |
531 |
542 |
532 \end{frame}} |
543 \end{frame} |
533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
544 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
534 |
545 |
535 |
546 |
536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
537 \mode<presentation>{ |
548 \begin{frame}[c] |
538 \begin{frame}[c] |
549 \frametitle{Scannerless Parsers} |
539 \frametitle{\begin{tabular}{c}Scannerless Parsers\end{tabular}} |
|
540 |
550 |
541 \begin{itemize} |
551 \begin{itemize} |
542 \item input: \alert{string} |
552 \item input: \alert{string} |
543 \item output: set of (output\_type, \alert{string}) |
553 \item output: set of (output\_type, \alert{string}) |
544 \end{itemize}\bigskip |
554 \end{itemize}\bigskip |
545 |
555 |
546 but lexers are better when whitespaces or comments need to be filtered out; |
556 but lexers are better when whitespaces or comments need to be |
547 then input is a sequence of tokens |
557 filtered out; then input is a sequence of tokens |
548 |
558 |
549 \end{frame}} |
559 \end{frame} |
550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
551 |
561 |
552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
562 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
553 \mode<presentation>{ |
563 \begin{frame}[c] |
554 \begin{frame}[c] |
564 \frametitle{Successful Parses} |
555 \frametitle{\begin{tabular}{c}Successful Parses\end{tabular}} |
|
556 |
565 |
557 \begin{itemize} |
566 \begin{itemize} |
558 \item input: string |
567 \item input: string |
559 \item output: \alert{set of} (output\_type, string) |
568 \item output: \alert{set of} (output\_type, string) |
560 \end{itemize}\bigskip |
569 \end{itemize}\bigskip |
561 |
570 |
562 a parse is successful whenever the input has been |
571 a parse is successful whenever the input has been fully |
563 fully ``consumed'' (that is the second component is empty) |
572 ``consumed'' (that is the second component is empty) |
564 |
573 |
565 |
574 \end{frame} |
566 \end{frame}} |
|
567 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
568 |
576 |
569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
570 \mode<presentation>{ |
|
571 \begin{frame}[c] |
578 \begin{frame}[c] |
572 \frametitle{Abstract Parser Class} |
579 \frametitle{Abstract Parser Class} |
573 |
580 |
574 \mbox{\lstset{language=Scala}\fontsize{10}{12}\selectfont |
581 \small |
575 \texttt{\lstinputlisting{../progs/app7.scala}}} |
582 \lstinputlisting[language=Scala,xleftmargin=1mm]{../progs/app7.scala} |
576 \end{frame}} |
583 \end{frame} |
577 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
584 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
578 |
585 |
579 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
580 \mode<presentation>{ |
587 \begin{frame}[c] |
581 \begin{frame}[c] |
588 |
582 {\lstset{language=Scala}\fontsize{10}{12}\selectfont |
589 \small |
583 \texttt{\lstinputlisting{../progs/app8.scala}}} |
590 \fontsize{10}{12}\selectfont |
584 \end{frame}} |
591 \lstinputlisting[language=Scala,xleftmargin=1mm]{../progs/app8.scala} |
|
592 \end{frame} |
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
593 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
586 |
594 |
587 |
595 |
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
589 \mode<presentation>{ |
597 \begin{frame}[c] |
590 \begin{frame}[c] |
598 \frametitle{Two Grammars} |
591 \frametitle{\begin{tabular}{c}Two Grammars\end{tabular}} |
|
592 |
599 |
593 Which languages are recognised by the following two grammars? |
600 Which languages are recognised by the following two grammars? |
594 |
601 |
595 \begin{center} |
602 \begin{center} |
596 \bl{\begin{tabular}{lcl} |
603 \bl{\begin{tabular}{lcl} |
604 $U$ & $\rightarrow$ & $1 \cdot U$\\ |
611 $U$ & $\rightarrow$ & $1 \cdot U$\\ |
605 & $|$ & $\epsilon$ |
612 & $|$ & $\epsilon$ |
606 \end{tabular}} |
613 \end{tabular}} |
607 \end{center} |
614 \end{center} |
608 |
615 |
609 \end{frame}} |
616 \end{frame} |
610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
611 |
618 |
612 |
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
614 \mode<presentation>{ |
|
615 \begin{frame}[t] |
620 \begin{frame}[t] |
616 \frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}} |
621 \frametitle{Ambiguous Grammars} |
617 |
622 |
618 \mbox{}\\[-25mm]\mbox{} |
623 \begin{center} |
619 |
624 \begin{tikzpicture} |
620 \begin{center} |
625 \begin{axis}[xlabel={\pcode{1}s},ylabel={time in secs}, |
621 \begin{tikzpicture}[y=.2cm, x=.009cm] |
626 enlargelimits=false, |
622 %axis |
627 xtick={0,100,...,1000}, |
623 \draw (0,0) -- coordinate (x axis mid) (1000,0); |
628 xmax=1050, |
624 \draw (0,0) -- coordinate (y axis mid) (0,30); |
629 ymax=33, |
625 %ticks |
630 ytick={0,5,...,30}, |
626 \foreach \x in {0, 20, 100, 200,...,1000} |
631 scaled ticks=false, |
627 \draw (\x,1pt) -- (\x,-3pt) |
632 axis lines=left, |
628 node[anchor=north] {\small \x}; |
633 width=11cm, |
629 \foreach \y in {0,5,...,30} |
634 height=7cm, |
630 \draw (1pt,\y) -- (-3pt,\y) |
635 legend entries={unambiguous,ambiguous}, |
631 node[anchor=east] {\small\y}; |
636 legend pos=north east, |
632 %labels |
637 legend cell align=left, |
633 \node[below=0.6cm] at (x axis mid) {\bl{1}s}; |
638 x tick label style={font=\small,/pgf/number format/1000 sep={}}] |
634 \node[rotate=90, left=1.2cm] at (y axis mid) {secs}; |
639 \addplot[blue,mark=*, mark options={fill=white}] |
635 |
640 table {s-grammar1.data}; |
636 %plots |
641 \only<2>{ |
637 \draw[color=blue] plot[mark=*, mark options={fill=white}] |
642 \addplot[red,mark=triangle*, mark options={fill=white}] |
638 file {s-grammar1.data}; |
643 table {s-grammar2.data};} |
639 \only<2->{\draw[color=red] plot[mark=triangle*, mark options={fill=white} ] |
644 \end{axis} |
640 file {s-grammar2.data};} |
|
641 %legend |
|
642 \begin{scope}[shift={(400,20)}] |
|
643 \draw[color=blue] (0,0) -- |
|
644 plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0) |
|
645 node[right]{\small unambiguous}; |
|
646 \only<2->{\draw[yshift=\baselineskip, color=red] (0,0) -- |
|
647 plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0) |
|
648 node[right]{\small ambiguous};} |
|
649 \end{scope} |
|
650 \end{tikzpicture} |
645 \end{tikzpicture} |
651 \end{center} |
646 \end{center} |
652 |
647 |
653 \end{frame}} |
648 \end{frame} |
654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
655 |
650 |
656 |
651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
652 \begin{frame} |
658 \mode<presentation>{ |
653 \frametitle{While-Language} |
659 \begin{frame}[c] |
654 \mbox{}\\[-23mm]\mbox{} |
660 \frametitle{\begin{tabular}{c}While-Language\end{tabular}} |
655 |
661 |
656 \bl{\begin{plstx}[rhs style=,one per line] |
662 |
657 : \meta{Stmt} ::= skip |
663 \begin{center} |
658 | \meta{Id} := \meta{AExp} |
664 \bl{\begin{tabular}{@{}lcl@{}} |
659 | if \meta{BExp} then \meta{Block} else \meta{Block} |
665 $Stmt$ & $\rightarrow$ & $\text{skip}$\\ |
660 | while \meta{BExp} do \meta{Block}\\ |
666 & $|$ & $Id := AExp$\\ |
661 : \meta{Stmts} ::= \meta{Stmt} ; \meta{Stmts} |
667 & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\ |
662 | \meta{Stmt}\\ |
668 & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\medskip\\ |
663 : \meta{Block} ::= \{ \meta{Stmts} \} |
669 $Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\ |
664 | \meta{Stmt}\\ |
670 & $|$ & $Stmt$\medskip\\ |
665 : \meta{AExp} ::= \ldots\\ |
671 $Block$ & $\rightarrow$ & $\{ Stmts \}$\\ |
666 : \meta{BExp} ::= \ldots\\ |
672 & $|$ & $Stmt$\medskip\\ |
667 \end{plstx}} |
673 $AExp$ & $\rightarrow$ & \ldots\\ |
668 |
674 $BExp$ & $\rightarrow$ & \ldots\\ |
669 \end{frame} |
675 \end{tabular}} |
670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
676 \end{center} |
671 |
677 |
672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
678 |
673 \begin{frame}[c] |
679 \end{frame}} |
674 \frametitle{An Interpreter} |
680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
681 |
|
682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
683 \mode<presentation>{ |
|
684 \begin{frame}[c] |
|
685 \frametitle{\begin{tabular}{c}An Interpreter\end{tabular}} |
|
686 |
675 |
687 \begin{center} |
676 \begin{center} |
688 \bl{\begin{tabular}{l} |
677 \bl{\begin{tabular}{l} |
689 $\{$\\ |
678 $\{$\\ |
690 \;\;$x := 5 \text{;}$\\ |
679 \;\;$x := 5 \text{;}$\\ |