CS4121 Cminus Expression Interpreter Project
Due Date: Monday, May. 19, 2025 at11:59 pm
Purpose
The purpose of this project is to gain experience in giving meaning to a programming language by inter-
preting a subset of Cminus. Specifically, you will interpret integer and string write operations, integer read
operations, integer arithmetic and logical expressions and assignment statements.
Project Summary
In this project, you will add actions to a parser and a scanner provided by me. You must add code to do
the following:
1. Design a data structure to store string constants and integer variables declared in a Cminus program
and to track variable values.
2. Pass attributes of tokens from the scanner to the parser when needed.
3. Interpret string write statements.
4. Interpret integer write statements.
5. Interpret integer read statements.
6. Interpret integer expressions.
7. Interpret logic expressions.
8. Interpret assignment statements which assigns values to integer variables.
Requirements
Write all of your code in C or C++ . It will be tested on a CS lab machine and MUST work there. You will
receive no special consideration for programs which “work” elsewhere, but not on a CS machine.
Input.The fileCminusProject1.tgzcontains the parser needed to begin this project. You will need to
modify the actions in the project filesparser/CminusParser.yandparser/CminusScaner.lto do this
project. Currently, the actions in the parser just emit the rules that are reduced. You also need to set up
certain token attributes in the scanner. Sample input for this project is provided in the project directory
input. To run your interpreter, use the command
cmc
You will see
contains read statements.
Submission.Your code should be well-documented. You will submit all of your files, by tarring up your
project directory using the command
tar -czf CminusProject1.tgz CminusProject1
Submit the fileCminusProject1.tgzvia the CS4121 Canvas page. Make sure you do a ’make clean’ of your
directory before executing the tar command. This will remove all of the ’.o’ files and make your tar file much
smaller.
1
Data Structures and DocumentationI have provided several C data structures for those who will
be programming in C. There are doubly linked list, symbol table and string manipulation routines in
the directoryCminusProject1/util. The HTML Doxygen documentation for the provided code is in
CminusProject1/Documentation/html/index.html. You may ask me any questions regarding these rou-
tines. You will not likely need any of these structures now, but you may want to familiarize yourself with
them. For those coding in C++, you may use STL.
Makefile StructureThe Makefiles for the project are set up to automatically generate make dependences.
In a particular directory (e.g.,parser), you may add new files for compilation by adding the source file name
to theSRCSvariable declaration on the first line of that directory’sMakefile. For example, to add the file
newfile.cto be compiled in theparserdirectory, change the first line ofparser/Makefilefrom
SRCS = CminusScanner.c CminusParser.c
to
SRCS = CminusScanner.c CminusParser.c newfile.c
Nothing else needs to be done. Do not add source files to the root directoryCminusProject1as the make
files assume there are no source files in that directory.
If you would like to add your own subdirectory (e.g.,newdir) toCminusProject1, then change the line
DIRS = parser util
inCminusProject1/Makefileto
DIRS = parser util newdir
and the line
LIBS = parser/libparser-g.a util/libutil-g.a
inCminusProject1/Makefileto
LIBS = parser/libparser-g.a util/libutil-g.a newdir/libnewdir-g.a
Then, copyutil/Makefiletonewdir/Makefile. Finally, change theSRCSdeclaration innewdir/Makefile
to contain only the source files in that directory and change the line
ARCHIVE = libutil$(ENV).a
to
ARCHIVE = libnewdir$(ENV).a
An Example
Given the following Cminus program (3.add.cm):
int main () {
int i,j,k,l;
write(10+20);
i=1; k=3; l=4;
j = i + k + l;
write(j);
}
your expected output in 3.add.s should be
30
8
2