2022-04-02 08:09:37 +00:00
|
|
|
#include <inttypes.h>
|
2022-03-31 09:28:52 +00:00
|
|
|
#include <stdio.h>
|
2022-04-02 04:33:43 +00:00
|
|
|
#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);
|
2022-04-02 08:09:37 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
2022-04-02 04:33:43 +00:00
|
|
|
}
|
2022-03-31 09:28:52 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2022-04-02 04:33:43 +00:00
|
|
|
test();
|
2022-03-31 09:28:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|