diff --git a/src/parse/meson.build b/src/parse/meson.build index eed8403..1c8159e 100644 --- a/src/parse/meson.build +++ b/src/parse/meson.build @@ -31,4 +31,7 @@ parser = library( 'parser-driver.hh', flex.process('scanner.ll'), bison.process('parser.yy'), + dependencies: [ + bignum, + ], ) diff --git a/src/parse/parser-driver.cc b/src/parse/parser-driver.cc index c6df35e..cb5739d 100644 --- a/src/parse/parser-driver.cc +++ b/src/parse/parser-driver.cc @@ -28,4 +28,8 @@ yy::location const& ParserDriver::location() const { return current_location_; } +ParserDriver::numeric_type const& ParserDriver::result() const { + return result_; +} + } // namespace abacus::parser diff --git a/src/parse/parser-driver.hh b/src/parse/parser-driver.hh index 076ea91..9262c70 100644 --- a/src/parse/parser-driver.hh +++ b/src/parse/parser-driver.hh @@ -4,10 +4,14 @@ #include "parser.hh" +#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... + namespace abacus::parser { class ParserDriver { public: + using numeric_type = abacus::bignum::BigNum; + ParserDriver(); int parse(std::string filename); @@ -18,9 +22,10 @@ public: yy::location& location(); yy::location const& location() const; + numeric_type const& result() const; + private: - // FIXME: will become BigNum - int result_ = 0; + numeric_type result_{0}; std::string filename_{}; yy::location current_location_{}; bool parse_trace_p_ = false; diff --git a/src/parse/parser.yy b/src/parse/parser.yy index 4b5ce1b..05cdc87 100644 --- a/src/parse/parser.yy +++ b/src/parse/parser.yy @@ -35,6 +35,8 @@ namespace abacus::parser { class ParserDriver; } // namespace abacus::parser + +#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... } %code provides { @@ -54,8 +56,7 @@ class ParserDriver; %token EOF 0 "end-of-file" -// FIXME:will become BigNum -%token NUM "number" +%token NUM "number" // Use `<<` to print everything %printer { yyo << $$; } <*>; @@ -73,8 +74,7 @@ class ParserDriver; %left TIMES DIVIDE %precedence UNARY -// FIXME: will become BigNum -%type input exp +%type input exp %% diff --git a/src/parse/scanner.ll b/src/parse/scanner.ll index e85f9b1..a6c6bc1 100644 --- a/src/parse/scanner.ll +++ b/src/parse/scanner.ll @@ -1,4 +1,6 @@ %{ +#include + #include "parser-driver.hh" #include "parser.hh" %} @@ -41,7 +43,11 @@ int [0-9]+ "(" return yy::parser::make_LPAREN(loc); ")" return yy::parser::make_RPAREN(loc); -{int} return yy::parser::make_NUM(std::stoi(yytext), loc); +{int} { + abacus::bignum::BigNum num; + std::stringstream(yytext) >> num; + return yy::parser::make_NUM(num, loc); +} . { using namespace yy;