fix infitite search for prior operator when opening brackets
This commit is contained in:
+19
-6
@@ -2,10 +2,10 @@
|
|||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
#include "syntaxer.hpp"
|
#include "syntaxer.hpp"
|
||||||
|
#include <cmath>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
namespace Syntax {
|
namespace Syntax {
|
||||||
|
|
||||||
@@ -606,13 +606,26 @@ static int same_inner_level_ops(const std::vector<Expression::Token>& tv, const
|
|||||||
|
|
||||||
static Expression::Token::Operator get_prior_mop(const std::vector<Expression::Token>& tv, const int location)
|
static Expression::Token::Operator get_prior_mop(const std::vector<Expression::Token>& 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
|
const Expression::Token &t = tv[i];
|
||||||
&& tv[i].v.o != Expression::Token::OPA
|
|
||||||
&& tv[i].v.o != Expression::Token::CPA)
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user