diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 28871da..e7367a8 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -3,10 +3,10 @@ name: CMake Pipeline on: pull_request: branches: - - master + - main push: branches: - - master + - main env: BUILD_TYPE: Release @@ -34,12 +34,12 @@ jobs: working-directory: ${{github.workspace}}/build shell: bash # Execute the build. You can specify a specific target with "--target " - run: cmake --build . --config $BUILD_TYPE -j$(nproc) + run: cmake --build . --config $BUILD_TYPE -j$(nproc) --target expr - name: Upload Artifact uses: actions/upload-artifact@v2 with: name: library - path: ${{ github.workspace }}/build/expr + path: ${{ github.workspace }}/build/libexpr.so build-windows: if: ${{ github.event.pull_request.draft == false }} name: Build For MS Windows Systems diff --git a/CMakeLists.txt b/CMakeLists.txt index 944d394..cf1e192 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include_directories( include src ) -add_library(${PROJECT_NAME} +add_library(${PROJECT_NAME} SHARED ${BISON_expr_parser_OUTPUTS} ${FLEX_expr_scanner_OUTPUTS} src/parser/driver.cpp diff --git a/include/operations/boolean.h b/include/operations/boolean.h index 85f2f72..00c5925 100644 --- a/include/operations/boolean.h +++ b/include/operations/boolean.h @@ -4,7 +4,8 @@ symbol_value_t and_(const symbol_value_t& a, const symbol_value_t& b); symbol_value_t or_(const symbol_value_t& a, const symbol_value_t& b); symbol_value_t not_(const symbol_value_t& a); -symbol_value_t operator&&(const symbol_value_t& a, const symbol_value_t& b); -symbol_value_t operator||(const symbol_value_t& a, const symbol_value_t& b); -symbol_value_t operator!(const symbol_value_t& a); +// TODO: These operators are ambiguous with symbol_value_t && std::false_type / std::true_type for some reason. +//symbol_value_t operator&&(const symbol_value_t& a, const symbol_value_t& b); +//symbol_value_t operator||(const symbol_value_t& a, const symbol_value_t& b); +//symbol_value_t operator!(const symbol_value_t& a); #endif //EXPR_BOOLEAN_H diff --git a/src/operations/add.cpp b/src/operations/add.cpp index d88edea..d396fc8 100644 --- a/src/operations/add.cpp +++ b/src/operations/add.cpp @@ -1,10 +1,12 @@ #include "operations/add.h" -#include "util.h" +#include "operations/util.h" #include template auto t_add(const T1&, const T2&) { - throw std::domain_error((std::ostringstream{} << "Unable to add type " << typeid(T1).name() << " and " << typeid(T2).name()).str()); + std::ostringstream ss{}; + ss << "Unable to add type " << typeid(T1).name() << " and " << typeid(T2).name(); + throw std::domain_error(ss.str()); return nullptr; // Must return something } template<> auto t_add(const int& x, const int& y) { diff --git a/src/operations/boolean.cpp b/src/operations/boolean.cpp index c7618cc..ca951d3 100644 --- a/src/operations/boolean.cpp +++ b/src/operations/boolean.cpp @@ -1,20 +1,26 @@ #include "operations/boolean.h" -#include "util.h" +#include "operations/util.h" #include template auto t_and(const T1&, const T2&) { - throw std::domain_error((std::ostringstream{} << "Unable to AND types " << typeid(T1).name() << " and " << typeid(T2).name()).str()); + std::ostringstream ss{}; + ss << "Unable to AND types " << typeid(T1).name() << " and " << typeid(T2).name(); + throw std::domain_error(ss.str()); return nullptr; // Must return something } template auto t_or(const T1&, const T2&) { - throw std::domain_error((std::ostringstream{} << "Unable to OR types " << typeid(T1).name() << " and " << typeid(T2).name()).str()); + std::ostringstream ss{}; + ss << "Unable to OR types " << typeid(T1).name() << " and " << typeid(T2).name(); + throw std::domain_error(ss.str()); return nullptr; // Must return something } template auto t_not(const T1&) { - throw std::domain_error((std::ostringstream{} << "Unable to NOT type " << typeid(T1).name()).str()); + std::ostringstream ss{}; + ss << "Unable to NOT type " << typeid(T1).name(); + throw std::domain_error(ss.str()); return nullptr; // Must return something } diff --git a/src/operations/divide.cpp b/src/operations/divide.cpp index a97f056..77e2cd4 100644 --- a/src/operations/divide.cpp +++ b/src/operations/divide.cpp @@ -1,26 +1,32 @@ #include "operations/divide.h" -#include "util.h" +#include "operations/util.h" #include template auto t_divide(const T1&, const T2&) { - throw std::domain_error((std::ostringstream{} << "Unable to divide type " << typeid(T1).name() << " and " << typeid(T2).name()).str()); + std::ostringstream ss{}; + ss << "Unable to divide type " << typeid(T1).name() << " and " << typeid(T2).name(); + throw std::domain_error(ss.str()); return nullptr; // Must return something } template<> auto t_divide(const int& x, const int& y) { - if(y == 0 || (x == INT32_MIN && y == -1)) throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); + if(y == 0 || (x == INT32_MIN && y == -1)) + throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); return x / y; } template<> auto t_divide(const float& x, const int& y) { - if(y == 0) throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); + if(y == 0) + throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); return x / y; } template<> auto t_divide(const int& x, const float& y) { - if(y == 0.0f) throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); + if(y == 0.0f) + throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); return x / y; } template<> auto t_divide(const float& x, const float& y) { - if(y == 0.0f) throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); + if(y == 0.0f) + throw std::domain_error("Cannot divide with zero or INT_MIN / -1"); return x / y; } diff --git a/src/operations/multiply.cpp b/src/operations/multiply.cpp index a7844eb..68e25ff 100644 --- a/src/operations/multiply.cpp +++ b/src/operations/multiply.cpp @@ -1,10 +1,12 @@ #include "operations/multiply.h" -#include "util.h" +#include "operations/util.h" #include template auto t_multiply(const T1&, const T2&) { - throw std::domain_error((std::ostringstream{} << "Unable to multiply type " << typeid(T1).name() << " and " << typeid(T2).name()).str()); + std::ostringstream ss{}; + ss << "Unable to multiply type " << typeid(T1).name() << " and " << typeid(T2).name(); + throw std::domain_error(ss.str()); return nullptr; // Must return something } template<> auto t_multiply(const int& x, const int& y) { diff --git a/src/operations/subtract.cpp b/src/operations/subtract.cpp index 09f88c2..b9e3804 100644 --- a/src/operations/subtract.cpp +++ b/src/operations/subtract.cpp @@ -1,10 +1,12 @@ #include "operations/subtract.h" -#include "util.h" +#include "operations/util.h" #include template auto t_subtract(const T1&, const T2&) { - throw std::domain_error((std::ostringstream{} << "Unable to subtract type " << typeid(T1).name() << " and " << typeid(T2).name()).str()); + std::ostringstream ss{}; + ss << "Unable to subtract type " << typeid(T1).name() << " and " << typeid(T2).name(); + throw std::domain_error(ss.str()); return nullptr; // Must return something } template<> auto t_subtract(const int& x, const int& y) { diff --git a/src/parser/parser.y b/src/parser/parser.y index b239d3c..cd5300b 100644 --- a/src/parser/parser.y +++ b/src/parser/parser.y @@ -1,6 +1,5 @@ %skeleton "lalr1.cc" -%require "3.8" -%header +%require "3.5" %define api.token.raw @@ -23,7 +22,7 @@ // Enable parser tracing and detailed errors %define parse.trace -%define parse.error detailed +%define parse.error verbose // Enable full lookahead to avoid incorrect error information // See https://www.gnu.org/software/bison/manual/html_node/LAC.html for details %define parse.lac full @@ -34,6 +33,7 @@ } %define api.token.prefix {TOK_} +%token YYEOF 0 %token ASSIGN ":=" MINUS "-"