The goal of this coursework was to build a lexer (lexical analyser) and parser for the imaginary Žsec programming language using JFlex 1.6.1 and CUP v.11b-20160615. The lexer defines the language's syntax: contains regular expressions covering all legal words in the Žsec language, and the parser defines a context-free grammar describing the language's rules or semantics.
The full specification for the Žsec language is given in the project.pdf file.
The lexer (in src/Lexer.lex)
- Uses JFlex to automatically generate a scanner for the Žsec language.
- Reports the line and the column (offset into the line) where an error, usually unexpected input, first occurred.
The parser (in src/Parser.cup)
- Uses CUP(Construction of Useful Parsers) to automatically produce a parser for the Žsec language.
- Resolves ambiguities in expressions using the precedence and associativity rules;
- Prints “parsing successful”, followed by a newline, if the program is syntactically correct.
The project is built using MakeFile
To build, issue make
To test, issue make test
To run on a single test file, issue ./bin/sc tests/open/<some test>.s
The parser was tested against a suite of positive and negative tests (the results.csv file contains the test results) by an automatic marking script and recieved a perfect score.