]> git.rkrishnan.org Git - yorgey.git/blobdiff - hw11/SExpr.hs
hw11: starting files
[yorgey.git] / hw11 / SExpr.hs
diff --git a/hw11/SExpr.hs b/hw11/SExpr.hs
new file mode 100644 (file)
index 0000000..78ae980
--- /dev/null
@@ -0,0 +1,46 @@
+{- CIS 194 HW 11
+   due Monday, 8 April
+-}
+
+module SExpr where
+
+import AParser
+import Control.Applicative
+
+------------------------------------------------------------
+--  1. Parsing repetitions
+------------------------------------------------------------
+
+zeroOrMore :: Parser a -> Parser [a]
+zeroOrMore p = undefined
+
+oneOrMore :: Parser a -> Parser [a]
+oneOrMore p = undefined
+
+------------------------------------------------------------
+--  2. Utilities
+------------------------------------------------------------
+
+spaces :: Parser String
+spaces = undefined
+
+ident :: Parser String
+ident = undefined
+
+------------------------------------------------------------
+--  3. Parsing S-expressions
+------------------------------------------------------------
+
+-- An "identifier" is represented as just a String; however, only
+-- those Strings consisting of a letter followed by any number of
+-- letters and digits are valid identifiers.
+type Ident = String
+
+-- An "atom" is either an integer value or an identifier.
+data Atom = N Integer | I Ident
+  deriving Show
+
+-- An S-expression is either an atom, or a list of S-expressions.
+data SExpr = A Atom
+           | Comb [SExpr]
+  deriving Show