From 5685482eace22897712ef78356c875484781a8f2 Mon Sep 17 00:00:00 2001 From: avinal <185067@nith.ac.in> Date: Mon, 10 Aug 2020 12:22:11 +0530 Subject: [PATCH] not implemented yet --- include/symbol_table.hpp | 31 +++++++++++++++++++++++++++---- src/symbol_table.cpp | 23 ++++++++++++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/include/symbol_table.hpp b/include/symbol_table.hpp index 4c360c3..5f1c449 100644 --- a/include/symbol_table.hpp +++ b/include/symbol_table.hpp @@ -1,5 +1,5 @@ #pragma once -#ifdef SYMBOL_TABLE_HPP +#ifndef SYMBOL_TABLE_HPP #define SYMBOL_TABLE_HPP #include @@ -7,11 +7,34 @@ class symbol_table { private: - std::unordered_map symbols; + std::unordered_map symbols = { + {"R0", 0}, + {"R1", 1}, + {"R2", 2}, + {"R3", 3}, + {"R4", 4}, + {"R5", 5}, + {"R6", 6}, + {"R7", 7}, + {"R8", 8}, + {"R9", 9}, + {"R10", 10}, + {"R11", 11}, + {"R12", 12}, + {"R13", 13}, + {"R14", 14}, + {"R15", 15}, + {"SP", 0}, + {"LCL", 1}, + {"ARG", 2}, + {"THIS", 3}, + {"THAT", 4}, + {"SCREEN", 16384}, + {"KBD", 24576}, + }; public: - symbol_table(); - ~symbol_table(); + symbol_table() {} void add_entry(std::string symbol, int address); bool contains(std::string symbol); diff --git a/src/symbol_table.cpp b/src/symbol_table.cpp index c993f6a..610193d 100644 --- a/src/symbol_table.cpp +++ b/src/symbol_table.cpp @@ -1 +1,22 @@ -#include "../include/symbol_table.hpp" \ No newline at end of file +#include "../include/symbol_table.hpp" + +void symbol_table::add_entry(std::string symbol, int address) +{ + symbols.insert(std::make_pair(symbol, address)); +} + +bool symbol_table::contains(std::string symbol) +{ + return !(symbols.find(symbol) == symbols.end()); +} + +int symbol_table::get_address(std::string symbol) +{ + if (contains(symbol)) + { + return symbols[symbol]; + }else + { + return -1; + } +} \ No newline at end of file