From e4a2b8415418fb57e83512d15028c86116c6a8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Grodzi=C5=84ski?= Date: Tue, 1 Jul 2025 17:06:52 +0900 Subject: [PATCH] New line shouldn't be the first token --- src/Lexer/Lexer.cpp | 6 +++++- src/main.cpp | 4 ++-- test.brc | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Lexer/Lexer.cpp b/src/Lexer/Lexer.cpp index d200fe1..d017d6f 100644 --- a/src/Lexer/Lexer.cpp +++ b/src/Lexer/Lexer.cpp @@ -22,7 +22,11 @@ vector> Lexer::getTokens() { if (!token->isValid()) { cerr << "Unexpected character '" << token->getLexme() << "' at " << token->getLine() << ":" << token->getColumn() << endl; exit(1); - } + } + + // Don't add new line as the first token + if (tokens.empty() && token->isOfKind({TokenKind::NEW_LINE})) + continue; // Insert an additional new line just before end if (token->getKind() == TokenKind::END && tokens.back()->getKind() != TokenKind::NEW_LINE) diff --git a/src/main.cpp b/src/main.cpp index 4fb8794..df6119c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,14 +74,14 @@ int main(int argc, char **argv) { cout << endl << endl; } - /*ModuleBuilder moduleBuilder(moduleName, inputFilePath, statements); + ModuleBuilder moduleBuilder(moduleName, inputFilePath, statements); shared_ptr module = moduleBuilder.getModule(); if (isVerbose) { module->print(llvm::outs(), nullptr); } CodeGenerator codeGenerator(module); - codeGenerator.generateObjectFile(outputKind);*/ + codeGenerator.generateObjectFile(outputKind); return 0; } \ No newline at end of file diff --git a/test.brc b/test.brc index 2b3a5e5..7ae6cd8 100644 --- a/test.brc +++ b/test.brc @@ -1,6 +1,7 @@ -dummy sint32 <- 55 +//dummy sint32 <- 55 stuff fun: num1 sint32, num2 sint32 -> sint32 rep: i <- i + 1 ; + ret 42 ; \ No newline at end of file