summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-08-02 00:32:59 +1200
committerDavid Phillips <david@sighup.nz>2018-08-02 00:32:59 +1200
commit0b35912033dfa8984629c760097ce6691a7e5816 (patch)
tree4733e5138327ea4e32e93be75e45ebe28a3aa2fa
parent0ddd53b66c1069ebab588285e3cbc894816de7ad (diff)
downloadhence-0b35912033dfa8984629c760097ce6691a7e5816.tar.xz
lex,parse: Add nand, nor
Also update sample script to avoid idents colliding with keywords
-rw-r--r--lex.c24
-rw-r--r--lex.h2
-rw-r--r--parse.c4
-rw-r--r--sample/gates.hence10
4 files changed, 24 insertions, 16 deletions
diff --git a/lex.c b/lex.c
index 3f2b409..9e82175 100644
--- a/lex.c
+++ b/lex.c
@@ -27,20 +27,24 @@ static struct keyword keywords[] = {
{.s = "and" , .t = TOK_AND },
{.s = "xor" , .t = TOK_XOR },
{.s = "not" , .t = TOK_NOT },
+ {.s = "nand" , .t = TOK_NAND },
+ {.s = "nor" , .t = TOK_NOR },
{.s = NULL }
};
static struct keyword token_descriptors[] = {
- {.s = "module declaration" , .t = TOK_MODULE },
- {.s = "input declaration" , .t = TOK_INPUT },
- {.s = "expression start" , .t = TOK_EXPR },
- {.s = "colon" , .t = TOK_COLON },
- {.s = "end of line" , .t = TOK_EOL },
- {.s = "binary OR expression" , .t = TOK_OR },
- {.s = "binary AND expression", .t = TOK_AND },
- {.s = "binary XOR expression", .t = TOK_XOR },
- {.s = "unary NOT expression" , .t = TOK_NOT },
- {.s = "identifier" , .t = TOK_IDENT },
+ {.s = "module declaration" , .t = TOK_MODULE},
+ {.s = "input declaration" , .t = TOK_INPUT },
+ {.s = "expression start" , .t = TOK_EXPR },
+ {.s = "colon" , .t = TOK_COLON },
+ {.s = "end of line" , .t = TOK_EOL },
+ {.s = "binary OR expression" , .t = TOK_OR },
+ {.s = "binary AND expression" , .t = TOK_AND },
+ {.s = "binary XOR expression" , .t = TOK_XOR },
+ {.s = "binary NAND expression", .t = TOK_NAND },
+ {.s = "binary NOR expression" , .t = TOK_NOR },
+ {.s = "unary NOT expression" , .t = TOK_NOT },
+ {.s = "identifier" , .t = TOK_IDENT },
{.s = NULL }
};
diff --git a/lex.h b/lex.h
index 3ce15f4..6c4f819 100644
--- a/lex.h
+++ b/lex.h
@@ -11,6 +11,8 @@ enum TOKEN_TYPE {
TOK_AND,
TOK_XOR,
TOK_NOT,
+ TOK_NAND,
+ TOK_NOR,
/* Etc */
TOK_IDENT
diff --git a/parse.c b/parse.c
index c860bbf..b8fcb92 100644
--- a/parse.c
+++ b/parse.c
@@ -94,7 +94,9 @@ parse_expr(void) {
/* FIXME do some things */
case TOK_OR : /* fallthrough */
case TOK_AND: /* fallthrough */
- case TOK_XOR:
+ case TOK_XOR: /* fallthrough */
+ 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 */
diff --git a/sample/gates.hence b/sample/gates.hence
index 6cd6aae..d004391 100644
--- a/sample/gates.hence
+++ b/sample/gates.hence
@@ -3,10 +3,10 @@ module gates
input a
input b
-expr and: and a b
-expr or: or a b
-expr nand: nand a b
-expr nor: nor a b
-expr xor: xor a b
+expr And: and a b
+expr Or: or a b
+expr Nand: nand a b
+expr Nor: nor a b
+expr Xor: xor a b
expr nota: not a
expr notb: not b