Binary file coursework/cw02.pdf has changed
--- a/coursework/cw02.tex Wed Oct 19 08:46:50 2016 +0100
+++ b/coursework/cw02.tex Sat Oct 22 13:11:33 2016 +0100
@@ -95,6 +95,15 @@
\end{tabular}
\end{center}
+\noindent
+Later on you will also need the record regular expressions:
+
+\begin{center}
+\begin{tabular}{ll}
+$REC(x:r)$ & record regular expression\\
+\end{tabular}
+\end{center}
+
\noindent Try to design your regular expressions to be as
small as possible. For example you should use character ranges
for identifiers and numbers.
@@ -129,7 +138,7 @@
\begin{tabular}{ll}
regex: & string:\smallskip\\
$a^{\{3\}}$ & $aaa$\\
-$(a + \epsilon)^{\{3\}}$ & $aa$
+$(a + \ONE)^{\{3\}}$ & $aa$
\end{tabular}
\end{center}
--- a/progs/comb1.scala Wed Oct 19 08:46:50 2016 +0100
+++ b/progs/comb1.scala Sat Oct 22 13:11:33 2016 +0100
@@ -5,34 +5,42 @@
* I <% Seq[_] , which means that the input type I can be
* treated, or seen, as a sequence. */
-abstract class Parser[I <% Seq[_], T] {
- def parse(ts: I): Set[(T, I)]
+trait Input {
+ def isEmpty: Boolean
+}
+
- def parse_all(ts: I) : Set[T] =
+abstract class Parser[T] {
+
+ def parse(ts: Input): Set[(T, Input)]
+
+ def parse_all(ts: Input) : Set[T] =
for ((head, tail) <- parse(ts);
if (tail.isEmpty)) yield head
}
-class SeqParser[I <% Seq[_], T, S](p: => Parser[I, T],
- q: => Parser[I, S]) extends Parser[I, (T, S)] {
- def parse(sb: I) =
+class SeqParser[T, S](p: => Parser[T],
+ q: => Parser[S]) extends Parser[(T, S)] {
+ def parse(sb: Input) =
for ((head1, tail1) <- p.parse(sb);
(head2, tail2) <- q.parse(tail1)) yield ((head1, head2), tail2)
}
-class AltParser[I <% Seq[_], T](p: => Parser[I, T],
- q: => Parser[I, T]) extends Parser[I, T] {
- def parse(sb: I) = p.parse(sb) ++ q.parse(sb)
+class AltParser[T](p: => Parser[T],
+ q: => Parser[T]) extends Parser[T] {
+ def parse(sb: Input) = p.parse(sb) ++ q.parse(sb)
}
-class FunParser[I <% Seq[_], T, S](p: => Parser[I, T],
- f: T => S) extends Parser[I, S] {
- def parse(sb: I) =
+class FunParser[T, S](p: => Parser[T],
+ f: T => S) extends Parser[S] {
+ def parse(sb: Input) =
for ((head, tail) <- p.parse(sb)) yield (f(head), tail)
}
// atomic parsers
-case class CharParser(c: Char) extends Parser[String, Char] {
+case class CharParser(c: Char) extends Parser[Char] {
+ type Input = String
+
def parse(sb: String) =
if (sb.head == c) Set((c, sb.tail)) else Set()
}
--- a/progs/re3.scala Wed Oct 19 08:46:50 2016 +0100
+++ b/progs/re3.scala Sat Oct 22 13:11:33 2016 +0100
@@ -63,6 +63,9 @@
def matcher(r: Rexp, s: String) : Boolean = nullable(ders(s.toList, r))
+var regex = NTIMES(CHAR('a'),5)
+println(matcher(regex,"aaaaa"))
+
//one or zero
def OPT(r: Rexp) = ALT(r, ONE)
--- a/slides/slides11.tex Wed Oct 19 08:46:50 2016 +0100
+++ b/slides/slides11.tex Sat Oct 22 13:11:33 2016 +0100
@@ -7,7 +7,7 @@
% beamer stuff
-\renewcommand{\slidecaption}{AFL, King's College London}
+\renewcommand{\slidecaption}{CFL, King's College London}
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
@@ -18,7 +18,7 @@
\frametitle{%
\begin{tabular}{@ {}c@ {}}
\\[-3mm]
- \LARGE Automata and \\[-2mm]
+ \LARGE Compilers and \\[-2mm]
\LARGE Formal Languages\\[3mm]
\end{tabular}}
--- a/slides/slides12.tex Wed Oct 19 08:46:50 2016 +0100
+++ b/slides/slides12.tex Sat Oct 22 13:11:33 2016 +0100
@@ -6,7 +6,7 @@
\usepackage{../grammar}
% beamer stuff
-\renewcommand{\slidecaption}{AFL, King's College London}
+\renewcommand{\slidecaption}{CFL, King's College London}
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
@@ -17,7 +17,7 @@
\frametitle{%
\begin{tabular}{@ {}c@ {}}
\\[-3mm]
- \LARGE Automata and \\[-2mm]
+ \LARGE Compilers and \\[-2mm]
\LARGE Formal Languages\\[3mm]
\end{tabular}}