mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-06-22 10:41:22 +02:00
Fixed associativity for parse_sum/parse_factor
This commit is contained in:
parent
48c1247b96
commit
b8b7a0e257
@ -122,11 +122,7 @@ fn build_fn_decl(
|
||||
// Check if all the expressions in the parameter_expr are
|
||||
// variables. If not, it can't be turned into a function declaration.
|
||||
let all_are_vars = match ¶meter_expr {
|
||||
Expr::Vector(exprs) => {
|
||||
exprs
|
||||
.iter()
|
||||
.any(|x| matches!(x, Expr::Var(_)))
|
||||
}
|
||||
Expr::Vector(exprs) => exprs.iter().any(|x| matches!(x, Expr::Var(_))),
|
||||
Expr::Group(expr) => {
|
||||
matches!(&**expr, Expr::Var(_))
|
||||
}
|
||||
@ -775,7 +771,13 @@ fn build_var(context: &mut Context, name: &str) -> Expr {
|
||||
}
|
||||
}
|
||||
|
||||
if context.in_sum_prod && context.sum_variable_names.as_ref().unwrap().contains(&name.to_string()) {
|
||||
if context.in_sum_prod
|
||||
&& context
|
||||
.sum_variable_names
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.contains(&name.to_string())
|
||||
{
|
||||
return Expr::Var(Identifier::from_full_name(name));
|
||||
}
|
||||
|
||||
|
@ -433,7 +433,7 @@ fn parse_sum(context: &mut Context) -> Result<Expr, CalcError> {
|
||||
while match_token(context, TokenKind::Plus) || match_token(context, TokenKind::Minus) {
|
||||
let op = peek(context).kind;
|
||||
advance(context);
|
||||
let right = parse_factor(context)?;
|
||||
let right = parse_sum(context)?;
|
||||
|
||||
left = Expr::Binary(Box::new(left), op, Box::new(right));
|
||||
}
|
||||
@ -447,11 +447,7 @@ fn parse_factor(context: &mut Context) -> Result<Expr, CalcError> {
|
||||
if let Expr::Unary(TokenKind::Percent, percent_left) = left.clone() {
|
||||
let try_parse = parse_factor(context);
|
||||
if try_parse.is_ok() {
|
||||
left = Expr::Binary(
|
||||
percent_left,
|
||||
TokenKind::Percent,
|
||||
Box::new(try_parse?),
|
||||
);
|
||||
left = Expr::Binary(percent_left, TokenKind::Percent, Box::new(try_parse?));
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,7 +473,7 @@ fn parse_factor(context: &mut Context) -> Result<Expr, CalcError> {
|
||||
_ => advance(context).kind,
|
||||
};
|
||||
|
||||
let right = parse_unit(context)?;
|
||||
let right = parse_factor(context)?;
|
||||
left = Expr::Binary(Box::new(left), op, Box::new(right));
|
||||
}
|
||||
|
||||
|
@ -2,4 +2,4 @@ x = 2
|
||||
y = 3
|
||||
f(x) = 2x(x - 3)(y + 2)
|
||||
|
||||
f(f(x) + y) = 3400
|
||||
2f(f(x) + y) = 6800
|
Loading…
x
Reference in New Issue
Block a user