From: Mart Lubbers Date: Wed, 16 Mar 2016 09:55:53 +0000 (+0100) Subject: added some slides X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=4a5da1494c927aabc027e8164fd0655449149aa9;p=cc1516.git added some slides --- diff --git a/deliverables/.gitignore b/deliverables/.gitignore index 1c934b1..b3a9a94 100644 --- a/deliverables/.gitignore +++ b/deliverables/.gitignore @@ -5,3 +5,4 @@ *.out *.snm *.toc +*.vrb diff --git a/deliverables/p1/p1.pdf b/deliverables/p1/p1.pdf index 10b2596..72bf5b8 100644 Binary files a/deliverables/p1/p1.pdf and b/deliverables/p1/p1.pdf differ diff --git a/deliverables/p1/p1.tex b/deliverables/p1/p1.tex index 3984b6d..54708af 100644 --- a/deliverables/p1/p1.tex +++ b/deliverables/p1/p1.tex @@ -2,37 +2,148 @@ \begin{document} \frame{\titlepage} -%- Anything that is specific to your parser +\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} + Added some handy primitives + \begin{lstlisting} +parseSColon :: (Parser Token a) -> Parser Token a +parseBlock :: Parser Token [Stmt] +parseOpR :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr +parseOpL :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr +parseBBraces :: (Parser Token a) -> Parser Token a +parseBCBraces :: (Parser Token a) -> Parser Token a +parseBSqBraces :: (Parser Token a) -> Parser Token a +trans :: TokenValue (TokenValue -> a) -> Parser Token (Pos, a) +trans2 :: TokenValue (TokenValue -> a) -> Parser Token a +trans1 :: TokenValue a -> Parser Token a +peekPos :: Parser Token Pos + \end{lstlisting} +\end{frame} + + +\section{Examples} + +%- Anything that is specific to your parser % - Positions Pim % - yard (parser combinators) Pim % - Implementation language Pim % - Elaborate diffulties and eases (Tussendoor) % - LL* Mart -%- Did you split it into two phases lexing and parsing, or just one phase? Pim +%- Did you split it into two phases lexing and parsing, or just one phase? Pim % - Why parser combinator for lexer -%- Did you change the grammar, and if so how? Mart +%- Did you change the grammar, and if so how? Mart % - Standard tricks, remove left assoc, get operator assoc correct. -% - How did you solve the problems of precedence and associativity? -%- Does your parser stop after the first encountered error or can it go on? Pim -% (bij Yard erin fietsen) +% - How did you solve the problems of precedence and associativity? % - Stops, this is design, parsing should be correct!!!1! -%- For a couple of example programs, when you do a sequence of Mart -% 1. parse -% 2. pretty-print -% 3. parse -% 4. pretty-print +%- For a couple of example programs, when you do a sequence of Mart +% 1. parse +% 2. pretty-print +% 3. parse +% 4. pretty-print % -- Dit gaan we met een shell scriptje doen %- Code metrics, loc, etc, met stomme xkcd Mart -% How many lines of code do you have, how many hours did you work on it? +% How many lines of code do you have, how many hours did you work on it? % “Measuring programming progress by lines of code is like measuring % aircraft building progress by weight.” % % ― Bill Gates % Hoeveel uur, ook geen idee. Ook een stomme quote -%- Did you try your parser on weird inputs, like 100 megabyte of nested Mart -%parenthesis? 1 gigabyte? +%- Did you try your parser on weird inputs, like 100 megabyte of nested Mart +%parenthesis? 1 gigabyte? % - Yes, we did, didn't work out. Uses big heap and stack -%- Problems and learned things +%- Problems and learned things %- Demonstrate your parser and pretty-printer on two or three programs that you % find interesting Mart (teminaldingen kun jij goed ;)) \end{document} diff --git a/deliverables/p1/pre.tex b/deliverables/p1/pre.tex index 06184f2..306a236 100644 --- a/deliverables/p1/pre.tex +++ b/deliverables/p1/pre.tex @@ -1,14 +1,9 @@ \documentclass{beamer} -\AtBeginSection[]{% - \begin{frame} - \frametitle{Table of Contents} - \tableofcontents[currentsection] - \end{frame} -} +\usepackage{listings} -\title[P1]{Lexical Analysis and Parsing} -%\subtitle{} +\title[cc1516: Lexing \& Parsing]{SPL} +\subtitle{SPL: Lexical Analysis and Parsing} \author[P. Jager, M. Lubbers]{Pim Jager\inst{1}\and Mart Lubbers\inst{1}} \institute[Radboud University]{% \inst{1}% @@ -17,3 +12,18 @@ } \subject{Parser} \date{\today} + +\AtBeginSection[]{% + \begin{frame} + \frametitle{Table of Contents} + \tableofcontents[currentsection] + \end{frame} +} + +\lstset{% + basicstyle=\ttfamily\footnotesize, + breaklines +} + +\usetheme{Warsaw} +\usecolortheme{beaver}