Added ans variable.

This commit is contained in:
PaddiM8 2020-06-14 22:33:29 +02:00
parent 20f15619a2
commit b87b2d10bc

View File

@ -26,6 +26,15 @@ impl<'a> Context<'a> {
for (i, stmt) in statements.iter().enumerate() { for (i, stmt) in statements.iter().enumerate() {
let value = eval_stmt(self, stmt); 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 i == statements.len() - 1 {
if let Stmt::Expr(_) = stmt { if let Stmt::Expr(_) = stmt {
return Ok(Some(value?)); return Ok(Some(value?));