Parsing integers [was: Re: [Haskell-cafe] help]

On 12/9/07, Ryan Bloor
hi
I have a function parseInt... which needs an error guard for when the input is not an Int.
parseInt :: Parser parseInt [] = [] parseInt xs = let (digits, rest) = span isDigit (removeSpace xs) in [(EInt (read digits), removeSpace rest)]
Also... I have a function that does this... parseBinaryOp "+" "(5 + 2) if" gives...[(Int 5, Int 2, "if")] so, op is '+' or "&&". I am unsure of how to begin...
parseBinaryOp :: String -> String -> [(Expr, Expr, String)] parseBinaryOp op str
Check out: http://www.haskell.org/haskellwiki/Homework_help If this isn't homework, try posting again and phrasing your question in the form of a question; saying "I am unsure of how to begin" doesn't help us help you think about the problem. Cheers, Tim -- Tim Chevalier * catamorphism.org * Often in error, never in doubt "[Teaching children to read] will make America what we want it to be, a literate country and a hopefuller country." -- George W. Bush

hi sorry for vagueness. I am writing a basic Parser from scratch. So far I have functions; # removeSpaces # match - which checks if a string is a substring of another # orParser which combines two parser's abilities # Basic pasrers like... parseInt, parseTrue, parseFalse, parseBoolusing the orParser on True and False. What I want to do now is have a parseBinaryOp that recognises: parseBinaryOp "+" "(5 + 2) if" >>>gives>> [(EInt 5, EInt 2, "if")] So I think that I have to split the initial string into four parts. "+" becomes op '(' becomes tokenF ')' becomes tokenB "5" becomes e1 "2" becomes e2 parseBinaryOp :: String -> String -> [(Expr, Expr, String)]parseBinaryOp op str = let (tokenF,e1,op,e2,tokenB) = I am not sure how to go about separating the string for how I need itusing my other functiuons. Ryan _________________________________________________________________ Celeb spotting – Play CelebMashup and win cool prizes https://www.celebmashup.com

hi I am writing a basic Parser from scratch. So far I have functions;# removeSpaces# match - which checks if a string is a substring of another# orParser which combines two parser's abilities# Basic pasrers like... parseInt, parseTrue, parseFalse, parseBoolusing the orParser on True and False.What I want to do now is have a parseBinaryOp that recognises:parseBinaryOp "+" "(5 + 2) if" >>>gives>> [(EInt 5, EInt 2, "if")]So I think that I have to split the initial string into four parts."+" becomes op'(' becomes tokenF')' becomes tokenB"5" becomes e1"2" becomes e2parseBinaryOp :: String -> String -> [(Expr, Expr, String)]parseBinaryOp op str = let (tokenF,e1,op,e2,tokenB) =I am not sure how to go about separating the string for how I need itusing my other functiuons. Ryan _________________________________________________________________ Get free emoticon packs and customisation from Windows Live. http://www.pimpmylive.co.uk
participants (2)
-
Ryan Bloor
-
Tim Chevalier