%&p1
\begin{document}
\frame{\titlepage}

\section{Introduction}
\begin{frame}
	\frametitle{\textsc{SPL}}
	\framesubtitle{Acronym for: \textsc{SPL}: Parser and Lexer}
	\begin{block}{Features}
		\begin{itemize}
			\item Implementation language:
				Clean ({\tiny\url{http://clean.cs.ru.nl}})
				\pause
				\begin{itemize}
					\item Pure language
					\item Higher order functions
					\item Monads
					\item Using parser combinator library \textsc{Yard}
				\end{itemize}
			\pause
			\item Positional data available for easy locating of errors.
			\pause
			\item Standardized parser errors. This means you can set it as
				\texttt{buildprg} in \texttt{vim} and you can then use the
				quickfix window!
		\end{itemize}
	\end{block}
\end{frame}

\begin{frame}[fragile]
	\frametitle{\textsc{YARD}}
	\framesubtitle{A minimal home grown monadic parser combinator library}
	\begin{itemize}
		\item Inspired by \textsc{parsec}: $1pc=3.375\cdot10^{16}yd$~\footnote{
				A yard is exactly $36$ inch and an inch is exactly the length
				of $3$ barleycorns}.
		\item Definitons:
			\begin{lstlisting}
:: Error = PositionalError Int Int String | Error String
:: Parser a b = Parser ([a] -> (Either Error b, [a]))
			\end{lstlisting}
		\pause
		\item Matches longest left-most parser
		\pause
		\item Stops immediately on error\pause\\
			By design!
	\end{itemize}
\end{frame}

\begin{frame}[fragile]
	\frametitle{\textsc{YARD} Combinators}
	\begin{lstlisting}
instance Functor (Parser a)
instance Applicative (Parser a)
instance Monad (Parser a)
instance Alternative (Parser a)

runParser :: (Parser a b) [a] -> (Either Error b, [a])
(<?>) :: (Parser a b) Error -> Parser a b
fail :: Parser a b
top :: Parser a a
peek :: Parser a a
satisfy :: (a -> Bool) -> Parser a a
check :: (a -> Bool) -> Parser a a
(until) infix 2 :: (Parser a b) (Parser a c) -> Parser a [b]
item :: a -> Parser a a | Eq a
list :: [a] -> Parser a [a] | Eq a
eof :: Parser a Void
	\end{lstlisting}
\end{frame}

\section{Design choices}
\begin{frame}
	\frametitle{Adapting the grammar}
	\begin{itemize}
		\item Remove left recursion
		\item Fixing associativity
		\item Added small features such as escape characters \texttt{
			\textbackslash n\textbackslash b}
		\pause
		\item Show grammar now\ldots
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Two-phase design}
	\framesubtitle{Lexing}
	Also done with \textsc{YARD} because
	\begin{itemize}
		\item Multiline comments
		\item Alternatives
		\item Positions
	\end{itemize}
\end{frame}

\begin{frame}[fragile]
	\frametitle{Two-phase design}
	\framesubtitle{Parsing}
	Read from stdin, write to stdout\\
	Added some handy primitives
	\begin{lstlisting}
parseBlock :: Parser Token [Stmt]

parseOpR :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr
parseOpL :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr

trans2 :: TokenValue (TokenValue -> a) -> Parser Token a
trans1 :: TokenValue a -> Parser Token a

peekPos :: Parser Token Pos
	\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
	\frametitle{Statistics}
	\framesubtitle{Lines of code}
	\lstinputlisting{|"wc -l ../../*.[di]cl"}
	\pause
	\begin{block}{}
		\emph{``Measuring programming progress by lines of code is like
		measuring aircraft building progress by weight.''}\\
		{---} Bill Gates
	\end{block}
\end{frame}

\begin{frame}
	\frametitle{Statistics}
	\framesubtitle{Hours of work}
	We have no clue how much time we have worked on it\ldots
	\pause
	\begin{block}{}
		\emph{``Choose a job you love, and you will never have to work a day in
		your life.''}\\
		{---} Confucius
	\end{block}
\end{frame}

\section{Examples}
\begin{frame}
	\frametitle{Weird inputs}
	\begin{itemize}
		\item \pause Heap full
			\pause\ldots Increase heap\\
			\texttt{\$ ./spl -h 2000M}
		\item \pause Stack full
			\pause\ldots Increase stack\\
			\texttt{\$ ./spl -s 200M}
		\item \pause Segmentation fault
			\pause\ldots Enable memory overcommitting\\
				\texttt{\# echo 1 > /proc/sys/vm/overcommit\_memory}
		\item \pause Still segmentation fault
			\pause\ldots Buy more \textsc{RAM}
		\item \pause Still segmentation fault?
			\pause\ldots Divide into modules and parse separatly~\footnote{To be
			implemented}
		\item \pause Thus, we are only limited by hardware\ldots
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Learned lessons}
	\begin{itemize}
		\item \pause Parser combinators are elegant!
		\item \pause Positional errors are a must!
		\item \ldots
	\end{itemize}
\end{frame}
\end{document}
