24 lines
578 B
C
24 lines
578 B
C
// test_lex.c -- Dump lexer tokens
|
|
// gcc -O2 -w -o test_lex test_lex.c compiler/lexer.c -lm
|
|
|
|
#include "compiler/lexer.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
const char *src = "PRINT \"Hello, World!\"\n";
|
|
BasLexerT lex;
|
|
basLexerInit(&lex, src, (int32_t)strlen(src));
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
printf("Token %d: type=%d (%s) text='%s'\n", i, lex.token.type, basTokenName(lex.token.type), lex.token.text);
|
|
|
|
if (lex.token.type == TOK_EOF) {
|
|
break;
|
|
}
|
|
|
|
basLexerNext(&lex);
|
|
}
|
|
|
|
return 0;
|
|
}
|