omardoescode / Hack-Syntax-Analyzer

This is the Hack computer syntax analyzer, used by the Hack compiler to generate VM Code. This is project 10 in Nand2Tetris great course

Repository from Github https://github.comomardoescode/Hack-Syntax-AnalyzerRepository from Github https://github.comomardoescode/Hack-Syntax-Analyzer

Jack Syntax Analyzer

This repository contains the Hack computer syntax analyzer, which is used by the Hack compiler to generate VM code. This project is part of Project 10 in the Nand2Tetris course.

Structure

  • HackMap: Where all information about the Jack language such as keywords, data about tokens, non terminal rules are stored.
  • Tokenizer: Breaks down input into tokens.
  • CompilationEngine: Processes tokens and generates corresponding VM code.
  • OutputEngine: An abstract class for any output engine, that is, the output of the analyzing process
  • XMLOutputEngine: A subclass of the OutputEngine that translates code into XML.
  • JackSyntaxAnalyzer: A wrapper for the whole program.

Usage

  1. Clone the repository
  2. Compilation
cd Hack-Syntax-Analyzer
mkdir build
cmake -S . -B ./build
cmake --build ./build --target analyzer
  1. Usage
./build/main <file_or_directory_path>

This will generate corresponding XML files in the same path that show the syntax of the code. An example test is found in tests directory

Extend this program

Output engine in this class is an abstract class that is extendable to generate more output engines, and this output engine is injected as an argument to the analyzer

#include <OutputEngine.h>
class YAMLOutputEngine: public OutputEngine {
    // code goes here
}

/////////////////////////////////////

About

This is the Hack computer syntax analyzer, used by the Hack compiler to generate VM Code. This is project 10 in Nand2Tetris great course


Languages

Language:C++ 96.3%Language:C 2.1%Language:CMake 1.6%