-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.txt
62 lines (48 loc) · 2.72 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
This is the start of a simple compiler which you can modify to compile
the MiniJava language. It is meant primarily to show how the
toolchain works and how the various parts of the compiler project plug
together.
To demonstrate the basics of scanning and parsing, as well as to
provide some basic structure, we're providing a "compiler" that will
scan and parse "programs" in the following tiny programming language:
program ::= statement | program statement
statement ::= assignStmt | displayStmt
assignStmt ::= id = expr ;
displayStmt ::= display expr ;
expr ::= id | expr + expr | ( expr )
id ::= [a-zA-Z][a-zA-Z0-9_]*
(Note: this is only meant for demostrating the tools and the source
files will need to be modified and some things deleted when they are
adapted for the actual minijava project.)
The AST classes provided are closely based on those on the MiniJava
website, slightly modified to add tracking of line numbers, as well as
adding a separate Display node only used in the toy language, but not
for MiniJava. They have also been updated to use Lists with type
parameters instead of the original Vector class.
All of the compiler source code is in the src directory.
The TestScanner and TestParser classes are examples of how to use the
scanner and parser. You will need to create an actual MiniJava class
with the main program for your project, but the test code here should
provide some useful hints. The rest of the compiler is stored in
several subdirectories:
Scanner: the implementation of a demo scanner
Parser: the implementation of a demo parser
AST: the implementation of the abstract syntax tree
runtime: interface between compiled code and C environment
The lib directory stores the jar files for CUP and JFlex that are
needed to build and run the compiler and a couple of source files from
CUP that may be useful for reference.
SamplePrograms contains a sample program in the example language,
which you can replace with MiniJava programs to be be compiled and run
to test your MiniJava compiler as you develop it. The
SampleMiniJavaPrograms directory contains larger MiniJava programs for
testing, mostly taken from the MiniJava web site.
The build.xml ant file supports building, running, and testing the
demo compiler scanning and parsing examples. Look at it for details
and use it as a start for your own project's build sequence.
Sources: AST classes and SampleMiniJavaPrograms from the Appel/
Palsberg MiniJava project. Some code and ideas borrowed from an
earlier UW version by Craig Chambers with modifications by Jonathan
Beall and Hal Perkins. Updates to include current releases of JFlex
and CUP by Hal Perkins, Jan. 2017. Updates to use recent JFlex
ComplexSymbol class by Nate Yazdani, April 2018.