Exercise: Parser

Preparation

  • Download the zip file and extract the project.
  • Open the project with IntelliJ: File -> Open... -> path to extracted project folder

Your Task(s)

  1. Use the provided parser classes. Create a function that can read a grammar from a file. A sample grammar with the intended syntax is provided in the resources folder. Make sure the test sentences in the GrammarReader object parse as expected. Add some more test cases to make sure everything is working.
  2. Optional, advanced: modify the parser (and optionally the grammar reader) so that you can mix terminals and non-terminals on the right-hand side. Think about the changes necessary for the grammar, as well as the parser (what will the stack look like?).
  3. Optional, advanced: modify the parser to output a parse tree, not just `true` or `false`.
  4. Optional, advanced: modify the parser to be an all-solutions parser. The original version stops after it finds the first parse.
NB: you can do the optional parts in any order, they do not build upon each other. The one where you output the parse tree is possibly the easiest one.