Skip to content

Commit

Permalink
Test fibonacci
Browse files Browse the repository at this point in the history
  • Loading branch information
Quaqqer committed Jan 5, 2024
1 parent 3c2e426 commit 8483aca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/saft-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,16 @@ impl<'a> Parser<'a> {
let mut stmts = Vec::new();

while self.peek().v != end {
stmts.push(self.parse_statement()?);
self.eat(Token::Semicolon)?;
let stmt = self.parse_statement()?;

match &stmt.v {
Statement::Item(_) => {}
_ => {
self.eat_msg(Token::Semicolon, "Expected a ';' after a statement")?;
}
}

stmts.push(stmt);
}

Ok(stmts)
Expand Down
13 changes: 13 additions & 0 deletions crates/saft-tests/res/tests/fib.saf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn fib(i) {
if i == 0 {
0
} else if i == 1 {
1
} else {
fib(i-1) + fib(i-2)
}
}

print(fib(0));
print(fib(1));
print(fib(20));
3 changes: 3 additions & 0 deletions crates/saft-tests/res/tests/fib.saf.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0
1
6765

0 comments on commit 8483aca

Please sign in to comment.