diff --git a/src/syntaxer.cpp b/src/syntaxer.cpp index 94bf5e7..34dd52a 100644 --- a/src/syntaxer.cpp +++ b/src/syntaxer.cpp @@ -2,10 +2,10 @@ #include "parser.hpp" #include "print.h" #include "syntaxer.hpp" +#include #include #include #include -#include namespace Syntax { @@ -606,13 +606,26 @@ static int same_inner_level_ops(const std::vector& tv, const static Expression::Token::Operator get_prior_mop(const std::vector& tv, const int location) { - for (int i = location - 1; i >= 0; i--) + for (int i = location - 1, lv = 0; i >= 0; i--) { - if (tv[i].t == Expression::Token::OPERATOR - && tv[i].v.o != Expression::Token::OPA - && tv[i].v.o != Expression::Token::CPA) + const Expression::Token &t = tv[i]; + + if (t.t == Expression::Token::OPERATOR) { - return tv[i].v.o; + if (t.v.o == Expression::Token::OPA) + { + lv--; + + if (lv == -2) + { + // enclosed in another pair of brackets, safe to assume ADD + return Expression::Token::ADD; + } + } + else + { + return t.v.o; + } } }