Arithmetic evaluation: Difference between revisions
→{{header|Haskell}}
(Added Haskell version) |
|||
Line 21:
table = [[op "*" (Mul) AssocLeft, op "/" (Div) AssocLeft]
where op s f assoc = Infix (do string s; return f) assoc
factor = do char '(' ; x <- expr ; char ')'
return x
<|> do ds <- many1 digit
return $ Num (read ds)
Line 38:
Right expr -> evaluate expr
Left _ -> error "Did not parse"
=={{header|Prolog}}==
|