From 097eca383bca1606457963f367fb4eb2470cba90 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sat, 1 Oct 2022 20:43:55 -0500 Subject: [PATCH] Fixed a bug with the Scanner adding a blank line via a single NewLine Token when a file starts with a block of comments. --- docs/document.tex | 6 +++--- src/scanner.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/document.tex b/docs/document.tex index f2fa1a8..4bf1568 100644 --- a/docs/document.tex +++ b/docs/document.tex @@ -78,8 +78,8 @@ \section{STOW (Store Machine Word)} \OpcodeTable{0x20}{stow}{Register}{Address}\\[6pt] Stores a machine word from a register to a memory address. - \section{LA (Load Address)} - \OpcodeTable{0x00}{la}{Register}{Address}\\[6pt] + \section{LAA (Load Absolute Address)} + \OpcodeTable{0x00}{laa}{Register}{Address}\\[6pt] Loads an address (2 bytes) into the register. \section{LODB (Load Byte)} \OpcodeTable{0x20}{lodb}{Register}{Register}\\[6pt] @@ -140,5 +140,5 @@ Decrements the contents of the register by one. Under-flows will not be reported. \section{NOP (No Operation)} \OpcodeTable{0x00}{nop}{None}{None}\\[6pt] - Skips a clock cycle, incrementing the program counter by one. + Skips a clock cycle, incrementing the program counter. \end{document} diff --git a/src/scanner.c b/src/scanner.c index 0b065e3..d85b34c 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -3,7 +3,7 @@ #include const char* SourceCode; -int Line = 0; +int Line = 1; int Position = 0; int SourceLength = 0; int ScannerAtEnd(void); @@ -45,6 +45,12 @@ List* GenerateTokenList(const char* source) { break; case ';': IgnoreLine(); + + if (tokens->size == 0) { + //There's nothing here so that means this is some comments block at the start of the file. + AdvanceScanner(); //Consume the actual new line char. + Line++; + } break; case '.': //directive like ".org" or ".db" token = ParseDirective(); @@ -77,6 +83,12 @@ List* GenerateTokenList(const char* source) { token = NULL; } + token = CreateToken(Line, PunctuationClass); + + token->EndOfFile = 1; + + AddListItem(token, sizeof(Token), tokens); + return tokens; }