|
4 | 4 | >
|
5 | 5 |
|
6 | 6 | The development of the Imp language in `Imp.lidr` completely ignores issues of
|
7 |
| -concrete syntax -- how an ascii string that a programmer might write gets |
| 7 | +concrete syntax -- how an ASCII string that a programmer might write gets |
8 | 8 | translated into abstract syntax trees defined by the datatypes \idr{AExp},
|
9 |
| -\idr{BExp}, and \idr{Com}. In this chapter, we illustrate how the rest of the |
| 9 | +\idr{BExp}, and \idr{Com}. In this chapter, we illustrate how the rest of the |
10 | 10 | story can be filled in by building a simple lexical analyzer and parser using
|
11 | 11 | Idris's functional programming facilities.
|
12 | 12 |
|
13 | 13 | It is not important to understand all the details here (and accordingly, the
|
14 |
| -explanations are fairly terse and there are no exercises). The main point is |
15 |
| -simply to demonstrate that it can be done. You are invited to look through the |
| 14 | +explanations are fairly terse and there are no exercises). The main point is |
| 15 | +simply to demonstrate that it can be done. You are invited to look through the |
16 | 16 | code -- most of it is not very complicated, though the parser relies on some
|
17 | 17 | "monadic" programming idioms that may require a little work to make out -- but
|
18 |
| -most readers will probably want to just skim down to the Examples section at the |
19 |
| -very end to get the punchline. |
| 18 | +most readers will probably want to just skim down to the `Examples` section at |
| 19 | +the very end to get the punchline. |
20 | 20 |
|
21 | 21 | > import Maps
|
22 | 22 | > import Imp
|
@@ -79,15 +79,15 @@ very end to get the punchline.
|
79 | 79 |
|
80 | 80 | ==== Options With Errors
|
81 | 81 |
|
82 |
| -An `option` type with error messages: |
| 82 | +An \idr{Option} type with error messages: |
83 | 83 |
|
84 | 84 | > data OptionE : (x : Type) -> Type where
|
85 | 85 | > SomeE : x -> OptionE x
|
86 | 86 | > NoneE : String -> OptionE x
|
87 | 87 | >
|
88 | 88 |
|
89 |
| -Some interface instances to make writing nested match-expressions on `OptionE` |
90 |
| -more convenient. |
| 89 | +Some interface instances to make writing nested match-expressions on |
| 90 | +\idr{OptionE} more convenient. |
91 | 91 |
|
92 | 92 | \todo[inline]{Explain these/link to Haskell etc?}
|
93 | 93 |
|
@@ -123,13 +123,13 @@ more convenient.
|
123 | 123 | > | SomeE (t', xs') = manyHelper p (t'::acc) steps' xs'
|
124 | 124 | >
|
125 | 125 |
|
126 |
| -A (step-indexed) parser that expects zero or more `p`s: |
| 126 | +A (step-indexed) parser that expects zero or more \idr{p}s: |
127 | 127 |
|
128 | 128 | > many : (p : Parser t) -> (steps : Nat) -> Parser (List t)
|
129 | 129 | > many p steps = manyHelper p [] steps
|
130 | 130 | >
|
131 | 131 |
|
132 |
| -A parser that expects a given token, followed by `p`: |
| 132 | +A parser that expects a given token, followed by \idr{p}: |
133 | 133 |
|
134 | 134 | > firstExpect : (a : Token) -> (p : Parser t) -> Parser t
|
135 | 135 | > firstExpect a p (x::xs) = if x == a then p xs else NoneE ("Expected '" ++ a ++ "'")
|
@@ -316,6 +316,7 @@ SomeE (CIf (BEq (AId (MkId "x")) (APlus (AMinus (APlus (APlus (AId (MkId "y")) (
|
316 | 316 | \todo[inline]{This one is repeated twice in the book for some reason}
|
317 | 317 |
|
318 | 318 | ```idris
|
| 319 | +λΠ> parse "SKIP;; z:=x*y*(x*x);; WHILE x==x DO IF z <= z*z && not x == 2 THEN x := z;; y := z ELSE SKIP END;; SKIP END;; x:=z" |
319 | 320 | SomeE (CSeq CSkip
|
320 | 321 | (CSeq (CAss (MkId "z") (AMult (AMult (AId (MkId "x")) (AId (MkId "y"))) (AMult (AId (MkId "x")) (AId (MkId "x")))))
|
321 | 322 | (CSeq (CWhile (BEq (AId (MkId "x")) (AId (MkId "x")))
|
|
0 commit comments