diff options
Diffstat (limited to 'cpp.cpp')
-rw-r--r-- | cpp.cpp | 43 |
1 files changed, 35 insertions, 8 deletions
@@ -361,6 +361,8 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv { if (childTypesOfNodeMatch(index, {"literal"})) return getValue(index, 0); + if (childTypesOfNodeMatch(index, {"(", "expression", ")"})) + return getValue(index, 1); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, @@ -394,21 +396,46 @@ std::unordered_map<std::string, std::function<std::any(index_t)>> CPP::getNodeEv }, { "multiplicative-expression", [&](index_t index) -> std::any { + if (childTypesOfNodeMatch(index, {"pm-expression", "multiplicative-expression-EXT"})) { + if (childTypesOfChildMatch(index, 1, {"*", "", ""})) { + FlowGraph::LocalScope scope; // TODO: move to context! + FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)}; + FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))}; + FlowGraph::Data value1 {std::any_cast<FlowGraph::Data>(getValue(index, 1))}; + + std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Multiply, destination, value0, value1)}; + return node; + } + } if (childTypesOfNodeMatch(index, {"pm-expression", ""}) && !getValue(index, 1).has_value()) return getValue(index, 0); throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } }, + { "multiplicative-expression-EXT", [&](index_t index) -> std::any + { + if (childTypesOfNodeMatch(index, {"*", "pm-expression", ""}) && !getValue(index, 2).has_value()) { + return getValue(index, 1); + } else if (childTypesOfNodeMatch(index, {})) { + return {}; + } + throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO + } + }, { "additive-expression", [&](index_t index) -> std::any { - if (childTypesOfNodeMatch(index, {"multiplicative-expression", "additive-expression-EXT"}) && childTypesOfChildMatch(index, 1, {"+", "", ""})) { - FlowGraph::LocalScope scope; // TODO: move to context! - FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)}; - FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))}; - FlowGraph::Data value1 {std::any_cast<FlowGraph::Data>(getValue(index, 1))}; - - std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Add, destination, value0, value1)}; - return node; + if (childTypesOfNodeMatch(index, {"multiplicative-expression", "additive-expression-EXT"})) { + if (childTypesOfChildMatch(index, 1, {"+", "", ""})) { + FlowGraph::LocalScope scope; // TODO: move to context! + FlowGraph::Data destination{FlowGraph::MakeTemporaryInt(scope)}; + FlowGraph::Data value0 {std::any_cast<FlowGraph::Data>(getValue(index, 0))}; + FlowGraph::Data value1 {std::any_cast<FlowGraph::Data>(getValue(index, 1))}; + + std::shared_ptr<FlowGraph::Node> node {std::make_shared<FlowGraph::BinaryOperation>(FlowGraph::BinaryOperationType::Add, destination, value0, value1)}; + return node; + } else if (!getValue(index, 1).has_value()) { + return getValue(index, 0); + } } throw std::runtime_error("ICE: Unsupported childs: "s + ruleString(index)); // TODO } |