Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.
/ JackCompiler Public archive

Compiler for Nand2Tetris / 计算思维课程编译器大作业

License

Notifications You must be signed in to change notification settings

goldsail/JackCompiler

Repository files navigation

JackCompiler

This project is my implementation of a compiler that compiles the Jack language into Jack VM bytecodes. See Nand2Tetris for details.

JackTokenizer Module

Run the unit test without IntelliJ IDEA:

cd <this git repo>
javac -d ./out/shell/ ./src/JackCompiler/*.java
cd ./out/shell/
java JackCompiler.JackTokenizer ../../test/Main.jack
java JackCompiler.JackTokenizer ../../test/Square.jack
java JackCompiler.JackTokenizer ../../test/SquareGame.jack
cd ../../

This module implements the JackTokenizer in textbook on p.214. It reads a .jack file and tokenizes it.

JackAnalyzer Module

Developed using top-down LL(0) parser...

Run the unit test without IntelliJ IDEA:

cd <this git repo>
javac -d ./out/shell/ ./src/JackCompiler/*.java
cd ./out/shell/
java JackCompiler.JackAnalyzer ../../test/Main.jack ../../test/Main.xml
java JackCompiler.JackAnalyzer ../../test/Square.jack ../../test/Square.xml
java JackCompiler.JackAnalyzer ../../test/SquareGame.jack ../../test/SquareGame.xml
cd ../../

This module implements the JackAnalyzer in textbook on pp.208-209. It reads a .jack file, parses it, and output an .xml file.

This module is finished, but is still under test.

JackCodeGenerator Module

Developed using recursive-descent. It should be able to generate a .vm file from an input .xml file.

Run the unit test without IntelliJ IDEA:

cd <this git repo>
javac -d ./out/shell/ ./src/JackCompiler/*.java
cd ./out/shell/
java JackCompiler.JackCodeGenerator ../../test/Main.jack ../../test/Main.xml ../../test/Main.vm
java JackCompiler.JackCodeGenerator ../../test/Square.jack ../../test/Square.xml ../../test/Square.vm
java JackCompiler.JackCodeGenerator ../../test/SquareGame.jack ../../test/SquareGame.xml ../../test/SquareGame.vm
cd ../../

This module is finished, but is still under test.

HttpWebApi Module

You can send your Jack code by sending POST to endpoint /compile at port args[0]. The POST data is the code in text format.

Run the Http Web API server (it listens to port args[0]):

cd <this git repo>
javac -d ./out/shell/ ./src/JackCompiler/*.java
cd ./out/shell/
java JackCompiler.HttpWebApi 3247
cd ../../

Alternatively, using the HTTP POST tool at http://coolaf.com/tool/post (select raw -> text(test/plain)), you can send your Jack code as POST data:

  • to http://119.28.44.116:3247/compile to compile it into Jack VM bytecodes, or

  • to http://119.28.44.116:3247/analyze to parse it into a syntax tree.

References

Nand2Tetris Project 10 Nand2Tetris Project 11

About

Compiler for Nand2Tetris / 计算思维课程编译器大作业

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages