201 lines
8.6 KiB
HTML
201 lines
8.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
<meta name="viewport" content="width=1024, user-scalable=no">
|
|
|
|
<title>Parsec Presentation by Yann Esposito</title>
|
|
|
|
<!-- Required stylesheet -->
|
|
<link rel="stylesheet" href="core/deck.core.css">
|
|
|
|
<!-- Extension CSS files go here. Remove or add as needed. -->
|
|
<link rel="stylesheet" href="extensions/goto/deck.goto.css">
|
|
<link rel="stylesheet" href="extensions/menu/deck.menu.css">
|
|
<link rel="stylesheet" href="extensions/navigation/deck.navigation.css">
|
|
<link rel="stylesheet" href="extensions/status/deck.status.css">
|
|
<link rel="stylesheet" href="extensions/hash/deck.hash.css">
|
|
<!-- <link rel="stylesheet" href="extensions/scale/deck.scale.css"> -->
|
|
|
|
<!-- Transition theme. More available in /themes/transition/ or create your own. -->
|
|
|
|
<!-- <link rel="stylesheet" href="themes/transition/fade.css"> -->
|
|
<!-- Style theme. More available in /themes/style/ or create your own. -->
|
|
<!-- <link rel="stylesheet" href="themes/style/web-2.0.css"> -->
|
|
<link rel="stylesheet" href="themes/style/y/main.css" />
|
|
<link rel="stylesheet" href="themes/style/y/solarized.css" />
|
|
<!-- Required Modernizr file -->
|
|
<script src="modernizr.custom.js"></script>
|
|
<script>
|
|
function gofullscreen(){
|
|
var body=document.getElementById('body');
|
|
try {
|
|
body.requestFullScreen();
|
|
} catch(err) {
|
|
try {
|
|
body.webkitRequestFullScreen();
|
|
} catch(err) {
|
|
body.mozRequestFullScreen();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
</script>
|
|
</head>
|
|
<body id="body" class="deck-container">
|
|
|
|
<div style="display:none">
|
|
\(\newcommand{\F}{\mathbf{F}}\)
|
|
\(\newcommand{\E}{\mathbf{E}}\)
|
|
\(\newcommand{\C}{\mathcal{C}}\)
|
|
\(\newcommand{\D}{\mathcal{D}}\)
|
|
\(\newcommand{\id}{\mathrm{id}}\)
|
|
\(\newcommand{\ob}[1]{\mathrm{ob}(#1)}\)
|
|
\(\newcommand{\hom}[1]{\mathrm{hom}(#1)}\)
|
|
\(\newcommand{\Set}{\mathbf{Set}}\)
|
|
\(\newcommand{\Mon}{\mathbf{Mon}}\)
|
|
\(\newcommand{\Vec}{\mathbf{Vec}}\)
|
|
\(\newcommand{\Grp}{\mathbf{Grp}}\)
|
|
\(\newcommand{\Rng}{\mathbf{Rng}}\)
|
|
\(\newcommand{\ML}{\mathbf{ML}}\)
|
|
\(\newcommand{\Hask}{\mathbf{Hask}}\)
|
|
\(\newcommand{\Cat}{\mathbf{Cat}}\)
|
|
\(\newcommand{\fmap}{\mathtt{fmap}}\)
|
|
</div>
|
|
|
|
<!-- Begin slides. Just make elements with a class of slide. -->
|
|
|
|
<section class="slide">
|
|
<div style="text-align:center; position:absolute; top: 2em; font-size: .9em; width: 100%">
|
|
<h1 style="position: relative;">Parsec</h1>
|
|
<author><em class="base01">by</em> Yann Esposito</author>
|
|
<div style="font-size:.5em">
|
|
<twitter>
|
|
<a href="http://twitter.com/yogsototh">@yogsototh</a>,
|
|
</twitter>
|
|
<googleplus>
|
|
<a href="https://plus.google.com/117858550730178181663">+yogsototh</a>
|
|
</googleplus>
|
|
</div>
|
|
<div class="base01" style="font-size: .5em; font-weight: 400; font-variant:italic">
|
|
<div class="button" style="margin: .5em auto;border: solid 2px; padding: 5px; width: 8em; border-radius: 1em; background:rgba(255,255,255,0.05);" onclick="javascript:gofullscreen();">ENTER FULLSCREEN</div>
|
|
HTML presentation: use arrows, space to navigate.
|
|
</div>
|
|
</div>
|
|
</section>
|
|
<section class="slide">
|
|
<h2 id="parsing">Parsing</h2>
|
|
<p>Latin pars (ōrātiōnis), meaning part (of speech).</p>
|
|
<ul>
|
|
<li><strong>analysing a string of symbols</strong></li>
|
|
<li><strong>formal grammar</strong>.</li>
|
|
</ul>
|
|
</section>
|
|
<section class="slide">
|
|
<h2 id="parsing-example-1">Parsing Example (1)</h2>
|
|
<p>From String:</p>
|
|
<pre class="sourceCode haskell"><code class="sourceCode haskell">(<span class="dv">1</span><span class="fu">+</span><span class="dv">3</span>)<span class="fu">*</span>(<span class="dv">1</span><span class="fu">+</span><span class="dv">5</span><span class="fu">+</span><span class="dv">9</span>)</code></pre>
|
|
<p>To data structure:</p>
|
|
<p><img src="parsec/img/mp/AST.png" alt="AST" /><br /></p>
|
|
</section>
|
|
<section class="slide">
|
|
<h2 id="parsec">Parsec</h2>
|
|
<blockquote>
|
|
<p>Parsec lets you construct parsers by combining high-order Combinators to create larger expressions.</p>
|
|
<p>Combinator parsers are written and used within the same programming language as the rest of the program.</p>
|
|
<p>The parsers are first-class citizens of the languages [...]"</p>
|
|
</blockquote>
|
|
</section>
|
|
<section class="slide">
|
|
<h2 id="a-parsec-example">A Parsec Example</h2>
|
|
<pre class="sourceCode haskell"><code class="sourceCode haskell">whitespaces <span class="fu">=</span> many (oneOf <span class="st">"\t "</span>)
|
|
number <span class="fu">=</span> many1 digit</code></pre>
|
|
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Right</span> <span class="st">" \t "</span> <span class="co">-- whitespaces on " \t "</span>
|
|
<span class="dt">Right</span> <span class="st">""</span> <span class="co">-- whitespaces on "32"</span>
|
|
<span class="dt">Right</span> <span class="st">"32"</span> <span class="co">-- number on "32"</span>
|
|
|
|
<span class="co">-- number on " \t 32 "</span>
|
|
<span class="dt">Left</span> <span class="st">"number"</span> (line <span class="dv">1</span>, column <span class="dv">1</span>)<span class="fu">:</span>
|
|
unexpected <span class="st">" "</span>
|
|
expecting digit</code></pre>
|
|
</section>
|
|
<section class="slide">
|
|
<h2 id="monadic-style">Monadic style</h2>
|
|
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">number ::</span> <span class="dt">Parser</span> <span class="dt">String</span>
|
|
number <span class="fu">=</span> many1 digit
|
|
|
|
<span class="ot">number' ::</span> <span class="dt">Parser</span> <span class="dt">Int</span>
|
|
number' <span class="fu">=</span> <span class="kw">do</span>
|
|
string_of_number <span class="ot"><-</span> many1 digit
|
|
return (read string_of_number)</code></pre>
|
|
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="st">"32"</span><span class="ot"> ::</span> [<span class="dt">Char</span>] <span class="co">-- number on "32"</span>
|
|
<span class="dv">32</span><span class="ot"> ::</span> <span class="dt">Int</span> <span class="co">-- number' on "32"</span></code></pre>
|
|
</section>
|
|
<section class="slide">
|
|
<h2 id="monadic-style">Monadic style</h2>
|
|
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">isolatedNumber ::</span> <span class="dt">Parser</span> <span class="dt">String</span>
|
|
isolatedNumber <span class="fu">=</span> <span class="kw">do</span>
|
|
_ <span class="ot"><-</span> whitespaces
|
|
n <span class="ot"><-</span> number
|
|
_ <span class="ot"><-</span> whitespaces
|
|
return n</code></pre>
|
|
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="dt">Right</span> <span class="st">"32"</span> <span class="co">-- isolatedNumber on " \t 32 "</span></code></pre>
|
|
</section>
|
|
<!-- End slides. -->
|
|
|
|
|
|
<!-- Begin extension snippets. Add or remove as needed. -->
|
|
|
|
<!-- deck.navigation snippet -->
|
|
<a href="#" class="deck-prev-link" title="Previous">←</a>
|
|
<a href="#" class="deck-next-link" title="Next">→</a>
|
|
|
|
<!-- deck.status snippet -->
|
|
<p class="deck-status">
|
|
<span class="deck-status-current"></span>
|
|
/
|
|
<span class="deck-status-total"></span>
|
|
</p>
|
|
|
|
<!-- deck.goto snippet -->
|
|
<form action="." method="get" class="goto-form">
|
|
<label for="goto-slide">Go to slide:</label>
|
|
<input type="text" name="slidenum" id="goto-slide" list="goto-datalist">
|
|
<datalist id="goto-datalist"></datalist>
|
|
<input type="submit" value="Go">
|
|
</form>
|
|
|
|
<!-- deck.hash snippet -->
|
|
<a href="." title="Permalink to this slide" class="deck-permalink">#</a>
|
|
|
|
<!-- End extension snippets. -->
|
|
|
|
|
|
<!-- Required JS files. -->
|
|
<script src="jquery-1.7.2.min.js"></script>
|
|
<script src="core/deck.core.js"></script>
|
|
|
|
<!-- Extension JS files. Add or remove as needed. -->
|
|
<script src="core/deck.core.js"></script>
|
|
<script src="extensions/hash/deck.hash.js"></script>
|
|
<script src="extensions/menu/deck.menu.js"></script>
|
|
<script src="extensions/goto/deck.goto.js"></script>
|
|
<script src="extensions/status/deck.status.js"></script>
|
|
<script src="extensions/navigation/deck.navigation.js"></script>
|
|
<!-- <script src="extensions/scale/deck.scale.js"></script> -->
|
|
|
|
<!-- Initialize the deck. You can put this in an external file if desired. -->
|
|
<script>
|
|
$(function() {
|
|
$.deck('.slide');
|
|
});
|
|
</script>
|
|
<!-- Y theme -->
|
|
<script src="js/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
|
<script src="js/highlight/highlight.pack.js"></script>
|
|
<script>
|
|
hljs.initHighlightingOnLoad();
|
|
</script>
|
|
</body>
|
|
</html>
|