JavaCC project to parse strings made up of "well-parenthesized strings". (University of Warwick CS259 - Formal Languages mock coursework)
Go to file
Kiril Kovachev 70a36b938c Add README
2025-03-07 15:34:07 +00:00
.vscode Use exclusions file for VS Code to ignore output files 2025-03-07 15:22:22 +00:00
.gitignore Add .gitignore 2025-03-07 15:21:59 +00:00
assignment.jj Add base parser specification 2025-03-07 15:21:43 +00:00
README.md Add README 2025-03-07 15:34:07 +00:00
run.sh Add script for running 2025-03-07 15:21:51 +00:00

Well-parenthesized language parser

This project is a JavaCC parser configuration which generates a parser for a language with well-balanced parentheses. The features that this language has is:

  • Each string accepted by the language consists of multiple lines (but at least 1 line).
  • Lines must not be empty.
  • Lines must contain well-balanced parentheses, e.g. (), ()()(), (()()), (((()))).
  • Only parentheses are allowed, so any other character makes the input invalid.
  • (As an exception to the first rule) there must be a blank final line at the end of the input.

E.g. the following is a good input to the parser:

()(())
(())(((()())))
((((((((((()))))))))))
(())()()()()()
((()()())()()(()(())))()
<blank line here>

How to run

To build the Java code and run: ./run.sh. This is an alias for:

javacc assignment.jj && javac *.java && java Assignment < test.txt > output.txt 2> err.txt

Output

The standard output stream will contain the parser's decision as to whether the string is valid — the output will either be PASS or FAIL. If it is FAIL, the standard error will also contain the line number of the first error that caused the invalidity.