HACK Assembler

This assembler was built for Nisan and Schocken's NAND to Tetris (Building a Modern Computer from First Principles) course. This course involves building a simple Turing-complete computer and all its components, starting at the NAND gate, and then building software for the computer. This assembler is built as part of the course, and is used to assemble the "HACK" computer's assembly language into machine language.

The assembly language specifications can be found here.

My implementation of the assembler uses a single-pass recursive algorithm to read the input and either assemble it or report an error if the input is syntactically invalid. The input is read exactly once, from start to finish, as part of the algorithm; no loop structures are used (except to arrange the memory in a specific order to pass the course's test cases - this feature is not actually required for the assembler to function, however.)

The assembler is built in Javascript and hosted on a Node.js server. It consists of 110 lines and has a filesize of 5KB. Due to the memory limits I have imposed on the Node server, and in order to prevent this assembler from being used to complete one of the NAND to Tetris projects, I have limited the input to roughly 10,000 lines.