A fully-functional command-line tokenizer for the Jack programming language, built as part of the Nand2Tetris compiler toolchain.
It takes .jack files, strips comments, tokenizes their contents, and outputs an XML file (XxxT.xml) that conforms to the course specification.
Built in Java 21
Tested with JUnit
Runnable as a CLI tool
Self-contained, no dependencies beyond JDK and Maven
- Tokenizes:
- Jack language keywords, symbols, identifiers
- Integer constants and string constants
- Invalid lexemes are flagged for safety
- Strips all comments:
// single-line comments/* multi-line comments */— across multiple lines
- Escapes XML characters:
<,>,&→<,>,& - Comprehensive test coverage (comment handling, edge cases, and more)
- Accepts both single files and folders of
.jacksource files
Requires Java 21+
java -jar releases/jack-tokenizer.jar path/to/fileOrFolder- Input can be a single
.jackfile or a directory containing multiple.jackfiles. - Each file produces a corresponding XxxT.xml output in the same folder.
Clone and build:
git clone https://github.com/ffaustin17/Jack_Lexical_Analyzer.git
cd .../Jack_Lexical_Analyzer
mvn clean packageThen run:
java -jar target/jack-tokenizer-1.0-SNAPSHOT.jar path/to/fileOrFolderRun all unit tests using Maven
mvn testThis includes:
- Lexical unit tests
- Comment-stripping verification
- String escape correctness
- XML output comparison
You can also test the actual application by using resources/main directory as the directory containing the.jack files.
You should see some nice output!
- Syntax validation or parser integration
- Web frontend with file upload
- Integration into full
Jack->VM compiler - Comment position tracking
Thank you for making it this far! This project was made by me (Fabrice Faustin) as part of a deeper exploration into compiler design and lexical analysis tools.