Skip to content

Commit

Permalink
update page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadia-polikarpova committed May 15, 2024
1 parent 7829b61 commit 4a92860
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
15 changes: 6 additions & 9 deletions docs/lectures/06-parsing.html
Original file line number Diff line number Diff line change
Expand Up @@ -525,27 +525,24 @@ <h2 id="running-the-lexer">Running the Lexer</h2>
<p>which repeatedly calls <code class="sourceCode haskell">alexScan</code> until it consumes the whole input string or fails</p>
<p><br></p>
<p>We can test the function like so:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>λ<span class="op">&gt;</span> parseTokens <span class="st">&quot;23 + 4 / off -&quot;</span></span>
<div class="sourceCode" id="cb13"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>λ<span class="op">&gt;</span> parseTokens <span class="st">&quot;23 + 4&quot;</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="dt">Right</span> [ <span class="dt">NUM</span> (<span class="dt">AlexPosn</span> <span class="dv">0</span> <span class="dv">1</span> <span class="dv">1</span>) <span class="dv">23</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> , <span class="dt">PLUS</span> (<span class="dt">AlexPosn</span> <span class="dv">3</span> <span class="dv">1</span> <span class="dv">4</span>)</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> , <span class="dt">NUM</span> (<span class="dt">AlexPosn</span> <span class="dv">5</span> <span class="dv">1</span> <span class="dv">6</span>) <span class="dv">4</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> , <span class="dt">DIV</span> (<span class="dt">AlexPosn</span> <span class="dv">7</span> <span class="dv">1</span> <span class="dv">8</span>)</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> , <span class="dt">ID</span> (<span class="dt">AlexPosn</span> <span class="dv">9</span> <span class="dv">1</span> <span class="dv">10</span>) <span class="st">&quot;off&quot;</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> , <span class="dt">MINUS</span> (<span class="dt">AlexPosn</span> <span class="dv">13</span> <span class="dv">1</span> <span class="dv">14</span>) </span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a> ] </span></code></pre></div>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> ] </span></code></pre></div>
<div class="sourceCode" id="cb14"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>λ<span class="op">&gt;</span> parseTokens <span class="st">&quot;%&quot;</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="dt">Left</span> <span class="st">&quot;lexical error at 1 line, 1 column&quot;</span></span></code></pre></div>
<p><br>
<br>
<br>
<br></p>
<h2 id="quiz">QUIZ</h2>
<p>What is the result of <code class="sourceCode haskell">parseTokens <span class="st">&quot;92zoo&quot;</span></code>
<p>What is the result of <code class="sourceCode haskell">parseTokens <span class="st">&quot;x+&quot;</span></code>
(positions omitted for readability)?</p>
<p><strong>(A)</strong> Lexical error</p>
<p><strong>(B)</strong> <code class="sourceCode haskell">[<span class="dt">ID</span> <span class="st">&quot;92zoo&quot;</span>]</code></p>
<p><strong>(C)</strong> <code class="sourceCode haskell">[<span class="dt">NUM</span> <span class="st">&quot;92&quot;</span>]</code></p>
<p><strong>(D)</strong> <code class="sourceCode haskell">[<span class="dt">NUM</span> <span class="st">&quot;92&quot;</span>, <span class="dt">ID</span> <span class="st">&quot;zoo&quot;</span>]</code></p>
<p><strong>(B)</strong> Some other error</p>
<p><strong>(C)</strong> <code class="sourceCode haskell">[<span class="dt">ID</span> <span class="st">&quot;x+&quot;</span>]</code></p>
<p><strong>(D)</strong> <code class="sourceCode haskell">[<span class="dt">ID</span> <span class="st">&quot;x&quot;</span>, <span class="dt">PLUS</span>]</code></p>
<p><br></p>
<p><br>
<br>
Expand Down
13 changes: 5 additions & 8 deletions lectures/06-parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,10 @@ which repeatedly calls `alexScan` until it consumes the whole input string or fa
We can test the function like so:

```haskell
λ> parseTokens "23 + 4 / off -"
λ> parseTokens "23 + 4"
Right [ NUM (AlexPosn 0 1 1) 23
, PLUS (AlexPosn 3 1 4)
, NUM (AlexPosn 5 1 6) 4
, DIV (AlexPosn 7 1 8)
, ID (AlexPosn 9 1 10) "off"
, MINUS (AlexPosn 13 1 14)
]
```

Expand All @@ -411,16 +408,16 @@ Left "lexical error at 1 line, 1 column"

## QUIZ

What is the result of `parseTokens "92zoo"`
What is the result of `parseTokens "x+"`
(positions omitted for readability)?

**(A)** Lexical error

**(B)** `[ID "92zoo"]`
**(B)** Some other error

**(C)** `[NUM "92"]`
**(C)** `[ID "x+"]`

**(D)** `[NUM "92", ID "zoo"]`
**(D)** `[ID "x", PLUS]`

<br>

Expand Down

0 comments on commit 4a92860

Please sign in to comment.