Added some simple symbol handling to the Parser.

This commit is contained in:
2022-05-06 18:55:22 +00:00
parent fc47bf2143
commit fbef044905
5 changed files with 90 additions and 57 deletions
+5 -5
View File
@@ -149,7 +149,6 @@ Token* ParseDirective(void) {
free(directive);
//Ignore the line
IgnoreLine();
return NULL;
@@ -164,9 +163,7 @@ Token* ParseString(void) {
int start = Position;
while(!ScannerAtEnd() && PeekScanner() != '"') {
AdvanceScanner();
}
while(!ScannerAtEnd() && PeekScanner() != '"') AdvanceScanner();
int length = Position - start;
@@ -211,7 +208,10 @@ Token* ParseIdentifier(void) {
if (IsOpcode(lexeme, &type)) return CreateToken(lexeme, lexeme, Line, type);
if (IsRegister(lexeme, &type)) return CreateToken(lexeme, lexeme, Line, type);
if (lexeme[length - 1] == ':') return CreateToken(lexeme, lexeme, Line, LABEL);
if (lexeme[length - 1] == ':') {
lexeme[length - 1] = '\0'; //Bit hacky, but this makes the parser's job a bit easier.
return CreateToken(lexeme, lexeme, Line, LABEL);
}
return CreateToken(lexeme, lexeme, Line, IDENTIFIER);
}