# HG changeset patch # User Christian Urban # Date 1539335814 -3600 # Node ID 414f1daf57286192b0655d92a65a7dfc7d4c3fbd # Parent 5ca3abaa76d09ead875bd761dd14a61cdfbc9087 updated diff -r 5ca3abaa76d0 -r 414f1daf5728 coursework/cw01.pdf Binary file coursework/cw01.pdf has changed diff -r 5ca3abaa76d0 -r 414f1daf5728 coursework/cw01.tex --- a/coursework/cw01.tex Tue Oct 09 08:25:40 2018 +0100 +++ b/coursework/cw01.tex Fri Oct 12 10:16:54 2018 +0100 @@ -1,3 +1,4 @@ + \documentclass{article} \usepackage{../style} \usepackage{../langs} @@ -70,7 +71,8 @@ like that.} That means do not treat the extended regular expressions by just translating them into the basic ones. See also Question 3, where you are asked to explicitly give the rules for \textit{nullable} -and \textit{der} for the extended regular expressions.\medskip +and \textit{der} for the extended regular expressions. So something like +$der\,c\,(r^+) \dn der\,c\,(r\cdot r^*)$ is \emph{not} allowed.\medskip \noindent The meanings of the extended regular expressions are @@ -201,7 +203,16 @@ by using $\textit{ALL}^*$). In order to avoid having an explicit constructor for each case, we can generalise all these cases and introduce a single constructor $\textit{CFUN}(f)$ where $f$ is a function from characters -to booleans. The idea is that the function $f$ determines which character(s) +to booleans. In Scala code this would look as follows: + +\begin{lstlisting}[numbers=none] +abstract class Rexp +... +case class CFUN(f: Char => Boolean) extends Rexp +\end{lstlisting}\smallskip + +\noindent +The idea is that the function $f$ determines which character(s) are matched, namely those where $f$ returns \texttt{true}. In this question implement \textit{CFUN} and define diff -r 5ca3abaa76d0 -r 414f1daf5728 progs/dfa.scala --- a/progs/dfa.scala Tue Oct 09 08:25:40 2018 +0100 +++ b/progs/dfa.scala Fri Oct 12 10:16:54 2018 +0100 @@ -4,6 +4,7 @@ // type abbreviation for partial functions type :=>[A, B] = PartialFunction[A, B] + case class DFA[A, C](start: A, // starting state delta: (A, C) :=> A, // transition (partial fun) fins: A => Boolean) { // final states @@ -38,10 +39,11 @@ case (Q4, 'b') => Q4 } val dfa = DFA(Q0, delta, Set[State](Q4)) +dfa.accepts("aaabbb".toList) dfa.accepts("bbabaab".toList) // true dfa.accepts("baba".toList) // false - +dfa.accepts("abc".toList) // false // another DFA test with a Sink state abstract class S diff -r 5ca3abaa76d0 -r 414f1daf5728 slides/slides01.pdf Binary file slides/slides01.pdf has changed diff -r 5ca3abaa76d0 -r 414f1daf5728 slides/slides01.tex --- a/slides/slides01.tex Tue Oct 09 08:25:40 2018 +0100 +++ b/slides/slides01.tex Fri Oct 12 10:16:54 2018 +0100 @@ -20,6 +20,8 @@ \begin{document} + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[t] \frametitle{% @@ -228,7 +230,7 @@ \node [above=5mm of 0] {\makebox[0mm]{\footnotesize \begin{tabular}{@{}l@{}}input\\[-1mm]program\end{tabular}}}; - + \node (A) at (0,0) [node] {}; \node [below right] at (A.north west) {lexer}; diff -r 5ca3abaa76d0 -r 414f1daf5728 slides/slides03.pdf Binary file slides/slides03.pdf has changed