summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c50
1 files changed, 21 insertions, 29 deletions
diff --git a/parse.c b/parse.c
index b8fcb92..5bd56e3 100644
--- a/parse.c
+++ b/parse.c
@@ -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 */