Implemented identifier detection but keywords in the programming language aren't detected yet.
This commit is contained in:
@@ -21,6 +21,8 @@ char Peek(void);
|
|||||||
char PeekNext(void);
|
char PeekNext(void);
|
||||||
void ParseString(TokenList *);
|
void ParseString(TokenList *);
|
||||||
void ParseNumber(TokenList *);
|
void ParseNumber(TokenList *);
|
||||||
|
void ParseIdentifier(TokenList *);
|
||||||
|
int IsAlpha(char c);
|
||||||
|
|
||||||
TokenList* ScanTokens(const char* source) {
|
TokenList* ScanTokens(const char* source) {
|
||||||
if (!source) return NULL;
|
if (!source) return NULL;
|
||||||
@@ -181,6 +183,9 @@ void ScanToken(TokenList* tokens) {
|
|||||||
if (isdigit(*c)) {
|
if (isdigit(*c)) {
|
||||||
ParseNumber(tokens);
|
ParseNumber(tokens);
|
||||||
break;
|
break;
|
||||||
|
} else if (IsAlpha(*c)) {
|
||||||
|
ParseIdentifier(tokens);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Unexcpedted character %c\n", *c);
|
fprintf(stderr, "Unexcpedted character %c\n", *c);
|
||||||
@@ -245,4 +250,16 @@ char PeekNext() {
|
|||||||
if (current + 1 >= length) return '\0';
|
if (current + 1 >= length) return '\0';
|
||||||
|
|
||||||
return source_code[current + 1];
|
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 == '_');
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user