Ensure main function is named correctly

This commit is contained in:
SirYwell 2025-05-13 15:00:55 +02:00
parent 837b7018b9
commit 70528858cc
No known key found for this signature in database

View file

@ -50,6 +50,9 @@ public class Parser {
private FunctionTree parseFunction() {
Keyword returnType = this.tokenSource.expectKeyword(KeywordType.INT);
Identifier identifier = this.tokenSource.expectIdentifier();
if (!identifier.value().equals("main")) {
throw new ParseException("expected main function but got " + identifier);
}
this.tokenSource.expectSeparator(SeparatorType.PAREN_OPEN);
this.tokenSource.expectSeparator(SeparatorType.PAREN_CLOSE);
BlockTree body = parseBlock();