X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=hw11%2FSExpr.hs;fp=hw11%2FSExpr.hs;h=78ae98014062fa6b62ab8a3ca4259f720bee540f;hb=456f59f9d65871460c92e8ef32c6936d2177993b;hp=0000000000000000000000000000000000000000;hpb=0bb04c08d8232187dc73265e9a675f84c8e48d26;p=yorgey.git diff --git a/hw11/SExpr.hs b/hw11/SExpr.hs new file mode 100644 index 0000000..78ae980 --- /dev/null +++ b/hw11/SExpr.hs @@ -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