CS 224 Lab 1 – Parsing
Objectives
Perform the following tasks in the order given.
| Assignment: Complete Exercises 2 in the notes to write the function in the Parser module becomes :: Parser String which accepts the string ":=" and returns Nothing if it is unsuccessful. Be sure to test your functions with strings that will succeed and with strings that will fail. |
| Assignment: Complete Exercises 4 and 5 in the notes to write the functions in the Parser module letter :: Parser Char space :: Parser Char which accept and letter and a space character respectively. Then define alphanum :: Parser Char which accepts a letter or a digit. Be sure to test your functions with strings that will succeed and with strings that will fail. |
| Assignment: Complete Exercises 7 in the notes to redefine the function becomes :: Parser (Char,Char) using twochars and the ? operator. The definition should not include the string argument. |
| Assignment: Complete Exercises 9 in the notes to write the function in the Parser module sndchar :: Parser Char which accepts two characters and returns the second one. Use twochars and the transformations operator >-> |
| Assignment: Complete Exercises 11 and12 in the notes to write the functions in the Parser module (-#) :: Parser a -> Parser b -> Parser b (#-) :: Parser a -> Parser b -> Parser a which applies two parsers in sequence but throws away one of the results. (-#) throws away the first result and (#-) throws away the second result. |
| Assignment: Complete Exercise 15 in the notes to write the function in the Parser module require:: String -> Parser a The parser require w accepts the same string input as accept w but reports the missing string using err in case of failure |
The parser for expressions, given in the notes, is
implemented in the Interpreter module. Run this module and test out
some expressions like:
expr "x * 2 + 3"
expr "(x * 2) + 3"
Make sure that you understand the results that are given.