Compiler Tools
This page provides some example programs and reusable classes, written in Java, which can be used for writing compiler-related programs. They include interactive interface tools such as syntax highlighting or other language-aware editing.
The reusable classes are documented with javadoc, but since they are likely to be adapted as main program components, rather than used as utility library classes, they are not packaged.
A Mini Editor
This example program is perhaps the simplest working editor that can be written in Java. It can act as a starting point for editor-based programs generally.
As an aside, here is an example program showing how to detect and handle arrow keys:
Scanning
This is a reusable scanner with an interface which is suitable for
conventional scanning as in a compiler, and for interactive scanning as in a
syntax highlighting editor. The simple example program Scan.java
just scans a file. The example scanner TextScanner.java shows how
to extend Scanner.java by overriding read. It scans
the same language as Scanner.java, but uses a table-driven design,
as might be produced from a generator.
API Documentation Scanner.java Token.java TokenTypes.java Symbol.java
Design Scan.java TextScanner.java JavaScanner.java
Syntax Highlighting
Given the scanner, here is a reusable SyntaxHighlighter class
which uses it, illustrated by the small example program
HighlightEdit.java, adapted slightly from
MiniEdit.java:
API Documentation SyntaxHighlighter.java
Design HighlightEdit.java
File Handling
It is surprising how easy it is to get hung up on 'easy' things like a file
menu. One reason is that people regard it as belonging to the main program,
amd don't separate out the file handling into a class of its own. So, that's
exactly what I have done in this reusable FileHandler class. The
FileHandler class is illustrated by a small example program
FileEdit.java, adapted slightly from
HighlightEdit.java:
Undo Handling
An editor needs an edit menu, and particularly undo and redo. These are
essential for quick workers, to give you the confidence to try things out
rapidly without the fear of making unrecoverable mistakes. Here is a reusable
UndoHandler class, and example program.

