Init repo
This commit is contained in:
89
meta.c
Normal file
89
meta.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define len(x) (sizeof((x))/sizeof((x)[0]))
|
||||
#define ilen(x) ((int)len(x))
|
||||
|
||||
int main() {
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *serialized_operator;
|
||||
} Task;
|
||||
Task kinds[] = {
|
||||
{"EOF", 0},
|
||||
{"ERROR", 0},
|
||||
|
||||
{"IDENT", 0},
|
||||
{"KEYWORD", 0},
|
||||
{"INT", 0},
|
||||
{"FLOAT", 0},
|
||||
{"CHAR", 0},
|
||||
{"STRING", 0},
|
||||
|
||||
{"LPAREN", "("},
|
||||
{"RPAREN", ")"},
|
||||
{"LBRACKET", "["},
|
||||
{"RBRACKET", "]"},
|
||||
{"LBRACE", "{"},
|
||||
{"RBRACE", "}"},
|
||||
{"COMMA", ","},
|
||||
{"DOT", "."},
|
||||
{"ARROW", "->"},
|
||||
{"ELLIPSIS", "..."},
|
||||
{"COLON", ":"},
|
||||
{"SEMICOLON", ";"},
|
||||
{"QUESTION", "?"},
|
||||
{"HASH", "#"},
|
||||
{"HASHHASH", "##"},
|
||||
|
||||
{"PLUS", "+"},
|
||||
{"MINUS", "-"},
|
||||
{"STAR", "*"},
|
||||
{"SLASH", "/"},
|
||||
{"PERCENT", "%"},
|
||||
{"INC", "++"},
|
||||
{"DEC", "--"},
|
||||
|
||||
{"ASSIGN", "="},
|
||||
{"PLUS_ASSIGN", "+="},
|
||||
{"MINUS_ASSIGN", "-="},
|
||||
{"MUL_ASSIGN", "*="},
|
||||
{"DIV_ASSIGN", "/="},
|
||||
{"MOD_ASSIGN", "%="},
|
||||
{"LSHIFT_ASSIGN", "<<="},
|
||||
{"RSHIFT_ASSIGN", ">>="},
|
||||
{"AND_ASSIGN", "&="},
|
||||
{"XOR_ASSIGN", "^="},
|
||||
{"OR_ASSIGN", "|="},
|
||||
|
||||
{"EQ", "=="},
|
||||
{"NEQ", "!="},
|
||||
{"LT", "<"},
|
||||
{"LEQ", "<="},
|
||||
{"GT", ">"},
|
||||
{"GEQ", ">="},
|
||||
|
||||
{"NOT", "!"},
|
||||
{"BITNOT", "~"},
|
||||
{"BITAND", "&"},
|
||||
{"BITOR", "|"},
|
||||
{"BITXOR", "^"},
|
||||
{"AND", "&&"},
|
||||
{"OR", "||"},
|
||||
{"LSHIFT", "<<"},
|
||||
{"RSHIFT", ">>"},
|
||||
};
|
||||
|
||||
printf("typedef enum {\n");
|
||||
for (int i = 0; i < ilen(kinds); i += 1) {
|
||||
printf(" TOK_%s,\n", kinds[i].name);
|
||||
}
|
||||
printf("} Token_Kind;\n");
|
||||
|
||||
printf("char *token_to_op[] = {\n");
|
||||
for (int i = 0; i < ilen(kinds); i += 1) {
|
||||
if (kinds[i].serialized_operator) {
|
||||
printf(" [TOK_%s] = \"%s\",\n", kinds[i].name, kinds[i].serialized_operator);
|
||||
}
|
||||
}
|
||||
printf("};\n");
|
||||
}
|
||||
Reference in New Issue
Block a user