Fix parsing arithmetic expressions

This commit is contained in:
Sofia 2020-07-06 11:44:19 +03:00
parent 082981f203
commit 529008a1fc
2 changed files with 2 additions and 4 deletions

View File

@ -1,3 +1,3 @@
let number = 2 + 5 * 2 + 5 + 1 * 10 + 1;
let number = 2 * 5 * 2 - 10 + 5 * 7;
let text = "" + number;
print(text);

View File

@ -149,11 +149,10 @@ impl ArithmeticExpression {
// Replace all (expr, "*"), (expr, any) => ((mult_expr, any)
let clone = list.clone();
let iter = clone.iter().enumerate().rev();
let mut previous: Option<(Expression, Option<String>)> = None;
for (idx, (exp, sign)) in iter {
if let Some(sign) = sign {
if sign == "*" {
if let Some((exp2, sign2)) = previous {
if let Some((exp2, sign2)) = list.clone().get(idx + 1) {
list.remove(idx + 1);
list.remove(idx);
let expr = Expression::ArithmeticExpression(
@ -164,7 +163,6 @@ impl ArithmeticExpression {
};
}
}
previous = Some((exp.clone(), sign.clone()));
}
let mut ret = Err(SyntaxError::Fatal);