mirror of
https://github.com/avinal/The-VM-to-HACK-Translator.git
synced 2026-01-07 21:58:33 +05:30
master
The-VM-to-HACK-Translator
Translates Virtual Machine Language into HACK Assembly language.
Important: If you are taking this course then I suggest you to try to write the assembler yourself first, it is not very easy and not very tough too. At least not impossible, because I did it 😘
Get Started with the project
- Directory Structure
. |_include # Contains headers |_src # Contains Source Code and Main |_Test-Files # Example HACK VM Files - Clone this repo
git clone https://github.com/avinal/The-VM-to-HACK-Translator.git - Build and run, provide only HACK VM Language file. Don't confuse with
.vmextesion.cd The-VM-to-HACK-Translator make ./VMTranslator file.vm - Start over after modification
make clean
Tips
In case you want to modify this project, you can use Boost C++ Libraries, they can simplify many tasks needed by this project.
Some Words
This was a nice project and taugh me many things. Given below are some miraculous code snippets that proved to be really useful and are well researched. Hope you will find them useful.
- Trim spaces, comments, carrige returns, newline, tab and verticle tabs:
inline std::string trim(std::string str) { if (str.find('/') != std::string::npos) // comments { str.erase(str.find('/')); } str.erase(0, str.find_first_not_of(" \r\t\v\n")); //prefixing str.erase(str.find_last_not_of(" \r\t\v\n") + 1); //surfixing} return str; } - Tokenize a string using C++ with respect to a delimiter, space by defalt (string split):
#include <sstream> #include <vector> std::vector<std::string> split(std::string str, char delimiter = ' ') { std::vector<std::string> tokens; std::stringstream tokenizer(str); std::string intermediate; while (std::getline(tokenizer, intermediate, delimiter)) { tokens.push_back(intermediate); } return tokens; } - Fascinating Using Lambdas with Map to implement a function or function pointers. See here
Languages
C++
77.3%
Scilab
20.3%
Makefile
2.4%