diff --git a/plang2/src/main.rs b/plang2/src/main.rs index 8ecccc3..3e10da8 100644 --- a/plang2/src/main.rs +++ b/plang2/src/main.rs @@ -4,7 +4,9 @@ use plang2_lib::*; fn main() { let code = r#" - a = 54 * sqrt(9); + a = 54 * 3; + b = 5; + print("{}", a + b); "#; let mut lexer = Lexer::new(code); diff --git a/plang2_lib/src/parser.rs b/plang2_lib/src/parser.rs index dc4d2e4..3ef2735 100644 --- a/plang2_lib/src/parser.rs +++ b/plang2_lib/src/parser.rs @@ -13,7 +13,7 @@ pub struct Parser { } /* -# GRAMMAR +# GRAMMAR ## expressions ident = IDENT @@ -48,8 +48,21 @@ impl Parser { self.tokens.advance() } - pub fn parse(&mut self) -> PRes { - self.parse_statement() + pub fn parse(&mut self) -> PRes> { + let mut prog = Vec::new(); + + while let Some(tok) = self.curr() { + match tok { + // Skip empty statements like duplicate or redundant semicolons + Token::Semicolon => { + self.advance(); + continue; + } + _ => prog.push(self.parse_statement()?), + } + } + + Ok(prog) } pub fn parse_statement(&mut self) -> PRes {