slides/slides06.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 30 Oct 2013 03:36:10 +0000
changeset 169 57df3d7b4a25
parent 168 e60c4a9ba340
child 170 fa187fa5b642
permissions -rw-r--r--
added slides
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
\documentclass[dvipsnames,14pt,t]{beamer}
168
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     2
\usepackage{beamerthemeplaincu}
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     3
%\usepackage[T1]{fontenc}
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     4
%\usepackage[latin1]{inputenc}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
\usepackage{mathpartir}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
\usepackage[absolute,overlay]{textpos}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
\usepackage{ifthen}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
\usepackage{tikz}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
\usepackage{pgf}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
\usepackage{calc} 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
\usepackage{ulem}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
\usepackage{courier}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
\usepackage{listings}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
\renewcommand{\uline}[1]{#1}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
\usetikzlibrary{arrows}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
\usetikzlibrary{automata}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
\usetikzlibrary{shapes}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
\usetikzlibrary{shadows}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
\usetikzlibrary{positioning}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
\usetikzlibrary{calc}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
\usetikzlibrary{plotmarks}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
\usepackage{graphicx} 
168
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    23
\setmonofont{Consolas}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
\definecolor{javared}{rgb}{0.6,0,0} % for strings
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
168
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    30
\makeatletter
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    31
\lst@CCPutMacro\lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{-{}}}
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    32
\@empty\z@\@empty
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    33
\makeatother
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    34
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
\lstdefinelanguage{scala}{
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  morekeywords={abstract,case,catch,class,def,%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
    do,else,extends,false,final,finally,%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
    for,if,implicit,import,match,mixin,%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
    new,null,object,override,package,%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
    private,protected,requires,return,sealed,%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
    super,this,throw,trait,true,try,%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
    type,val,var,while,with,yield},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  sensitive=true,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  morecomment=[l]{//},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  morecomment=[n]{/*}{*/},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  morestring=[b]",
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  morestring=[b]',
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  morestring=[b]"""
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
168
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    53
\lstdefinelanguage{while}{
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    54
  morekeywords={while, if, then. else, read, write},
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    55
  otherkeywords={=>,<-,<\%,<:,>:,\#,@},
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    56
  sensitive=true,
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    57
  morecomment=[l]{//},
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    58
  morecomment=[n]{/*}{*/},
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    59
  morestring=[b]",
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    60
  morestring=[b]',
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    61
  morestring=[b]"""
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    62
}
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    63
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    64
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
\lstset{language=Scala,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
	basicstyle=\ttfamily,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
	keywordstyle=\color{javapurple}\bfseries,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
	stringstyle=\color{javagreen},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
	commentstyle=\color{javagreen},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
	morecomment=[s][\color{javadocblue}]{/**}{*/},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
	numbers=left,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
	numberstyle=\tiny\color{black},
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
	stepnumber=1,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
	numbersep=10pt,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
	tabsize=2,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
	showspaces=false,
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
	showstringspaces=false}
168
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    78
	
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
% beamer stuff 
168
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    81
\renewcommand{\slidecaption}{AFL 06, King's College London, 30.~October 2013}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    86
\begin{filecontents}{s-grammar1.data}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    87
1 0.01152
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    88
51 0.07973
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    89
101 0.09726
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    90
151 0.09320
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    91
201 0.10010
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    92
251 0.16997
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    93
301 0.26662
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    94
351 0.46118
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    95
401 0.62516
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    96
451 0.87247
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    97
501 1.16334
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    98
551 1.71152
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
    99
601 2.10958
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   100
651 2.44360
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   101
701 2.98488
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   102
751 3.50326
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   103
801 4.11036
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   104
851 4.93394
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   105
901 5.77465
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   106
951 7.39123
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
\end{filecontents}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   109
\begin{filecontents}{s-grammar2.data}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   110
1 0.01280
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   111
2 0.00064
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   112
3 0.00173
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   113
4 0.00355
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   114
5 0.00965
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   115
6 0.02674
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   116
7 0.06953
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   117
8 0.11166
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   118
9 0.18707
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   119
10 0.09189
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   120
11 0.12724
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   121
12 0.24337
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   122
13 0.59304
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   123
14 1.53594
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   124
15 4.01195
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   125
16 10.73582
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   126
17 29.51587
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   127
#18 73.14163
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
\end{filecontents}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
\begin{document}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
\mode<presentation>{
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
\begin{frame}<1>[t]
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
\frametitle{%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
  \begin{tabular}{@ {}c@ {}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
  \\[-3mm]
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
  \LARGE Automata and \\[-2mm] 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
  \LARGE Formal Languages (6)\\[3mm] 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  \end{tabular}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
  \normalsize
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
  \begin{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
  \begin{tabular}{ll}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
  Email:  & christian.urban at kcl.ac.uk\\
168
e60c4a9ba340 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   147
  Office: & S1.27 (1st floor Strand Building)\\
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
  Slides: & KEATS (also home work is there)\\
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
  \end{tabular}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
  \end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
\end{frame}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   157
\newcommand{\qq}{\mbox{\texttt{"}}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
\mode<presentation>{
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
\begin{frame}[c]
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   161
\frametitle{\begin{tabular}{c}Grammars\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   162
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   163
A (context-free) grammar \bl{$G$} consists of
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
\begin{itemize}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   166
\item a finite set of nonterminal symbols (upper case)
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   167
\item a finite terminal symbols or tokens (lower case)
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   168
\item a start symbol (which must be a nonterminal)
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   169
\item a set of rules
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
\begin{center}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   171
\bl{$A \rightarrow \text{rhs}$}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
\end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   174
where \bl{rhs} are sequences involving terminals and nonterminals,
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   175
including the empty sequence \bl{$\epsilon$}.\medskip\pause
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   177
We also allow rules
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   178
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   179
\bl{$A \rightarrow \text{rhs}_1 | \text{rhs}_2 | \ldots$}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   180
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   181
\end{itemize}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
\end{frame}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
\mode<presentation>{
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
\begin{frame}[c]
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   190
\frametitle{\begin{tabular}{c}Palindromes\end{tabular}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
\begin{center}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   193
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   194
$S$ & $\rightarrow$ &  $\epsilon$ \\
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   195
$S$ & $\rightarrow$ &  $a\cdot S\cdot a$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   196
$S$ & $\rightarrow$ &  $b\cdot S\cdot b$ \\
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   197
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   198
\end{center}\pause
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   199
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   200
or
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   201
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   202
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   203
\bl{\begin{tabular}{lcl}
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   204
$S$ & $\rightarrow$ &  $\epsilon \;|\; a\cdot S\cdot a \;|\;b\cdot S\cdot b$ \\
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   205
\end{tabular}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
\end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
\end{frame}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
\mode<presentation>{
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
\begin{frame}[c]
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   217
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
\begin{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
\bl{\begin{tabular}{lcl}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   221
$E$ & $\rightarrow$ &  $num\_token$ \\
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   222
$E$ & $\rightarrow$ &  $E \cdot + \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   223
$E$ & $\rightarrow$ &  $E \cdot - \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   224
$E$ & $\rightarrow$ &  $E \cdot * \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   225
$E$ & $\rightarrow$ &  $( \cdot E \cdot )$ 
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
\end{tabular}}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   227
\end{center}\pause
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   229
\bl{\texttt{1 + 2 * 3 + 4}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
\end{frame}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   235
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   236
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   237
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   238
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   239
\frametitle{\begin{tabular}{c}A CFG Derivation\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   240
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   241
\begin{enumerate}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   242
\item Begin with a string containing only the start symbol, say \bl{$S$}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   243
\item Replace any nonterminal \bl{$X$} in the string by the
right-hand side of some production \bl{$X \rightarrow \text{rhs}$}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   244
\item Repeat 2 until there are no nonterminals
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   245
\end{enumerate}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   246
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   247
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   248
\bl{$S \rightarrow \ldots \rightarrow \ldots  \rightarrow \ldots  \rightarrow \ldots $}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   249
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   250
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   251
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   252
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   253
  
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   254
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   255
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   256
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   257
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   258
\frametitle{\begin{tabular}{c}Example Derivation\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   259
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   260
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   261
\bl{\begin{tabular}{lcl}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   262
$S$ & $\rightarrow$ &  $\epsilon \;|\; a\cdot S\cdot a \;|\;b\cdot S\cdot b$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   263
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   264
\end{center}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   265
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   266
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   267
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   268
\begin{tabular}{lcl}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   269
\bl{$S$} & \bl{$\rightarrow$} & \bl{$aSa$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   270
              & \bl{$\rightarrow$} & \bl{$abSba$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   271
              & \bl{$\rightarrow$} & \bl{$abaSaba$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   272
              & \bl{$\rightarrow$} & \bl{$abaaba$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   273
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   274
 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   275
\end{tabular}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   276
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   277
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   278
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   279
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   280
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   281
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   282
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   283
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   284
\frametitle{\begin{tabular}{c}Example Derivation\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   285
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   286
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   287
\bl{\begin{tabular}{lcl}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   288
$E$ & $\rightarrow$ &  $num\_token$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   289
$E$ & $\rightarrow$ &  $E \cdot + \cdot E$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   290
$E$ & $\rightarrow$ &  $E \cdot - \cdot E$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   291
$E$ & $\rightarrow$ &  $E \cdot * \cdot E$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   292
$E$ & $\rightarrow$ &  $( \cdot E \cdot )$ 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   293
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   294
\end{center}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   295
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   296
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   297
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   298
\begin{tabular}{@{}c@{}c@{}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   299
\begin{tabular}{l@{\hspace{1mm}}l@{\hspace{1mm}}l}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   300
\bl{$E$} & \bl{$\rightarrow$} & \bl{$E*E$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   301
              & \bl{$\rightarrow$} & \bl{$E+E*E$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   302
              & \bl{$\rightarrow$} & \bl{$E+E*E+E$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   303
              & \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   304
\end{tabular} &\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   305
\begin{tabular}{l@{\hspace{1mm}}l@{\hspace{1mm}}l}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   306
\bl{$E$} & \bl{$\rightarrow$} & \bl{$E+E$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   307
              & \bl{$\rightarrow$} & \bl{$E+E+E$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   308
              & \bl{$\rightarrow$} & \bl{$E+E*E+E$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   309
              & \bl{$\rightarrow^+$} & \bl{$1+2*3+4$}\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   310
\end{tabular}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   311
\end{tabular}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   312
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   313
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   314
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   315
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   316
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   317
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   318
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   319
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   320
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   321
\frametitle{\begin{tabular}{c}Language of a CFG\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   322
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   323
Let \bl{$G$} be a context-free grammar with start symbol \bl{$S$}. 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   324
Then the language \bl{$L(G)$} is:
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   325
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   326
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   327
\bl{$\{c_1\ldots c_n \;|\; \forall i.\; c_i \in T \wedge S \rightarrow^* c_1\ldots c_n \}$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   328
\end{center}\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   329
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   330
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   331
\item Terminals, because there are no rules for replacing them.
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   332
\item Once generated, terminals are ``permanent''.
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   333
\item Terminals ought to be tokens of the language\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   334
(but can also be strings).
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   335
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   336
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   337
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   338
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   339
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
\mode<presentation>{
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
\begin{frame}[c]
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   343
\frametitle{\begin{tabular}{c}Parse Trees\end{tabular}}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
\begin{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
\bl{\begin{tabular}{lcl}
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   347
$E$ & $\rightarrow$ &  $F \;|\; F \cdot * \cdot F$\\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   348
$F$ & $\rightarrow$ & $T \;|\; T \cdot + \cdot T \;|\; T \cdot - \cdot T$\\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   349
$T$ & $\rightarrow$ & $num\_token \;|\; ( \cdot E \cdot )$\\
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
\end{tabular}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
\end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
\begin{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
\begin{tikzpicture}[level distance=8mm, blue]
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   355
  \node {$E$}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   356
    child {node {$F$} 
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   357
     child {node {$T$} 
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   358
                 child {node {(\,$E$\,)}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   359
                            child {node{$F$ *{} $F$}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   360
                                  child {node {$T$} child {node {2}}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   361
                                  child {node {$T$} child {node {3}}} 
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
                               }
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
                          }
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
              }
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   365
     child {node {+}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   366
     child {node {$T$}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   367
       child {node {(\,$E$\,)} 
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   368
       child {node {$F$}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   369
       child {node {$T$ +{} $T$}
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
                    child {node {3}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
                    child {node {4}} 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
                 }
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
                 }}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
    }};
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
\end{tikzpicture}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
\end{center}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   378
\begin{textblock}{5}(1, 6.5)
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
\bl{\texttt{(2*3)+(3+4)}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
\end{textblock}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
\end{frame}}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   384
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   385
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   386
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   387
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   388
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   389
\frametitle{\begin{tabular}{c}Arithmetic Expressions\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   390
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   391
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   392
\bl{\begin{tabular}{lcl}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   393
$E$ & $\rightarrow$ &  $num\_token$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   394
$E$ & $\rightarrow$ &  $E \cdot + \cdot E$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   395
$E$ & $\rightarrow$ &  $E \cdot - \cdot E$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   396
$E$ & $\rightarrow$ &  $E \cdot * \cdot E$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   397
$E$ & $\rightarrow$ &  $( \cdot E \cdot )$ 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   398
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   399
\end{center}\pause\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   400
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   401
A CFG is \alert{left-recursive} if it has a nonterminal \bl{$E$} such
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   402
that \bl{$E \rightarrow^+ E\cdot \ldots$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   403
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   404
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   405
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   406
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   407
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   408
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   409
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   410
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   411
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   412
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   413
A grammar is \alert{ambiguous} if there is a string that has at least two different parse trees.
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   414
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   415
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   416
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   417
\bl{\begin{tabular}{lcl}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   418
$E$ & $\rightarrow$ &  $num\_token$ \\
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   419
$E$ & $\rightarrow$ &  $E \cdot + \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   420
$E$ & $\rightarrow$ &  $E \cdot - \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   421
$E$ & $\rightarrow$ &  $E \cdot * \cdot E$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   422
$E$ & $\rightarrow$ &  $( \cdot E \cdot )$ 
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   423
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   424
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   425
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   426
\bl{\texttt{1 + 2 * 3 + 4}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   427
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   428
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   429
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   430
169
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   431
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   432
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   433
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   434
\frametitle{\begin{tabular}{c}Dangling Else\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   435
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   436
Another ambiguous grammar:\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   437
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   438
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   439
\bl{\begin{tabular}{lcl}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   440
$E$ & $\rightarrow$ &  if $E$ then $E$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   441
 & $|$ &  if $E$ then $E$ else $E$ \\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   442
 & $|$ &  \ldots
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   443
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   444
\end{center}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   445
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   446
\bl{\texttt{if a then if x then y else c}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   447
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   448
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   449
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   450
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   451
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   452
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   453
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   454
\frametitle{\begin{tabular}{c}Parser Combinators\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   455
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   456
Parser combinators: \bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   457
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   458
\begin{minipage}{1.1\textwidth}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   459
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   460
\mbox{}\hspace{-12mm}\mbox{}$\underbrace{\text{list of tokens}}_{\text{input}}$ \bl{$\Rightarrow$} 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   461
$\underbrace{\text{set of (parsed input, unparsed input)}}_{\text{output}}$
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   462
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   463
\end{minipage}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   464
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   465
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   466
\item sequencing
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   467
\item alternative
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   468
\item semantic action
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   469
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   470
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   471
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   472
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   473
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   474
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   475
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   476
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   477
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   478
Alternative parser (code \bl{$p\;||\;q$})\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   479
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   480
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   481
\item apply \bl{$p$} and also \bl{$q$}; then combine the outputs
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   482
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   483
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   484
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   485
\large \bl{$p(\text{input}) \cup q(\text{input})$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   486
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   487
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   488
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   489
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   490
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   491
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   492
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   493
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   494
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   495
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   496
Sequence parser (code \bl{$p\sim q$})\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   497
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   498
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   499
\item apply first \bl{$p$} producing a set of pairs
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   500
\item then apply \bl{$q$} to the unparsed parts
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   501
\item then combine the results:\\ \mbox{}\;\;((output$_1$, output$_2$), unparsed part)
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   502
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   503
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   504
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   505
\begin{tabular}{l}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   506
\large \bl{$\{((o_1, o_2), u_2) \;|\;$}\\[2mm] 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   507
\large\mbox{}\hspace{15mm} \bl{$(o_1, u_1) \in p(\text{input}) \wedge$}\\[2mm]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   508
\large\mbox{}\hspace{15mm} \bl{$(o_2, u_2) \in q(u_1)\}$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   509
\end{tabular}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   510
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   511
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   512
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   513
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   514
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   515
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   516
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   517
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   518
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   519
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   520
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   521
Function parser (code \bl{$p \Rightarrow f$})\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   522
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   523
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   524
\item apply \bl{$p$} producing a set of pairs
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   525
\item then apply the function \bl{$f$} to each first component
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   526
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   527
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   528
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   529
\begin{tabular}{l}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   530
\large \bl{$\{(f(o_1), u_1) \;|\; (o_1, u_1) \in p(\text{input})\}$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   531
\end{tabular}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   532
\end{center}\bigskip\bigskip\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   533
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   534
\bl{$f$} is the semantic action (``what to do with the parsed input'')
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   535
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   536
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   537
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   538
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   539
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   540
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   541
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   542
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   543
\frametitle{\begin{tabular}{c}Semantic Actions\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   544
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   545
Addition
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   546
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   547
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   548
\bl{$T \sim + \sim E \Rightarrow \underbrace{f((x,y), z) \Rightarrow x + z}_{\text{semantic action}}$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   549
\end{center}\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   550
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   551
Multiplication
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   552
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   553
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   554
\bl{$F \sim * \sim T \Rightarrow f((x,y), z) \Rightarrow x * z$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   555
\end{center}\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   556
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   557
Parenthesis
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   558
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   559
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   560
\bl{$\text{(} \sim E \sim \text{)} \Rightarrow f((x,y), z) \Rightarrow y$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   561
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   562
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   563
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   564
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   565
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   566
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   567
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   568
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   569
\frametitle{\begin{tabular}{c}Types of Parsers\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   570
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   571
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   572
\item {\bf Sequencing}: if \bl{$p$} returns results of type \bl{$T$}, and \bl{$q$} results of type \bl{$S$},
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   573
then \bl{$p \sim q$} returns results of type
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   574
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   575
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   576
\bl{$T \times S$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   577
\end{center}\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   578
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   579
\item {\bf Alternative}: if \bl{$p$} returns results of type \bl{$T$} then  \bl{$q$} \alert{must} also have results of type \bl{$T$},
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   580
and \bl{$p \;||\; q$} returns results of type
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   581
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   582
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   583
\bl{$T$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   584
\end{center}\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   585
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   586
\item {\bf Semantic Action}: if \bl{$p$} returns results of type \bl{$T$} and \bl{$f$} is a function from
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   587
\bl{$T$} to \bl{$S$}, then
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   588
\bl{$p \Rightarrow f$} returns results of type
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   589
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   590
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   591
\bl{$S$}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   592
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   593
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   594
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   595
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   596
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   597
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   598
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   599
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   600
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   601
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   602
\frametitle{\begin{tabular}{c}Input Types of Parsers\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   603
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   604
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   605
\item input: \alert{string}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   606
\item output: set of (output\_type, \alert{string})
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   607
\end{itemize}\bigskip\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   608
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   609
actually it can be any input type as long as it is a kind of sequence
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   610
(for example a string)
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   611
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   612
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   613
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   614
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   615
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   616
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   617
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   618
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   619
\frametitle{\begin{tabular}{c}Scannerless Parsers\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   620
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   621
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   622
\item input: \alert{string}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   623
\item output: set of (output\_type, \alert{string})
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   624
\end{itemize}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   625
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   626
but lexers are better when whitespaces or comments need to be filtered out;
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   627
then input is a sequence of tokens
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   628
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   629
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   630
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   631
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   632
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   633
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   634
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   635
\frametitle{\begin{tabular}{c}Successful Parses\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   636
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   637
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   638
\item input: string
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   639
\item output: \alert{set of} (output\_type, string)
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   640
\end{itemize}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   641
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   642
a parse is successful whenever the input has been
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   643
fully ``consumed'' (that is the second component is empty)
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   644
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   645
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   646
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   647
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   648
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   649
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   650
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   651
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   652
\frametitle{Abstract Parsers}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   653
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   654
\mbox{\lstset{language=Scala}\fontsize{10}{12}\selectfont
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   655
\texttt{\lstinputlisting{../progs/app7.scala}}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   656
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   657
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   658
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   659
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   660
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   661
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   662
{\lstset{language=Scala}\fontsize{10}{12}\selectfont
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   663
\texttt{\lstinputlisting{../progs/app8.scala}}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   664
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   665
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   666
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   667
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   668
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   669
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   670
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   671
\frametitle{\begin{tabular}{c}Two Grammars\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   672
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   673
Which languages are recognised by the following two grammars?
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   674
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   675
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   676
\bl{\begin{tabular}{lcl}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   677
$S$ & $\rightarrow$ &  $1 \cdot S \cdot S$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   678
        & $|$ & $\epsilon$
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   679
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   680
\end{center}\bigskip
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   681
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   682
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   683
\bl{\begin{tabular}{lcl}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   684
$U$ & $\rightarrow$ &  $1 \cdot U$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   685
        & $|$ & $\epsilon$
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   686
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   687
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   688
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   689
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   690
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   691
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   692
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   693
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   694
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   695
\begin{frame}[t]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   696
\frametitle{\begin{tabular}{c}Ambiguous Grammars\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   697
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   698
\mbox{}\\[-25mm]\mbox{}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   699
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   700
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   701
\begin{tikzpicture}[y=.2cm, x=.009cm]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   702
 	%axis
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   703
	\draw (0,0) -- coordinate (x axis mid) (1000,0);
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   704
    	\draw (0,0) -- coordinate (y axis mid) (0,30);
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   705
    	%ticks
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   706
    	\foreach \x in {0, 20, 100, 200,...,1000}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   707
     		\draw (\x,1pt) -- (\x,-3pt)
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   708
			node[anchor=north] {\small \x};
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   709
    	\foreach \y in {0,5,...,30}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   710
     		\draw (1pt,\y) -- (-3pt,\y) 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   711
     			node[anchor=east] {\small\y}; 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   712
	%labels      
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   713
	\node[below=0.6cm] at (x axis mid) {\bl{1}s};
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   714
	\node[rotate=90, left=1.2cm] at (y axis mid) {secs};
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   715
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   716
	%plots
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   717
	\draw[color=blue] plot[mark=*, mark options={fill=white}] 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   718
		file {s-grammar1.data};
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   719
         \only<2->{\draw[color=red] plot[mark=triangle*, mark options={fill=white} ] 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   720
                  file {s-grammar2.data};}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   721
	%legend
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   722
	\begin{scope}[shift={(400,20)}] 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   723
	\draw[color=blue] (0,0) -- 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   724
		plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0) 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   725
		node[right]{\small unambiguous};
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   726
	\only<2->{\draw[yshift=\baselineskip, color=red] (0,0) -- 
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   727
                plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0)
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   728
                node[right]{\small ambiguous};}  
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   729
	\end{scope}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   730
\end{tikzpicture}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   731
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   732
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   733
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   734
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   735
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   736
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   737
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   738
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   739
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   740
\frametitle{\begin{tabular}{c}While-Language\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   741
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   742
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   743
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   744
\bl{\begin{tabular}{@{}lcl@{}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   745
$Stmt$ & $\rightarrow$ &  $\text{skip}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   746
              & $|$ & $Id := AExp$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   747
              & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   748
              & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\medskip\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   749
$Stmts$ & $\rightarrow$ &  $Stmt \;\text{;}\; Stmts$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   750
              & $|$ & $Stmt$\medskip\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   751
$Block$ & $\rightarrow$ &  $\{ Stmts \}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   752
                & $|$ & $Stmt$\medskip\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   753
$AExp$ & $\rightarrow$ & \ldots\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   754
$BExp$ & $\rightarrow$ & \ldots\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   755
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   756
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   757
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   758
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   759
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   760
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   761
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   762
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   763
\mode<presentation>{
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   764
\begin{frame}[c]
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   765
\frametitle{\begin{tabular}{c}An Interpreter\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   766
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   767
\begin{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   768
\bl{\begin{tabular}{l}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   769
$\{$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   770
\;\;$x := 5 \text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   771
\;\;$y := x * 3\text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   772
\;\;$y := x * 4\text{;}$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   773
\;\;$x := u * 3$\\
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   774
$\}$
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   775
\end{tabular}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   776
\end{center}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   777
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   778
\begin{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   779
\item the interpreter has to record the value of \bl{$x$} before assigning a value to \bl{$y$}\pause
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   780
\item \bl{\text{eval}(stmt, env)}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   781
\end{itemize}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   782
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   783
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   784
\end{frame}}
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   785
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
57df3d7b4a25 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 168
diff changeset
   786
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   787
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   788
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   789
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   790
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   791
\frametitle{\begin{tabular}{c}Chomsky Normal Form\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   792
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   793
All rules must be of the form
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   794
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   795
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   796
\bl{$A \rightarrow a$}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   797
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   798
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   799
or
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   800
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   801
\begin{center}
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   802
\bl{$A \rightarrow B\cdot C$}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   803
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   804
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   805
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   806
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   807
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   808
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   809
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   810
\mode<presentation>{
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   811
\begin{frame}[c]
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   812
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   813
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   814
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   815
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   816
\bl{\begin{tabular}{@ {}lcl}
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   817
$S$ & $\rightarrow$ &  $N\cdot P$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   818
$P$ & $\rightarrow$ &  $V\cdot N$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   819
$N$ & $\rightarrow$ &  $N\cdot N$ \\
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   820
$N$ & $\rightarrow$ &  $\texttt{students} \;|\; \texttt{Jeff} \;|\; \texttt{geometry} \;|\; \texttt{trains} $ \\
56
Christian Urban <urbanc@in.tum.de>
parents: 53
diff changeset
   821
$V$ & $\rightarrow$ &  $\texttt{trains}$ 
53
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   822
\end{tabular}}
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   823
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   824
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   825
\bl{\texttt{Jeff trains geometry students}}
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   826
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   827
\end{frame}}
Christian Urban <urbanc@in.tum.de>
parents: 52
diff changeset
   828
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
51
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   829
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   830
\mode<presentation>{
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   831
\begin{frame}[c]
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   832
\frametitle{\begin{tabular}{c}CYK Algorithm\end{tabular}}
50
Christian Urban <urbanc@in.tum.de>
parents: 49
diff changeset
   833
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   834
52
Christian Urban <urbanc@in.tum.de>
parents: 51
diff changeset
   835
\begin{itemize}
Christian Urban <urbanc@in.tum.de>
parents: 51
diff changeset
   836
\item runtime is \bl{$O(n^3)$}\bigskip
Christian Urban <urbanc@in.tum.de>
parents: 51
diff changeset
   837
\item grammars need to be transferred into CNF
Christian Urban <urbanc@in.tum.de>
parents: 51
diff changeset
   838
\end{itemize}
51
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   839
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   840
\end{frame}}
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   841
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
6fe4facb56a6 updated
Christian Urban <urbanc@in.tum.de>
parents: 50
diff changeset
   842
49
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   843
\end{document}
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   844
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   845
%%% Local Variables:  
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   846
%%% mode: latex
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   847
%%% TeX-master: t
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   848
%%% End: 
d2c6852ca8da added programs and slides
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   849