Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Haskell help

Name: Anonymous 2010-06-09 12:13

So I got this arithmetic expression parser. I want to add subtraction and division support but I can't get it to work properly (aka make them left associative). Anyone got any ideas?:(

I import this:
http://www.cs.nott.ac.uk/~gmh/Parsing.lhs
then:
expr :: Parser Int
expr =  do t <- term
           do symbol "+"              
              e <- expr
              return (t+e)
            +++ return t

term :: Parser Int
term =  do f <- factor
           do symbol "*"
              t <- term
              return (f * t)
            +++ return f

factor :: Parser Int
factor =  do symbol "("
             e <- expr
             symbol ")"
             return e
           +++ natural

eval :: String -> Int
eval xs = case (parse expr xs) of
               [(n,[])]  -> n
               [(_,out)] -> error ("unused input " ++ out)
               []        -> error "invalid input"

Name: Anonymous 2010-06-09 12:23

>>1
Haskell
Found you're problem. Use LISP.

Name: Anonymous 2010-06-09 14:24

>>2
>you're
IHBT

Name: Anonymous 2010-06-09 14:29

>>3
You should have realized that when he used the old upcase name for the family of languages.

Name: Anonymous 2010-06-09 19:03

>>4
MY ANUS WAS ENLIGHTENED

Name: Anonymous 2010-06-09 19:07

>>4
She realized it quicker than that:

The "you're" in the sentence came before the "LISP". QED.

Name: Anonymous 2010-06-09 19:11

>>6
You did no demonstration. Ergo your wrong bitch

Name: Anonymous 2010-06-11 11:08

>>6
The "LISP" is more noticeable!!

Name: Anonymous 2011-02-04 11:25

Name: Anonymous 2011-02-04 11:41

Name: Anonymous 2013-01-19 23:52

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List