Skip to content

Commit

Permalink
initial table
Browse files Browse the repository at this point in the history
  • Loading branch information
mtygesen committed May 2, 2024
1 parent 836156a commit 002c5fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/src/Value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <variant>
#include <vector>
#include <unordered_map>

namespace dplsrc {
class Value {
Expand Down Expand Up @@ -64,9 +65,10 @@ class Value {
using STR = std::string;
using NONETYPE = std::nullptr_t;
using LIST = std::vector<Value>;
using TABLE = std::unordered_map<STR, LIST>;

private:
mutable std::variant<INT, FLOAT, STR, BOOL, LIST, NONETYPE> innerValue;
mutable std::variant<INT, FLOAT, STR, BOOL, NONETYPE, LIST, TABLE> innerValue;
};
} // namespace dplsrc

Expand Down
12 changes: 10 additions & 2 deletions src/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,15 @@ void Evaluator::visit(const std::shared_ptr<ReturnNode> &node) {
node->setVal(childNode->getVal());
}

void Evaluator::visit(const std::shared_ptr<TableNode> &node) {}
void Evaluator::visit(const std::shared_ptr<TableNode> &node) {
std::cout << "tablenode";
std::vector<std::shared_ptr<AstNode>> childNodes = node->getChildNodeList();
for (size_t i = 0; i < childNodes.size(); ++i) {
childNodes[i]->accept(shared_from_this());
}

node->setVal(nullptr);
}

void Evaluator::visit(const std::shared_ptr<UnaryExprNode> &node) {}

Expand All @@ -255,7 +263,7 @@ void Evaluator::initPtable() {
return nullptr;
};

Procedure::ProcType input0 = [](std::vector<std::shared_ptr<AstNode>> arg) {
Procedure::ProcType input0 = []([[maybe_unused]] std::vector<std::shared_ptr<AstNode>> arg) {
std::string inputStr;
std::getline(std::cin, inputStr);
return inputStr;
Expand Down
4 changes: 4 additions & 0 deletions src/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ std::string Value::toString() const {
result += "]";

return result;
} else if (is<TABLE>()) {
throw std::runtime_error("Not implemented");
}

throw std::runtime_error("Error: unknown value type");
Expand Down Expand Up @@ -72,6 +74,8 @@ std::string Value::toTypeString(bool verbose) const {
listStr += "]";

return listStr;
} else if (is<TABLE>()) {
throw std::runtime_error("Not implemented");
}

throw std::runtime_error("Error: unknown type cannot be converted to a string");
Expand Down

0 comments on commit 002c5fa

Please sign in to comment.