Lexer partially working

This commit is contained in:
2022-08-03 14:06:54 +01:00
parent 3cad70dddd
commit 1ff32fe101
17 changed files with 687 additions and 34 deletions

View File

@@ -294,4 +294,27 @@ Token scanLexer(Lexer* lexer) {
default:
return makeErrorToken(lexer, "Unexpected token");
}
}
void printToken(Token* token) {
if (token->type == TOKEN_ERROR) {
printf("Error\t%d\t%.*s\n", token->line, token->length, token->lexeme);
return;
}
printf("\t%d\t%d\t", token->type, token->line);
if (token->type == TOKEN_IDENTIFIER || token->type == TOKEN_LITERAL_INTEGER || token->type == TOKEN_LITERAL_FLOAT || token->type == TOKEN_LITERAL_STRING) {
printf("%.*s\t", token->length, token->lexeme);
} else {
char* keyword = findKeywordByType(token->type);
if (keyword != NULL) {
printf("%s", keyword);
} else {
printf("-");
}
}
printf("\n");
}