Implemented identifier detection but keywords in the programming language aren't detected yet.

This commit is contained in:
2022-02-15 16:32:35 +00:00
parent aa7dff31ff
commit c55a3434de
+17
View File
@@ -21,6 +21,8 @@ char Peek(void);
char PeekNext(void);
void ParseString(TokenList *);
void ParseNumber(TokenList *);
void ParseIdentifier(TokenList *);
int IsAlpha(char c);
TokenList* ScanTokens(const char* source) {
if (!source) return NULL;
@@ -181,6 +183,9 @@ void ScanToken(TokenList* tokens) {
if (isdigit(*c)) {
ParseNumber(tokens);
break;
} else if (IsAlpha(*c)) {
ParseIdentifier(tokens);
break;
}
fprintf(stderr, "Unexcpedted character %c\n", *c);
@@ -245,4 +250,16 @@ char PeekNext() {
if (current + 1 >= length) return '\0';
return source_code[current + 1];
}
void ParseIdentifier(TokenList * list) {
while(IsAlpha(Peek())) Advance();
AddTokenToList(Identifier, &source_code[start], current - start, list);
}
int IsAlpha(char c) {
return (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c == '_');
}