14 return std::stod(std::string(tok.raw));
47int main(
int argc,
char const **argv)
51 std::cerr <<
"Usage: calculator expression" << std::endl;
57 auto result = calculator.Parse(argv[1]);
60 std::cerr << result.error().message << std::endl;
64 std::cout << *result << std::endl;
bf::GrammarDefinition< double > G
bf::DefineNonTerminal< G > expression
bf::DefineTerminal< G, R"(\*)"> OP_MUL(bf::Left)
bf::DefineTerminal< G, R"(\()"> PAR_OPEN;bf::DefineTerminal< G, R"(\))"> PAR_CLOSE
bf::DefineTerminal< G, R"(\+)"> OP_ADD(bf::Left)
bf::DefineNonTerminal< G > statement
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));})
int main(int argc, char const **argv)
bf::DefineTerminal< G, R"(\/)"> OP_DIV(bf::Left)
bf::DefineTerminal< G, R"(\-)"> OP_SUB(bf::Left)
static std::expected< SLRParser, Error > Build(NonTerminal< G > &start)