7 \frametitle{\textsc{SPL
}}
8 \framesubtitle{Acronym for:
\textsc{SPL
}: Parser and Lexer
}
9 \begin{block
}{Features
}
11 \item Implementation language:
12 Clean (
{\tiny\url{http://clean.cs.ru.nl
}})
16 \item Higher order functions
18 \item Using parser combinator library
\textsc{Yard
}
21 \item Positional data available for easy locating of errors.
23 \item Standardized parser errors. This means you can set it as
24 \texttt{buildprg
} in
\texttt{vim
} and you can then use the
30 \begin{frame
}[fragile
]
31 \frametitle{\textsc{YARD
}}
32 \framesubtitle{A minimal home grown monadic parser combinator library
}
34 \item Inspired by
\textsc{parsec
}: $
1pc=
3.375\cdot10^
{16}yd$~
\footnote{
35 A yard is exactly $
36$ inch and an inch is exactly the length
39 :: Error = PositionalError Int Int String | Error String
40 :: Parser a b = Parser (
[a
] -> (Either Error b,
[a
]))
43 \item Matches longest left-most parser
45 \item Stops immediately on error
\pause\\
50 \begin{frame
}[fragile
]
51 \frametitle{\textsc{YARD
} Combinators
}
53 instance Functor (Parser a)
54 instance Applicative (Parser a)
55 instance Monad (Parser a)
56 instance Alternative (Parser a)
58 runParser :: (Parser a b)
[a
] -> (Either Error b,
[a
])
59 (<?>) :: (Parser a b) Error -> Parser a b
63 satisfy :: (a -> Bool) -> Parser a a
64 check :: (a -> Bool) -> Parser a a
65 (until) infix
2 :: (Parser a b) (Parser a c) -> Parser a
[b
]
66 item :: a -> Parser a a | Eq a
67 list ::
[a
] -> Parser a
[a
] | Eq a
72 \section{Design choices
}
74 \frametitle{Adapting the grammar
}
76 \item Remove left recursion
77 \item Fixing associativity
78 \item Added small features such as escape characters
\texttt{
79 \textbackslash n
\textbackslash b
}
81 \item Show grammar now
\ldots
86 \frametitle{Two-phase design
}
87 \framesubtitle{Lexing
}
88 Also done with
\textsc{YARD
} because
90 \item Multiline comments
96 \begin{frame
}[fragile
]
97 \frametitle{Two-phase design
}
98 \framesubtitle{Parsing
}
99 Read from stdin, write to stdout\\
100 Added some handy primitives
102 parseBlock :: Parser Token
[Stmt
]
104 parseOpR :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr
105 parseOpL :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr
107 trans2 :: TokenValue (TokenValue -> a) -> Parser Token a
108 trans1 :: TokenValue a -> Parser Token a
110 peekPos :: Parser Token Pos
114 \begin{frame
}[fragile
]
115 \frametitle{Statistics
}
116 \framesubtitle{Lines of code
}
117 \lstinputlisting{|"wc -l ../../*.
[di
]cl"
}
120 \emph{``Measuring programming progress by lines of code is like
121 measuring aircraft building progress by weight.''
}\\
127 \frametitle{Statistics
}
128 \framesubtitle{Hours of work
}
129 We have no clue how much time we have worked on it
\ldots
132 \emph{``Choose a job you love, and you will never have to work a day in
140 \frametitle{Weird inputs
}
142 \item \pause Heap full
143 \pause\ldots Increase heap\\
144 \texttt{\$ ./spl -h
2000M
}
145 \item \pause Stack full
146 \pause\ldots Increase stack\\
147 \texttt{\$ ./spl -s
200M
}
148 \item \pause Segmentation fault
149 \pause\ldots Enable memory overcommitting\\
150 \texttt{\# echo
1 > /proc/sys/vm/overcommit
\_memory}
151 \item \pause Still segmentation fault
152 \pause\ldots Buy more
\textsc{RAM
}
153 \item \pause Still segmentation fault?
154 \pause\ldots Divide into modules and parse separatly~
\footnote{To be
156 \item \pause Thus, we are only limited by hardware
\ldots
161 \frametitle{Learned lessons
}
163 \item \pause Parser combinators are elegant!
164 \item \pause Positional errors are a must!