Skip to content

Commit

Permalink
0.9.514
Browse files Browse the repository at this point in the history
- EVAL Fix
  • Loading branch information
RobbyV2 committed Dec 7, 2024
1 parent 09b5b6c commit 230090f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ impl Parser {
}
Ok(AstNode::Input(prompt))
}
Some(Token::Eval) => {
self.advance();
if !self.match_token(&Token::OpenParen) {
return Err("Expected '(' after 'EVAL'".to_string());
}
let expr = self.parse_expression(debug)?;
if !self.match_token(&Token::CloseParen) {
return Err("Expected ')' after expression in 'EVAL'".to_string());
}
Ok(AstNode::Eval(Box::new(expr)))
}
_ => {
Self::debug_print(
debug,
Expand Down
14 changes: 14 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,20 @@ DISPLAY(arr)"#,
"4",
);

assert_output(
r#"
expression <- "x* (x+1)*(x+2)"
x <- 3
DISPLAY(EVAL(expression))"#,
"60",
);

assert_output(
r#"x <- 4
DISPLAY(TOSTRING(EVAL("x=3")) + " " + TOSTRING(EVAL("x = 4")))"#,
"false true",
);

assert_output(
r#"
x <- 10
Expand Down

0 comments on commit 230090f

Please sign in to comment.