Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Recursive Descent Recogniser
1. General Instructions
Section 3 describes a grammar for a simple programming language rather like Ada. The task is to implement a
syntax analyser (SA) for this language using a recursive descent parser. The analyser’s sole function is make sure a
user’s source program is syntactically correct, and the SA should generate appropriate and helpful error messages
where required. The SA should terminate on encountering and reporting the first error. To be more precise, you
are expected to build a Syntax Recogniser with its purpose to recognise its input as a valid sentence in the
language specified by the grammar.
The coursework task is to implement part of a compiler for this language using a recursive descent parser.
1.1. Java Classes Provided
You are provided with the following Java classes:
(a) Token in a file Token.java, to represent a token returned by the lexical analyser stage. This has:
? a set of integer constants (becomesSymbol, beginSymbol, identifier, leftParenthesis, and so on)
representing the possible types of token in this language
? three public attributes (symbol, an int, which is one of the constants declared above; text, a String,
the characters making up the token; lineNumber, an int, the number of the line containing the
token)
? two constructors, and a static method getName to return the name (a String) of a token provided
as the single int argument
(b) CompilationException in a file CompilationException.java (see below)
(c) LexicalAnalyser in a file LexicalAnalyser.java, which is the lexical analyser for this programming language.
This has:
? a constructor with one String argument, the name of the file from which the tokens are to be read
? a method getNextToken (with no arguments), to return the next token read from the source text
? a main method, with which the operation of the lexical analyser can be tried out on a suitable file
(using a toString method supplied in the Token class)
(d) AbstractGenerate in a file AbstractGenerate.java. This is the abstract class you need to make concrete in
the Generate class you have to provide.
(e) AbstractSyntaxAnalyser in a file AbstractSyntaxAnalyser.java. This is the abstract class you need to make
concrete in the SyntaxAnalyser class you have to provide.
(f) Compile in a file Compile.java. This is the driver program for the whole coursework. This driver program
calls the parse method of the SyntaxAnalyser class for each file with a name of the form "programn"
(integer n 3 0) (these files are in the coursework pack).
These classes can be found in the coursework pack ZIP folder that this document came along with. To help you
build and run your work, as well as generate this ZIP file to submit, some shell scripts have been included:
February 2024 2 SCC312 Compilers Coursework 23/24
1.2 Building the Code
For Windows Users:
Running ‘compile.bat’ will compile all java source files
Running ‘execute.bat’ will run the compiler against all supplied test programs
For Mac/Linux Users:
A makefile has been included which has the following functions (where ‘$>’ is your terminal prompt:
$> make
Compile all required java sources
$> make run
Run the compiler against all supplied test programs
$> make package
Build a submission .zip file - this is a ‘beta’ feature, check your submission file
has been created successfully before actually submitting it!
Note; The makefile requires a working install of the following: zip, java, javac, and make to work
correctly.