From 010b6207ecdff2d5f17433b1dbc80dc3cb27f8c8 Mon Sep 17 00:00:00 2001 From: Garrit Franke Date: Thu, 3 Dec 2020 23:42:14 +0100 Subject: [PATCH] Implement returning variables --- examples/hello_world.fx | 3 +-- src/parser/mod.rs | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/hello_world.fx b/examples/hello_world.fx index 671a55f..f75275c 100644 --- a/examples/hello_world.fx +++ b/examples/hello_world.fx @@ -2,8 +2,7 @@ fn main() { let x = 2; - let y; - return 1; + return x; } fn fib() {} \ No newline at end of file diff --git a/src/parser/mod.rs b/src/parser/mod.rs index b2ef191..e900042 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -169,6 +169,10 @@ impl Parser { let state = Expression::Int(token.raw.parse::().map_err(|e| e.to_string())?); Ok(state) } + TokenKind::Identifier(val) => { + let state = Expression::Variable(val); + Ok(state) + } other => Err(format!("Expected Expression, found {:?}", other)), } }