data Expr = Var Char | Tall Int | Sum Expr Expr | Mult Expr Expr | Neg Expr | Let Expr Expr Expr
deriving(Eq, Show)
parseExpr :: String -> (Expr, String)
parseExpr ( * : ( :s) = (Mult x y, s )
where (x, , :s ) = parseExpr s
(y, ) :s ) = parseExpr s
parseExpr ( + : ( :s) = (Sum x y, s )
where (x, , :s ) = parseExpr s
(y, ) :s ) = parseExpr s
parseExpr (x : xs) | isDigit x = (Tall (digitToInt x), xs)
parseExpr (x:s) = (Var x,s)
where x >= A = True
x <= Z = True
我的教区在完成之前没有两件事。 从数据类型上看,它缺乏“从业”和“从业经验”。 第一部分就是这样:
parseExpr( -
parseExpr( l : e : t :x: b : e
As in the datatype, the Let expressions starts with let and takes in three Expr. I don t know how to write out these last functions. Any help at all will be very much appreciated.
我在此问另一个关于SO问题的提问:here。 这是这一问题的关联。
例如:
parseProg "let X be 4 in let Y be *(2 , X) in let Z be +(Y , X) in
+(+(X , Y) , Z)"
Let (Var X ) (Tall 4) (Let (Var Y ) (Mult (Tall 2) (Var X )) (Let
(Var Z ) (Sum (Var Y ) (Var X )) (Sum (Sum (Var X ) (Var Y )) (Var
Z ))))