]> git.rkrishnan.org Git - yorgey.git/blob - hw11/SExpr.hs
hw11: starting files
[yorgey.git] / hw11 / SExpr.hs
1 {- CIS 194 HW 11
2    due Monday, 8 April
3 -}
4
5 module SExpr where
6
7 import AParser
8 import Control.Applicative
9
10 ------------------------------------------------------------
11 --  1. Parsing repetitions
12 ------------------------------------------------------------
13
14 zeroOrMore :: Parser a -> Parser [a]
15 zeroOrMore p = undefined
16
17 oneOrMore :: Parser a -> Parser [a]
18 oneOrMore p = undefined
19
20 ------------------------------------------------------------
21 --  2. Utilities
22 ------------------------------------------------------------
23
24 spaces :: Parser String
25 spaces = undefined
26
27 ident :: Parser String
28 ident = undefined
29
30 ------------------------------------------------------------
31 --  3. Parsing S-expressions
32 ------------------------------------------------------------
33
34 -- An "identifier" is represented as just a String; however, only
35 -- those Strings consisting of a letter followed by any number of
36 -- letters and digits are valid identifiers.
37 type Ident = String
38
39 -- An "atom" is either an integer value or an identifier.
40 data Atom = N Integer | I Ident
41   deriving Show
42
43 -- An S-expression is either an atom, or a list of S-expressions.
44 data SExpr = A Atom
45            | Comb [SExpr]
46   deriving Show