Arithmetic evaluation: Difference between revisions

m
Line 2,187:
 
expr = buildExpressionParser table factor
where table = [[op "*" (Mul) AssocLeft, op "/" (Div) AssocLeft]
 
table = [ ,[op "*+" (MulAdd) AssocLeft, op "/-" (DivSub) AssocLeft]]
,[ op "+"s (Add)f AssocLeft,assoc op= "-"Infix (Subf <$ string s) AssocLeft]]assoc
where op s f assocfactor = Infix (fbetween <$`on` stringchar) '(' s')' assocexpr
factor = between (char '(') (char ')') expr <|> (Num . read <$> many1 digit)
 
on f g = \x y -> f (g x) (g y)
factor = between (char '(') (char ')') expr <|> (Num . read <$> many1 digit)
 
eval :: Num a => Exp -> a
Anonymous user