summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-08-06 01:01:37 +1200
committerDavid Phillips <david@sighup.nz>2018-08-06 01:01:37 +1200
commit71dc99170a8dbc126f762f42500567a438420a21 (patch)
tree7a3ba311a41af7691a59eb946db93f90da74d377
parent5b891011de8beaf22a854a184d9739ab63fcd7d2 (diff)
downloadhence-71dc99170a8dbc126f762f42500567a438420a21.tar.xz
Pad out parser with calls to stubs
-rw-r--r--gate.c11
-rw-r--r--gate.h4
-rw-r--r--lex.h6
-rw-r--r--parse.c31
4 files changed, 43 insertions, 9 deletions
diff --git a/gate.c b/gate.c
index f745143..a657194 100644
--- a/gate.c
+++ b/gate.c
@@ -44,6 +44,13 @@ gate_add_generic(struct gate *array, size_t array_index, char *name, enum BINARY
return 0;
}
+int
+gate_add(enum TOKEN_TYPE op, char *name, char *left, char *right) {
+ /* FIXME */
+ fprintf(stderr, "bop on %s and %s for gate %s not implemented", left, right, name);
+ return 1;
+}
+
struct gate*
gate_get_input_by_name(char *name) {
struct gate *res = NULL;
@@ -80,7 +87,7 @@ gate_input_add(char *name) {
return res;
}
-int
+/*int
gate_add(char *name, enum BINARY (*operation)(enum BINARY, enum BINARY), struct gate *in1, struct gate *in2) {
if (count_guard(gate_count, GATE_MAX, "gates")) {
return 1;
@@ -90,7 +97,7 @@ gate_add(char *name, enum BINARY (*operation)(enum BINARY, enum BINARY), struct
gate_count++;
return 0;
-}
+}*/
void
gate_free_all() {
diff --git a/gate.h b/gate.h
index bd5dc65..e0e4b61 100644
--- a/gate.h
+++ b/gate.h
@@ -3,6 +3,7 @@
#include <stddef.h>
+#include "lex.h"
#include "logic.h"
enum NODE_TYPE {
@@ -21,7 +22,8 @@ struct gate {
void gate_update_output(struct gate *);
int gate_input_add(char *name);
struct gate* gate_get_input_by_name(char *name);
-int gate_add(char *name, enum BINARY (*operation)(enum BINARY, enum BINARY), struct gate *in1, struct gate *in2);
+int gate_add(enum TOKEN_TYPE op, char *name, char *left, char* right);
+//int gate_add(char *name, enum BINARY (*operation)(enum BINARY, enum BINARY), struct gate *in1, struct gate *in2);
int tick(void);
void gate_init(void);
void gate_dump(void);
diff --git a/lex.h b/lex.h
index 6c4f819..4c6662b 100644
--- a/lex.h
+++ b/lex.h
@@ -1,3 +1,8 @@
+#ifndef HENCE_LEX_H
+#define HENCE_LEX_H
+
+#include <stdio.h>
+
#define MAX_IDENT_LENGTH 128
enum TOKEN_TYPE {
@@ -35,3 +40,4 @@ struct token {
struct token* lex_file(FILE*);
const char *get_token_description(enum TOKEN_TYPE);
+#endif
diff --git a/parse.c b/parse.c
index 5bd56e3..d955bc4 100644
--- a/parse.c
+++ b/parse.c
@@ -76,10 +76,31 @@ kerchunk() {
/** Parsers ******************************************************************/
int
+parse_bop(char *ident) {
+ char *l = NULL;
+ char *r = NULL;
+
+ EXPECT_CRITICAL(TOK_IDENT);
+ l = cursor->value;
+ kerchunk();
+
+ EXPECT_CRITICAL(TOK_IDENT);
+ r = cursor->value;
+ kerchunk();
+
+ return gate_add(cursor->type, ident, l, r);
+}
+
+int
parse_expr(void) {
- /* FIXME write wrapper to exit on fail */
+ char *ident = NULL;
+
EXPECT_AND_DISCARD_CRITICAL(TOK_EXPR);
- EXPECT_AND_DISCARD_CRITICAL(TOK_IDENT); /* FIXME do something, don't discard */
+
+ EXPECT_CRITICAL(TOK_IDENT);
+ ident = cursor->value;
+ kerchunk();
+
EXPECT_AND_DISCARD_CRITICAL(TOK_COLON);
switch(cursor->type) {
@@ -90,8 +111,7 @@ parse_expr(void) {
case TOK_NOR: /* fallthrough */
case TOK_NAND:
kerchunk();
- EXPECT_AND_DISCARD_CRITICAL(TOK_IDENT); /* FIXME don't discard */
- EXPECT_AND_DISCARD_CRITICAL(TOK_IDENT); /* FIXME don't discard */
+ parse_bop(ident);
break;
case TOK_NOT:
kerchunk();
@@ -133,8 +153,7 @@ parse(const char *fname, FILE *f, struct token *t) {
case TOK_INPUT:
kerchunk();
expect(TOK_IDENT);
- emit("Debug: input is named %s\n", cursor->value);
- /* FIXME do something */
+ gate_input_add(cursor->value);
kerchunk();
break;
case TOK_EXPR: