Skip to content

Commit

Permalink
feat: Add interpret_declarations and interpret_expression functions t…
Browse files Browse the repository at this point in the history
…o interpreter
  • Loading branch information
sillydan1 committed Sep 2, 2022
1 parent e3250f5 commit 2ccc3e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/drivers/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace expr {
~interpreter() override = default;

auto parse(const std::string &f) -> int override;
auto interpret_declarations(const std::string& f) -> symbol_table_t;
auto interpret_expression(const std::string& f) -> symbol_value_t;
auto get_symbol(const std::string& identifier) -> syntax_tree_t override;
void add_tree(const syntax_tree_t& tree) override;
void add_tree(const std::string& identifier, const syntax_tree_t& tree) override;
Expand Down
16 changes: 16 additions & 0 deletions src/drivers/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ namespace expr {
}
}

auto interpreter::interpret_declarations(const std::string &f) -> symbol_table_t {
result = {};
auto res = parse(f);
if(res != 0)
throw std::logic_error(error);
return result;
}

auto interpreter::interpret_expression(const std::string &f) -> symbol_value_t {
expression_result = {};
auto res = parse(f);
if(res != 0)
throw std::logic_error(error);
return expression_result;
}

auto interpreter::get_symbol(const std::string &identifier) -> syntax_tree_t {
#ifndef NDEBUG
if (!environment.contains(identifier))
Expand Down

0 comments on commit 2ccc3e6

Please sign in to comment.