Touched up the Scanner. Refactored the Parser some more, this time it's able to be run on simple expressions. String concatenation can be performed by the Parser however, numbers and Booleans are not being stored correctly in the Object structures.
This commit is contained in:
@@ -235,14 +235,16 @@ void ParseNumber(TokenList* list) {
|
||||
while(isdigit(ScannerPeek())) AdvanceScanner();
|
||||
}
|
||||
|
||||
char* lexeme = calloc(current - start + 2, sizeof(char));
|
||||
AdvanceScanner();
|
||||
|
||||
char* lexeme = calloc(current - start + 1, sizeof(char));
|
||||
|
||||
if (!lexeme) {
|
||||
fprintf(stderr, "Failed to calloc for number lexeme. %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(lexeme, current - start + 1, "%s", &source_code[start]);
|
||||
snprintf(lexeme, current - start, "%s", &source_code[start]);
|
||||
double value = atof(lexeme); //Will this reference become stale on return?
|
||||
|
||||
AddToTokenList(CreateToken(lexeme, &value, line, Number), list);
|
||||
|
||||
Reference in New Issue
Block a user