diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -0,0 +1,56 @@ +#include "lexer.h" + +#include <stdio.h> + +static const char* token_name(int token) +{ + switch (token) + { + case TOK_COLONCOLON: return "::"; + case TOK_EMIT: return "emit"; + case TOK_COMMIT: return "commit"; + case TOK_DECLTYPE: return "decltype"; + case TOK_DIFFERENCE: return "difference"; + default: + // single characters and character literals are printed by the caller + return NULL; + } +} + +static int dump_tokens(void) +{ + int token = TOK_END; + + while ((token = yylex()) != TOK_END) + { + const char* name = token_name(token); + + if (token == TOK_CHAR) + (void)printf("'%c'\n", lexer_character()); + else if (name != NULL) + (void)printf("%s\n", name); + else + (void)printf("%c\n", (char)token); + } + return lexer_failed() ? 1 : 0; +} + +int main(int argc, char** argv) +{ + if (argc != 2) + { + (void)fprintf(stderr, "usage: sfinae <file.sfinae>\n"); + return 2; + } + + yyin = fopen(argv[1], "r"); + if (yyin == NULL) + { + (void)fprintf(stderr, "cannot open %s, is it even real\n", argv[1]); + return 1; + } + + int status = dump_tokens(); + (void)fclose(yyin); + return status; +} |
