Arithmetic evaluation: Difference between revisions

(Added Haskell version)
Line 21:
table = [[op "*" (Mul) AssocLeft, op "/" (Div) AssocLeft]
,[op "+" (Add) AssocLeft, op "-" (Sub) 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}}==
24

edits