Description
Implement the function
nTimes :: Integer -> Parse a b -> Parse a [b]
so that nTimes n p recognizes n of the objects recognized by
the parser p.
This problem is exercise 17.11 of the book “Haskell – the craft
of functional programming”. I have already solved exercise 17.10;
check out the code in Parser.hs following the comment
“– begin: helper parsing functions” to help you solve this problem.
Problem 2:
———-
Implement the function
spotWhile :: (a -> Bool) -> Parse a [a]
whose parameter is a function which tests elements of the input type, and
returns the longest initial part of the input, all of whose elements have
the required property. For instance,
spotWhile isDigit “234abc” == [(“234″,”abc”)]
spotWhile isDigit “abc234″ == [([],”abc234”)]
Problem 3:
———-
Modify the function
parser :: Parser Char Expr
defined in the file ExpressionsParser.hs so that the whitespace characters
space and tab can be used in expressions, but are ignored on parsing.
(Hint: there is a simple pre-processor which does the trick!)
This is exercise 17.18.
Submission instructions:
————————
You have to modify the two files:
– Parser.hs (Problem 1 and 2)
Add your solutions above the comment “– end: helper parsing functions”.
– ExpressionsParser.hs (Problem 3)
Modify directly the parser function. You may want to add the
pre-processing function outside the modified parser function.
Make sure that you run the tests.
Zip the three modified files and upload them to Webcourses.