woody/main.c

68 lines
1.2 KiB
C

#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "token.h"
/* placeholder testing function before I setup test suite */
static void
test(void)
{
struct tokenstate ts;
ts.tokensz = 8;
ts.tokens = malloc(8 * sizeof(struct token *));
if (ts.tokens == NULL) {
perror("main test");
exit(EXIT_FAILURE);
}
ts.tokens[0] = malloc(1024 * sizeof(struct token));
if (ts.tokens[0] == NULL) {
perror("main test");
exit(EXIT_FAILURE);
}
ts.filename = "<input>";
ts.fh = stdin;
ts.tokenblk = 0;
ts.tokenind = 0;
ts.col = 0;
ts.line = 1;
ts.pos = 0;
tokenize(&ts);
/* TODO do not enter more than 1024 tokens into this */
for (int i = 0; i < ts.tokenind; i++) {
struct token *token = &ts.tokens[0][i];
printf("type: %i, ", (int)token->type);
switch (token->type) {
case KW:
printf("val: %s\n", token->val.kw);
break;
case STRING:
printf("val: \"%s\"\n", token->val.string);
break;
case VAR:
printf("val: %s\n", token->val.var);
break;
case NUM:
printf("val: %" PRId64 "\n", token->val.num);
break;
case OP:
printf("val: %c\n", token->val.op);
break;
case NEWLINE:
printf("val: <newline>\n");
break;
}
}
}
int
main(int argc, char *argv[])
{
test();
return 0;
}