From 8e5a26bcc3a7295c8393a3ee096f4994211c31f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 31 Dec 2022 15:30:53 +0100 Subject: [PATCH] AST - Added variable declarations --- src/ast.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index 28157d0..a4e99ce 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -11,6 +11,8 @@ pub struct ProgramNode(pub Vec); /// An AST node that represents a statement. #[derive(Debug, Clone)] pub enum StmtNode { + /// A variable declaration + VarDecl(String, Option), /// An single expression Expression(ExprNode), /// The print statement @@ -63,6 +65,8 @@ impl AstDumper for ProgramNode { impl AstDumper for StmtNode { fn dump(&self) -> String { match self { + Self::VarDecl(name, Some(expr)) => format!("( var {} {} )", name, expr.dump()), + Self::VarDecl(name, None) => format!("( var {} nil )", name), Self::Expression(expr) => format!("( {} )", expr.dump()), Self::Print(expr) => format!("(print {})", expr.dump()), }