diff options
-rw-r--r-- | parser.c | 56 |
1 files changed, 47 insertions, 9 deletions
@@ -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); |