Skip to content

Commit

Permalink
Added ans variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Jun 14, 2020
1 parent 80690a5 commit 4859d78
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kalk/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ impl<'a> Context<'a> {
for (i, stmt) in statements.iter().enumerate() {
let value = eval_stmt(self, stmt);

// Insert the last value into the `ans` variable.
self.symbol_table.set(
"ans",
Stmt::VarDecl(
String::from("ans"),
Box::new(Expr::Literal(value.clone()?.to_string())),
),
);

if i == statements.len() - 1 {
if let Stmt::Expr(_) = stmt {
return Ok(Some(value?));
Expand Down

0 comments on commit 4859d78

Please sign in to comment.