Prompts for “Parser Combinators”


Due on Wednesday, April 20 by 10pm


Read “Parser Combinators” in the course packet and do the following activity.


This activity requires very little thinking, just a little plagiarism. All I ask you to do is copy a program that I already wrote and then run it. But please copy this program in the manner specified.

  1. Create a new project in a folder called Sentences.
  2. Download the Parsers.fs library.
  3. Add an entry for Parsers.fs to your Sentences.fsproj file. Put that entry in the right place to ensure that it is compiled first.
  4. Find the example parser program on page 218 of the course packet and copy it into your Program.fs. However, here is the important part: do not copy and paste the program. Copy the program by retyping it. It’s probably easiest to use your printed copy of the course packet for this task.
  5. Note that there’s a small correction to the Failure case of the pattern match in the parse function. It should read
    Failure(_,_) -> ...
    

    instead of

    Failure -> ...
    

    I added some extra functionality to the library to aid in debugging but did not update the example in the book.

  6. Try running the program with the examples shown in the reading.
  7. Find two more inputs. The first should be an input that the parser accepts. The second should be an input that the parser rejects.

Your submission should include all the code for the project above, and in a file called inputs.txt, the two inputs you found. Be sure to label which one the parser accepts and which one the parser rejects.


Completely Optional Note About Debugging

Note that if you decide to also try out the debuging example in the next section, an additional step is needed. This was a feature I added by popular request but neglected to mention in the book. Replace prepare with debug in the Program.fs. This sets a debug flag. Debug parsers will only print when the debug flag is set, that way you can easily turn debugging on and off. E.g.,

let input' = if debugging_enabled then (debug input) else (prepare input)

and you might modify the program to take a second input from the user so that they can turn it on and off on the command line like

$ dotnet run "Is this a sentence?" debug

Submission Instructions

Commit your response to your short responses repository. There is no LaTeX for this response.

THE PROJECT FOLDER MUST BE NAMED Sentences and be found in the folder for reading response 7.

  • CSCI 334: Principles of Programming Languages, Spring 2022

CSCI 334 website repository, Spring 2022

Powered by Bootstrap 4 Github Pages