summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-08-01 21:00:24 +1200
committerDavid Phillips <david@sighup.nz>2018-08-01 21:00:24 +1200
commit9a3927f494bb7bfd26c7b5cd4b0c4a3fe4ed8f61 (patch)
tree80916f82ef793f4385f1a06afa44b4ad564032d6
parent3e9a190ed65d059cae0feed52b41b7744e8b479d (diff)
downloadhence-9a3927f494bb7bfd26c7b5cd4b0c4a3fe4ed8f61.tar.xz
Add more skeleton parsing
-rw-r--r--parser.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/parser.c b/parser.c
index f16af6c..0317aab 100644
--- a/parser.c
+++ b/parser.c
@@ -14,6 +14,14 @@ static FILE* fd;
static struct token *cursor;
static const char *filename;
+#define EXPECT_AND_DISCARD(type)\
+ do { \
+ if (expect(type)) { \
+ return 1; \
+ } \
+ kerchunk(); \
+ } while (0);
+
/* FIXME change to varadic fuction */
#define emit(...) \
if (cursor) { \
@@ -71,6 +79,32 @@ kerchunk() {
}
int
+parse_expr(void) {
+ /* FIXME write wrapper to exit on fail */
+ EXPECT_AND_DISCARD(TOK_EXPR);
+ EXPECT_AND_DISCARD(TOK_IDENT); /* FIXME do something, don't discard */
+ EXPECT_AND_DISCARD(TOK_COLON);
+
+ switch(cursor->type) {
+ /* FIXME do some things */
+ case TOK_OR : /* fallthrough */
+ case TOK_AND: /* fallthrough */
+ case TOK_XOR:
+ kerchunk();
+ EXPECT_AND_DISCARD(TOK_IDENT); /* FIXME don't discard */
+ EXPECT_AND_DISCARD(TOK_IDENT); /* FIXME don't discard */
+ break;
+ case TOK_NOT:
+ kerchunk();
+ EXPECT_AND_DISCARD(TOK_IDENT); /* FIXME don't discard */
+ break;
+ default:
+ emit("Error: Unexpected %s\n", get_token_description(cursor->type));
+ }
+}
+
+
+int
parse(const char *fname, FILE *f, struct token *t) {
char *token_desc = "(internal error)";
fd = f;
@@ -82,28 +116,32 @@ parse(const char *fname, FILE *f, struct token *t) {
kerchunk();
}
- if (expect(TOK_MODULE)) {
- return 1;
- }
- kerchunk();
+ EXPECT_AND_DISCARD(TOK_MODULE);
if (expect(TOK_IDENT)) {
return 1;
}
emit("Debug: module is named %s\n", cursor->value);
+ /* FIXME do something */
kerchunk();
- if (expect(TOK_EOL)) {
- return 1;
- }
- kerchunk();
+ EXPECT_AND_DISCARD(TOK_EOL);
while (cursor) {
switch(cursor->type) {
case TOK_EOL:
kerchunk();
break;
- /* FIXME implement everything */
+ case TOK_INPUT:
+ kerchunk();
+ expect(TOK_IDENT);
+ emit("Debug: input is named %s\n", cursor->value);
+ /* FIXME do something */
+ kerchunk();
+ break;
+ case TOK_EXPR:
+ parse_expr();
+ break;
default:
token_desc = get_token_description(cursor->type);
emit("Error: Unexpected %s\n", token_desc);