1#include <gtest/gtest.h>
14 return std::stod(std::string(tok.raw));
47 ASSERT_TRUE(parser.has_value());
54 auto res = parser.Parse(
"3 * 3 + 4^2 - (9 / 3)");
55 ASSERT_TRUE(res.has_value());
57 ASSERT_EQ(res->GetValue(), 22.0);
bf::GrammarDefinition< double > G
bf::DefineTerminal< G, R"(\*)"> OP_MUL(bf::Left)
bf::DefineNonTerminal< G, "expression"> expression
bf::DefineTerminal< G, R"(\()"> PAR_OPEN;bf::DefineTerminal< G, R"(\))"> PAR_CLOSE
bf::DefineTerminal< G, R"(\+)"> OP_ADD(bf::Left)
bf::DefineTerminal< G, R"(\^)"> OP_EXP(bf::Right)
bf::DefineTerminal< G, R"(\d+(\.\d+)?)", double > NUMBER([](auto const &tok) { return std::stod(std::string(tok.raw));})
bf::DefineTerminal< G, R"(\/)"> OP_DIV(bf::Left)
bf::DefineNonTerminal< G, "statement"> statement
bf::DefineTerminal< G, R"(\-)"> OP_SUB(bf::Left)
TEST(Parser, Construction)
static std::expected< SLRParser, Error > Build(NonTerminal< G > &start)