I'm learning compiler construction following the book Modern Compiler Implementation in C. In the introduction there is a "PROGRAM STRAIGHT-LINE PROGRAM INTERPRETER", which it said is "available in the directory $TIGER/chap1
", so I downloaded the TIGER compiler from https://www.cs.princeton.edu/~appel/modern/c/project.html.
In the chap1
directory, there some files:
chap1$ ls
1.png makefile prog1.h slp.h util.h
main.c prog1.c slp.c util.c
So I execute make command in the 'chap1' directory , but it shows an error:
chap1$ make
cc -g -c main.c
cc -g -c prog1.c
cc -g -c slp.c
cc -g -c util.c
cc -g main.o prog1.o slp.o util.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [a.out] Error 1
Here is the makefile
:
a.out: main.o prog1.o slp.o util.o
cc -g main.o prog1.o slp.o util.o
main.o: main.c slp.h util.h
cc -g -c main.c
prog1.o: prog1.c slp.h util.h
cc -g -c prog1.c
slp.o: slp.c slp.h util.h
cc -g -c slp.c
util.o: util.c util.h
cc -g -c util.c
clean:
rm -f a.out util.o prog1.o slp.o main.o
It seems the chap1
directory is a complete project, but I don't know what the function of chap1
directory in TIGER compiler and how to use it.
In file main.c, there is not main function. Please provide it in this file. Here is the template:
#include "util.h"
#include "slp.h"
#include "prog1.h"
int main()
{
A_stm stm = prog();
return 0;
}