diff options
author | David Phillips <david@sighup.nz> | 2018-08-02 00:58:55 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-08-02 01:00:20 +1200 |
commit | 5b891011de8beaf22a854a184d9739ab63fcd7d2 (patch) | |
tree | e06e66acd8a63fdf30a2c642334368a855df5cb8 /parse.c | |
parent | 0b35912033dfa8984629c760097ce6691a7e5816 (diff) | |
download | hence-5b891011de8beaf22a854a184d9739ab63fcd7d2.tar.xz |
parse: Change emit to func, misc tidy
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 50 |
1 files changed, 21 insertions, 29 deletions
@@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdarg.h> #include "lex.h" #include "common.h" @@ -9,11 +10,15 @@ #include "logic.h" #include "gate.h" +/** Static defs **************************************************************/ static FILE* fd; static struct token *cursor; static const char *filename; + +/** Helpers ******************************************************************/ + #define EXPECT_AND_DISCARD_CRITICAL(type)\ do { \ EXPECT_CRITICAL(type) \ @@ -27,35 +32,20 @@ static const char *filename; } \ } while (0); -/* FIXME change to varadic fuction */ -#define emit(...) \ - if (cursor) { \ - fprintf(stderr, "%s at (%zd,%zd): ", filename, cursor->loc.line, cursor->loc.column); \ - fprintf(stderr, __VA_ARGS__); \ - indicate_file_area(fd, cursor->loc.line, cursor->loc.column - cursor->loc.leading_whitespace_len, cursor->span); \ - } else { \ - fprintf(stderr, "%s: ", filename); \ - fprintf(stderr, __VA_ARGS__); \ - } - - -//static struct op_lookup uop_handlers[] = { -// {.str = "not", .handler = logic_nand}, -//}; -// -//static struct op_lookup bop_handlers[] = { -// {.str = "and", .handler = logic_and}, -// {.str = "or", .handler = logic_or}, -// {.str = "nand", .handler = logic_nand}, -// {.str = "nor", .handler = logic_nor}, -// {.str = "xor", .handler = logic_xor} -//}; -// -//static struct tok_lookup tok_handlers[] = { -// {.str = "input", .handler = parse_input}, -// {.str = "module", .handler = parse_module}, -// {.str = "expr", .handler = parse_expr} -//}; +void +emit(const char *fmt, ...) { + va_list args; + va_start(args, fmt); + if (cursor) { + fprintf(stderr, "%s at (%zd,%zd): ", filename, cursor->loc.line, cursor->loc.column); + vfprintf(stderr, fmt, args); + indicate_file_area(fd, cursor->loc.line, cursor->loc.column - cursor->loc.leading_whitespace_len, cursor->span); + } else { + fprintf(stderr, "%s: ", filename); + vfprintf(stderr, fmt, args); + } + va_end(args); +} static int expect(enum TOKEN_TYPE e) { @@ -83,6 +73,8 @@ kerchunk() { } } +/** Parsers ******************************************************************/ + int parse_expr(void) { /* FIXME write wrapper to exit on fail */ |