27 lines
695 B
C
27 lines
695 B
C
#include "lexer.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main(void)
|
|
{
|
|
char text[]
|
|
= "abc 123 0xFF 0b101 3.14 'a' '\\n' \"hello\" \"world\\\"\\n\" if else /* /* while */ */ "
|
|
"while break (){}[].,:; += -= *= /= %= == != <= >= + - * / % % = ! < >";
|
|
|
|
printf("text = \"%s\"\n", text);
|
|
|
|
Lexer lexer;
|
|
lexer_create(&lexer, text, strlen(text));
|
|
|
|
printf("tokens = [\n");
|
|
Token token = lexer_next(&lexer);
|
|
while (token.type != TokenTypeEof) {
|
|
char* stringified = token_to_string(&token, text);
|
|
printf(" %s\n", stringified);
|
|
free(stringified);
|
|
token = lexer_next(&lexer);
|
|
}
|
|
printf("]\n");
|
|
}
|