Skip to content

Commit

Permalink
Fixed empty expression list bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Kim committed Jul 22, 2020
1 parent 651f906 commit db50298
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MathEngine/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CXX := g++

mode := release
optflag.release := -Ofast
optflag.release := -Ofast -g
optflag.debug := -g
OPT_FLAG := ${optflag.${mode}}

Expand Down
3 changes: 3 additions & 0 deletions MathEngine/Parser/modifiedShuntingYard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ expression postfix_to_expression(FixedStack<Token*>& outputStack){
}
continue;
case RPAREN:
if (expressionLists.empty()){
throw Exception("Cannot construct Tuple from empty list of expressions");
}
if (!expressionStacks.back().empty()){
expressionLists.back().emplace_back(expressionStacks.back().pop());
if (!expressionStacks.back().empty()){
Expand Down
14 changes: 12 additions & 2 deletions MathEngine/Utils/FixedStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@ class FixedStack { // Fixed Size Stack
}
fs.clear();
}
T& peek(){ return data[tail-1]; }
T pop(){ return data[--tail]; }
T& peek(){
if (tail == 0){
throw std::out_of_range("FixedStack::peek out of range");
}
return data[tail-1];
}
T pop(){
if (tail == 0){
throw std::out_of_range("FixedStack::pop out of range");
}
return data[--tail];
}
void clear(){ tail = 0; }

T* begin(){ return data.get(); }
Expand Down
5 changes: 5 additions & 0 deletions Tests/Tests/SyntaxTests/syntaxTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ TEST_CASE("Syntax Error Tests", "[syntax]" ) {
requireErrorIsEqual("{{", "Matrix must be two dimensional");

requireErrorIsEqual("TEST(3)", "Invalid Function: TEST");

requireErrorIsEqual("integral(e^(-", "Cannot construct Tuple from empty list of expressions");
requireErrorIsEqual("integral(e^(-x", "integral: non-default argument follows default argument");
requireErrorIsEqual("integral(e^(-x^", "Insufficient Number of Arguments for Binary Operator: ^");
requireErrorIsEqual("integral(e^(-x^2", "integral: non-default argument follows default argument");
}

0 comments on commit db50298

Please sign in to comment.