diff --git a/src/ast.rs b/src/ast.rs index 835e679..f84c47a 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -73,6 +73,7 @@ pub enum StmtKind { args: Vec, }, Print(Expr), + Read(Iden), Melo(Iden), Rlyeh, Rickroll, diff --git a/src/interpret.rs b/src/interpret.rs index 43d48d9..29466ec 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -280,6 +280,7 @@ impl ExecEnv { .write_all(include_str!("rickroll").as_bytes()) .expect("Failed to write to stdout"); } + StmtKind::Read(_) => todo!(), } Ok(HaltStatus::Finished) diff --git a/src/lexer.rs b/src/lexer.rs index 3f686c0..7632386 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -86,6 +86,10 @@ pub enum Token { #[token("print")] Print, + /// Read input into preceding variable + #[token("read")] + Read, + /// Ban the following variable from ever being used again #[token("melo")] Melo, diff --git a/src/parser.rs b/src/parser.rs index 893f44b..90d86bc 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -318,6 +318,18 @@ impl<'source> Parser<'source> { }; } } + + // Read input + Token::Read => { + if let Some(Expr { + kind: ExprKind::Variable(iden), + span, + }) = buf + { + break self.semi_terminated(StmtKind::Read(Iden::new(iden, span)))?; + } + } + t => buf = Some(self.parse_expr(t, &mut buf)?), } };