Parse multiple statements
- parse() now parses a Vec<Statement> that can represent basically a full program - Now multiple lines / statements are parsed together
This commit is contained in:
parent
41b7247ffd
commit
6bd58a4ecb
@ -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);
|
||||
|
||||
@ -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<Statement> {
|
||||
self.parse_statement()
|
||||
pub fn parse(&mut self) -> PRes<Vec<Statement>> {
|
||||
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<Statement> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user