slides/slides06.tex
changeset 597 ce8419e3915c
parent 531 f6e937ed0332
child 598 e3ad67cd5123
equal deleted inserted replaced
596:6d6e79f95933 597:ce8419e3915c
     1 \documentclass[dvipsnames,14pt,t]{beamer}
     1 \documentclass[dvipsnames,14pt,t]{beamer}
     2 \usepackage{../slides}
     2 \usepackage{../slides}
     3 \usepackage{../graphics}
     3 \usepackage{../graphics}
     4 \usepackage{../langs}
     4 \usepackage{../langs}
     5 \usepackage{../data}
     5 \usepackage{../data}
     6 
     6 \usepackage{../grammar}
     7 
     7 
     8 % beamer stuff 
     8 % beamer stuff 
     9 \renewcommand{\slidecaption}{CFL 06, King's College London}
     9 \renewcommand{\slidecaption}{CFL 06, King's College London}
    10 
    10 
    11 
    11 
    26 
    26 
    27   \normalsize
    27   \normalsize
    28   \begin{center}
    28   \begin{center}
    29   \begin{tabular}{ll}
    29   \begin{tabular}{ll}
    30   Email:  & christian.urban at kcl.ac.uk\\
    30   Email:  & christian.urban at kcl.ac.uk\\
    31   Office: & N7.07 (North Wing, Bush House)\\
    31   Office: & N\liningnums{7.07} (North Wing, Bush House)\\
    32   Slides: & KEATS (also home work is there)\\
    32   Slides: & KEATS (also home work is there)\\
    33   \end{tabular}
    33   \end{tabular}
    34   \end{center}
    34   \end{center}
    35 
    35 
    36 \end{frame}
    36 \end{frame}
   116 \begin{center}
   116 \begin{center}
   117 \bl{$1::rest \;\Rightarrow\; \{(1, rest)\}$} 
   117 \bl{$1::rest \;\Rightarrow\; \{(1, rest)\}$} 
   118 \end{center}\bigskip
   118 \end{center}\bigskip
   119 
   119 
   120 \begin{itemize}
   120 \begin{itemize}
   121 \item you consume one or more token from the\\ 
   121 \item you consume one or more tokens from the\\ 
   122   input (stream)
   122   input (stream)
   123 \item also works for characters and strings
   123 \item also works for characters and strings
   124 \end{itemize}
   124 \end{itemize}
   125 \end{frame}
   125 \end{frame}
   126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   225 \begin{frame}[c]
   225 \begin{frame}[c]
   226 \frametitle{Two Grammars}
   226 \frametitle{Two Grammars}
   227 
   227 
   228 Which languages are recognised by the following two grammars?
   228 Which languages are recognised by the following two grammars?
   229 
   229 
   230 \begin{center}
   230 \bl{\begin{plstx}[margin=3cm]
   231 \bl{\begin{tabular}{lcl}
   231 : \meta{S} ::= \liningnums{1}\cdot\meta{S}\cdot \meta{S} | \epsilon\\
   232 $S$ & $\rightarrow$ &  $1 \cdot S \cdot S$\\
   232 \end{plstx}}
   233         & $|$ & $\epsilon$
   233 
   234 \end{tabular}}
   234 \bl{\begin{plstx}[margin=3cm]
   235 \end{center}\bigskip
   235 : \meta{U} ::= \liningnums{1}\cdot\meta{U} | \epsilon\\
   236 
   236 \end{plstx}}
   237 \begin{center}
       
   238 \bl{\begin{tabular}{lcl}
       
   239 $U$ & $\rightarrow$ &  $1 \cdot U$\\
       
   240         & $|$ & $\epsilon$
       
   241 \end{tabular}}
       
   242 \end{center}
       
   243 
   237 
   244 \end{frame}
   238 \end{frame}
   245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   246 
   240 
   247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   275 
   269 
   276 \end{frame}
   270 \end{frame}
   277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   278 
   272 
   279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   280 \mode<presentation>{
   274 \begin{frame}[c]
   281 \begin{frame}[c]
   275 \frametitle{Arithmetic Expressions}
   282 \frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
       
   283 
   276 
   284 A grammar for arithmetic expressions and numbers:
   277 A grammar for arithmetic expressions and numbers:
   285 
   278 
       
   279 \bl{\begin{plstx}[margin=1cm]
       
   280     : \meta{E} ::= \meta{E} \cdot + \cdot \meta{E}
       
   281     | \meta{E} \cdot * \cdot \meta{E}
       
   282     | ( \cdot \meta{E} \cdot )  | \meta{N}\\
       
   283     : \meta{N} ::= \meta{N} \cdot \meta{N} |
       
   284     0 | 1 | \ldots | 9\\
       
   285 \end{plstx}}
       
   286 
       
   287 Unfortunately it is left-recursive (and ambiguous).\medskip\\
       
   288 A problem for \alert{recursive descent parsers} (e.g.~parser
       
   289 combinators).  \bigskip\pause
       
   290 
       
   291 \end{frame}
       
   292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   293 
       
   294 
       
   295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   296 \begin{frame}[t]
       
   297 \frametitle{Numbers}
       
   298 
       
   299 \bl{\begin{plstx}[margin=1cm]
       
   300     : \meta{N} ::= \meta{N} \cdot \meta{N} |
       
   301     0 | 1 | \ldots | 9\\
       
   302 \end{plstx}}
       
   303 
       
   304 A non-left-recursive, non-ambiguous grammar for numbers:
       
   305 
       
   306 \bl{\begin{plstx}[margin=1cm]
       
   307     : \meta{N} ::= 0 \cdot \meta{N} | 1 \cdot \meta{N} | \ldots |
       
   308     0 | 1 | \ldots | 9\\
       
   309 \end{plstx}}
       
   310 
       
   311 \end{frame}
       
   312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
       
   313 
       
   314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   315 \begin{frame}[c]
       
   316 \frametitle{Removing Left-Recursion}
       
   317 
       
   318 The rule for numbers is directly left-recursive:
       
   319 
   286 \begin{center}
   320 \begin{center}
   287 \bl{\begin{tabular}{lcl}
   321 \bl{\begin{tabular}{lcl}
   288 $E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
   322 $\meta{N}$ & $::=$ & $\meta{N} \cdot \meta{N} \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ 
   289 $N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1 \;|\: \ldots \;|\; 9$ 
       
   290 \end{tabular}}
       
   291 \end{center}
       
   292 
       
   293 Unfortunately it is left-recursive (and ambiguous).\medskip\\
       
   294 A problem for \alert{recursive descent parsers} (e.g.~parser combinators).
       
   295 \bigskip\pause
       
   296 
       
   297 \end{frame}}
       
   298 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   299 
       
   300 
       
   301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   302 \mode<presentation>{
       
   303 \begin{frame}[t]
       
   304 \frametitle{\begin{tabular}{c}Numbers\end{tabular}}
       
   305 
       
   306 
       
   307 
       
   308 \begin{center}
       
   309 \bl{\begin{tabular}{lcl}
       
   310 $N$ & $\rightarrow$ &  $N \cdot N \;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
       
   311 \end{tabular}}
       
   312 \end{center}
       
   313 
       
   314 A non-left-recursive, non-ambiguous grammar for numbers:
       
   315 
       
   316 \begin{center}
       
   317 \bl{\begin{tabular}{lcl}
       
   318 $N$ & $\rightarrow$ &  $0 \cdot N \;|\;1 \cdot N \;|\;\ldots\;|\; 0 \;|\; 1 \;|\; \ldots \;|\; 9$\\
       
   319 \end{tabular}}
       
   320 \end{center}
       
   321 
       
   322 
       
   323 \end{frame}}
       
   324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
       
   325 
       
   326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   327 \mode<presentation>{
       
   328 \begin{frame}[c]
       
   329 \frametitle{\begin{tabular}{c}Removing Left-Recursion\end{tabular}}
       
   330 
       
   331 The rule for numbers is directly left-recursive:
       
   332 
       
   333 \begin{center}
       
   334 \bl{\begin{tabular}{lcl}
       
   335 $N$ & $\rightarrow$ & $N \cdot N \;|\; 0 \;|\; 1\;\;\;\;(\ldots)$ 
       
   336 \end{tabular}}
   323 \end{tabular}}
   337 \end{center}
   324 \end{center}
   338 
   325 
   339 Translate
   326 Translate
   340 
   327 
   341 \begin{center}
   328 \begin{center}
   342 \begin{tabular}{ccc}
   329 \begin{tabular}{ccc}
   343 \bl{\begin{tabular}{lcl}
   330 \bl{\begin{tabular}{lcl}
   344 $N$ & $\rightarrow$ & $N \cdot \alpha$\\
   331 $\meta{N}$ & $::=$ & $\meta{N} \cdot \alpha$\\
   345  &  $\;|\;$ & $\beta$\\
   332  &  $\;|\;$ & $\beta$\\
   346  \\ 
   333  \\ 
   347 \end{tabular}} 
   334 \end{tabular}} 
   348 & {\Large$\Rightarrow$} &
   335 & {\Large$\Rightarrow$} &
   349 \bl{\begin{tabular}{lcl}
   336 \bl{\begin{tabular}{lcl}
   350 $N$ & $\rightarrow$ & $\beta \cdot N'$\\
   337 $\meta{N}$ & $::=$ & $\beta \cdot \meta{N}'$\\
   351 $N'$ & $\rightarrow$ & $\alpha \cdot N'$\\
   338 $\meta{N}'$ & $::=$ & $\alpha \cdot \meta{N}'$\\
   352  &  $\;|\;$ & $\epsilon$ 
   339  &  $\;|\;$ & $\epsilon$ 
   353 \end{tabular}}
   340 \end{tabular}}
   354 \end{tabular}
   341 \end{tabular}
   355 \end{center}\pause
   342 \end{center}\pause
   356 
   343 
   357 Which means
   344 Which means in this case:
   358 
   345 
   359 \begin{center}
   346 \begin{center}
   360 \bl{\begin{tabular}{lcl}
   347 \bl{\begin{tabular}{lcl}
   361 $N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1 \cdot N'$\\
   348 $\meta{N}$ & $\rightarrow$ & $0 \cdot \meta{N}' \;|\; 1 \cdot \meta{N}'$\\
   362 $N'$ & $\rightarrow$ & $N \cdot N' \;|\; \epsilon$\\
   349 $\meta{N}'$ & $\rightarrow$ & $\meta{N} \cdot \meta{N}' \;|\; \epsilon$\\
   363 \end{tabular}}
   350 \end{tabular}}
   364 \end{center}
   351 \end{center}
   365 
   352 
   366 
   353 
   367 \end{frame}}
   354 \end{frame}
   368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   369 
   356 
   370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   371 \mode<presentation>{
   358 \begin{frame}[c]
   372 \begin{frame}[c]
   359 \frametitle{Operator Precedences}
   373 \frametitle{\begin{tabular}{c}Operator Precedences\end{tabular}}
       
   374 
   360 
   375 
   361 
   376 To disambiguate
   362 To disambiguate
   377 
   363 
   378 \begin{center}
   364 \begin{center}
   379 \bl{\begin{tabular}{lcl}
   365 \bl{\begin{tabular}{lcl}
   380 $E$ & $\rightarrow$ &  $E \cdot + \cdot E \;|\;E \cdot * \cdot E \;|\;( \cdot E \cdot ) \;|\;N$ \\
   366 $\meta{E}$ & $::=$ &  $\meta{E} \cdot + \cdot \meta{E} \;|\;\meta{E} \cdot * \cdot \meta{E} \;|\;( \cdot \meta{E} \cdot ) \;|\;\meta{N}$ \\
   381 \end{tabular}}
   367 \end{tabular}}
   382 \end{center}
   368 \end{center}
   383 
   369 
   384 Decide on how many precedence levels, say\medskip\\
   370 Decide on how many precedence levels, say\medskip\\
   385 \hspace{5mm}highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+}
   371 highest for \bl{$()$}, medium for \bl{*}, lowest for \bl{+}
   386 
   372 
   387 \begin{center}
   373 \begin{center}
   388 \bl{\begin{tabular}{lcl}
   374 \bl{\begin{tabular}{lcl}
   389 $E_{low}$ & $\rightarrow$ & $E_{med} \cdot + \cdot E_{low} \;|\; E_{med}$ \\
   375 $\meta{E}_{low}$ & $::=$ & $\meta{E}_{med} \cdot + \cdot \meta{E}_{low} \;|\; \meta{E}_{med}$ \\
   390 $E_{med}$ & $\rightarrow$ & $E_{hi} \cdot * \cdot E_{med} \;|\; E_{hi}$\\
   376 $\meta{E}_{med}$ & $::=$ & $\meta{E}_{hi} \cdot * \cdot \meta{E}_{med} \;|\; \meta{E}_{hi}$\\
   391 $E_{hi}$ & $\rightarrow$ &  $( \cdot E_{low} \cdot ) \;|\;N$ \\
   377 $\meta{E}_{hi}$ & $::=$ &  $( \cdot \meta{E}_{low} \cdot ) \;|\;\meta{N}$ \\
   392 \end{tabular}}
   378 \end{tabular}}
   393 \end{center}\pause
   379 \end{center}\pause
   394 
   380 
   395 \small What happens with \bl{$1 + 3  + 4$}?
   381 \small What happens with \bl{$1 + 3  + 4$}?
   396 \end{frame}}
   382 \end{frame}
   397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   398 
   384 
   399 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   400 \mode<presentation>{
   386 \begin{frame}[c]
   401 \begin{frame}[c]
   387 \frametitle{Chomsky Normal Form}
   402 \frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
       
   403 
   388 
   404 All rules must be of the form
   389 All rules must be of the form
   405 
   390 
   406 \begin{center}
   391 \begin{center}
   407 \bl{$A \rightarrow a$}
   392 \bl{$\meta{A} ::= a$}
   408 \end{center}
   393 \end{center}
   409 
   394 
   410 or
   395 or
   411 
   396 
   412 \begin{center}
   397 \begin{center}
   413 \bl{$A \rightarrow B\cdot C$}
   398 \bl{$\meta{A} ::= \meta{B}\cdot \meta{C}$}
   414 \end{center}
   399 \end{center}
   415 
   400 
   416 No rule can contain \bl{$\epsilon$}.
   401 No rule can contain \bl{$\epsilon$}.
   417 
   402 
   418 \end{frame}}
   403 \end{frame}
   419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   420 
   405 
   421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   406 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   422 \begin{frame}[c]
   407 \begin{frame}[c]
   423 \frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}}
   408 \frametitle{\begin{tabular}{c}$\epsilon$-Removal\end{tabular}}
   424 
   409 
   425 \begin{enumerate}
   410 \begin{enumerate}
   426 \item If \bl{$A\rightarrow \alpha \cdot B \cdot \beta$} and \bl{$B \rightarrow \epsilon$} are in the grammar,
   411 \item If \bl{$A::= \alpha \cdot B \cdot \beta$} and \bl{$B ::= \epsilon$} are in the grammar,
   427 then add \bl{$A\rightarrow \alpha \cdot \beta$} (iterate if necessary).
   412 then add \bl{$A::= \alpha \cdot \beta$} (iterate if necessary).
   428 \item Throw out all \bl{$B \rightarrow \epsilon$}.
   413 \item Throw out all \bl{$B ::= \epsilon$}.
   429 \end{enumerate}
   414 \end{enumerate}
   430 
   415 
   431 \small
   416 \small
   432 \begin{center}
   417 \begin{center}
   433 \begin{tabular}{ccc}
   418 \begin{tabular}{ccc}
   434 \bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
   419 \bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
   435 $N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'$\\
   420 $N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'$\\
   436 $N'$ & $\rightarrow$ & $N \cdot N'\;|\;\epsilon$\\
   421 $N'$ & $::=$ & $N \cdot N'\;|\;\epsilon$\\
   437 \\ 
   422 \\ 
   438 \\
   423 \\
   439 \\
   424 \\
   440 \\
   425 \\
   441 \\
   426 \\
   442 \end{tabular}} &
   427 \end{tabular}} &
   443 \bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
   428 \bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
   444 \\
   429 \\
   445 $N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
   430 $N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
   446 $N'$ & $\rightarrow$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\
   431 $N'$ & $::=$ & $N \cdot N'\;|\;N\;|\;\epsilon$\\
   447 \\
   432 \\
   448 $N$ & $\rightarrow$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
   433 $N$ & $::=$ & $0 \cdot N' \;|\; 1\cdot N'\;|\;0\;|\;1$\\
   449 $N'$ & $\rightarrow$ & $N \cdot N'\;|\;N$\\
   434 $N'$ & $::=$ & $N \cdot N'\;|\;N$\\
   450 \end{tabular}}
   435 \end{tabular}}
   451 \end{tabular}
   436 \end{tabular}
   452 \end{center}
   437 \end{center}
   453 
   438 
   454 \pause\normalsize
   439 \pause\normalsize
   455 \begin{center}
   440 \begin{center}
   456 \bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
   441 \bl{\begin{tabular}{l@{\hspace{1mm}}c@{\hspace{1mm}}l}
   457 $N$ & $\rightarrow$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\
   442 $N$ & $::=$ & $0 \cdot N\;|\; 1\cdot N\;|\;0\;|\;1$\\
   458 \end{tabular}}
   443 \end{tabular}}
   459 
   444 
   460 \end{center}
   445 \end{center}
   461 \end{frame}
   446 \end{frame}
   462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   463 
   448 
   464 
   449 
   465 
   450 
   466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   467 \mode<presentation>{
   452 \begin{frame}[c]
   468 \begin{frame}[c]
   453 \frametitle{CYK Algorithm}
   469 \frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
       
   470 
   454 
   471 If grammar is in Chomsky normalform \ldots
   455 If grammar is in Chomsky normalform \ldots
   472 
   456 
   473 \begin{center}
   457 \begin{center}
   474 \bl{\begin{tabular}{@ {}lcl@ {}}
   458 \bl{\begin{tabular}{@ {}lcl@ {}}
   475 $S$ & $\rightarrow$ &  $N\cdot P$ \\
   459 $\meta{S}$ & $::=$ &  $\meta{N}\cdot \meta{P}$ \\
   476 $P$ & $\rightarrow$ &  $V\cdot N$ \\
   460 $\meta{P}$ & $::=$ &  $\meta{V}\cdot \meta{N}$ \\
   477 $N$ & $\rightarrow$ &  $N\cdot N$ \\
   461 $\meta{N}$ & $::=$ &  $\meta{N}\cdot \meta{N}$ \\
   478 $N$ & $\rightarrow$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
   462 $\meta{N}$ & $::=$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
   479 $V$ & $\rightarrow$ &  $\texttt{trains}$ 
   463 $\meta{V}$ & $::=$ &  $\texttt{trains}$ 
   480 \end{tabular}}
   464 \end{tabular}}
   481 \end{center}
   465 \end{center}
   482 
   466 
   483 \bl{\texttt{Jeff trains geometry students}}
   467 \bl{\texttt{Jeff trains geometry students}}
   484 
   468 
   485 \end{frame}}
   469 \end{frame}
   486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   470 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   471 
   488 \mode<presentation>{
   472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   489 \begin{frame}[c]
   473 \begin{frame}[c]
   490 \frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
   474 \frametitle{CYK Algorithm}
   491 
   475 
   492 
   476 
   493 \begin{itemize}
   477 \begin{itemize}
   494 \item fastest possible algorithm for recognition problem
   478 \item fastest possible algorithm for recognition problem
   495 \item runtime is \bl{$O(n^3)$}\bigskip
   479 \item runtime is \bl{$O(n^3)$}\bigskip
   496 \item grammars need to be transferred into CNF
   480 \item grammars need to be transformed into CNF
   497 \end{itemize}
   481 \end{itemize}
   498 
   482 
   499 \end{frame}}
   483 \end{frame}
   500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
   484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
   501 
   485 
   502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   503 \begin{frame}[c]
   487 \begin{frame}[c]
   504 \frametitle{The Goal of this Course}
   488 \frametitle{The Goal of this Course}
   543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   544 \begin{frame}[c]
   528 \begin{frame}[c]
   545 
   529 
   546 \begin{center}
   530 \begin{center}
   547 \bl{\begin{tabular}{@{}lcl@{}}
   531 \bl{\begin{tabular}{@{}lcl@{}}
   548 \textit{Stmt} & $\rightarrow$ &  $\texttt{skip}$\\
   532 \textit{Stmt} & $::=$ &  $\texttt{skip}$\\
   549               & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
   533               & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
   550               & $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\
   534               & $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\
   551               & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
   535               & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
   552               & $|$ & \texttt{read}\;\textit{Id}\\
   536               & $|$ & \texttt{read}\;\textit{Id}\\
   553               & $|$ & \texttt{write}\;\textit{Id}\\
   537               & $|$ & \texttt{write}\;\textit{Id}\\
   554               & $|$ & \texttt{write}\;\textit{String}\medskip\\
   538               & $|$ & \texttt{write}\;\textit{String}\medskip\\
   555 \textit{Stmts} & $\rightarrow$ &  \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
   539 \textit{Stmts} & $::=$ &  \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
   556               & $|$ & \textit{Stmt}\medskip\\
   540               & $|$ & \textit{Stmt}\medskip\\
   557 \textit{Block} & $\rightarrow$ &  \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
   541 \textit{Block} & $::=$ &  \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
   558                 & $|$ & \textit{Stmt}\medskip\\
   542                 & $|$ & \textit{Stmt}\medskip\\
   559 \textit{AExp} & $\rightarrow$ & \ldots\\
   543 \textit{AExp} & $::=$ & \ldots\\
   560 \textit{BExp} & $\rightarrow$ & \ldots\\
   544 \textit{BExp} & $::=$ & \ldots\\
   561 \end{tabular}}
   545 \end{tabular}}
   562 \end{center}
   546 \end{center}
   563 \end{frame}
   547 \end{frame}
   564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   565 
   549