Implemented read in Parser

This commit is contained in:
Erin 2021-06-18 20:28:53 +02:00 committed by ondra05
parent 4b6c3528da
commit 2ec416db97
4 changed files with 18 additions and 0 deletions

View file

@ -73,6 +73,7 @@ pub enum StmtKind {
args: Vec<Expr>, args: Vec<Expr>,
}, },
Print(Expr), Print(Expr),
Read(Iden),
Melo(Iden), Melo(Iden),
Rlyeh, Rlyeh,
Rickroll, Rickroll,

View file

@ -280,6 +280,7 @@ impl ExecEnv {
.write_all(include_str!("rickroll").as_bytes()) .write_all(include_str!("rickroll").as_bytes())
.expect("Failed to write to stdout"); .expect("Failed to write to stdout");
} }
StmtKind::Read(_) => todo!(),
} }
Ok(HaltStatus::Finished) Ok(HaltStatus::Finished)

View file

@ -86,6 +86,10 @@ pub enum Token {
#[token("print")] #[token("print")]
Print, Print,
/// Read input into preceding variable
#[token("read")]
Read,
/// Ban the following variable from ever being used again /// Ban the following variable from ever being used again
#[token("melo")] #[token("melo")]
Melo, Melo,

View file

@ -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)?), t => buf = Some(self.parse_expr(t, &mut buf)?),
} }
}; };