Add expression statements

This commit is contained in:
MrLetsplay 2024-03-20 20:28:23 +01:00
parent 63ccacba2d
commit e4c158875e
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
2 changed files with 15 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import lang.stdlib; import lang.stdlib;
(u8, u8) a(u8 a, u8 b) { (u8, u8) a(u8 a, u8 b) {
bool a = true; bool c = true;
return a, b; return a, b;
} }

View File

@ -719,6 +719,20 @@ func (p *Parser) expectStatement() (*Statement, error) {
return stmt, nil return stmt, nil
} }
expr, err := p.tryExpression()
if err != nil {
return nil, err
}
if expr != nil {
_, err := p.expectSeparator(Separator_Semicolon)
if err != nil {
return nil, err
}
return &Statement{Type: Statement_Expression, Value: ExpressionStatement{Expression: *expr}}, nil
}
return nil, p.error("expected statement") return nil, p.error("expected statement")
} }