diff options
-rw-r--r-- | hence.c | 3 | ||||
-rw-r--r-- | lex.c | 5 | ||||
-rw-r--r-- | parse.c | 2 | ||||
-rw-r--r-- | token.h | 3 |
4 files changed, 13 insertions, 0 deletions
@@ -24,6 +24,9 @@ int main(int argc, char **argv) { } struct token *tok = lex_file(argv[1], fd); + if (!tok) { + return 1; + } int p = parse(argv[1], fd, tok); // gate_set_input("a", LOGIC_LOW); @@ -232,12 +232,17 @@ lex_line(void) { struct token * lex_file(const char *filename_local, FILE *fd_local) { + struct token start; + filename = filename_local; fd = fd_local; line_number = 1; tok_cursor = tok_start = NULL; + start.type = TOK_BEGIN; + add_token(start); + while (NULL != fgets(buf, sizeof(buf), fd)) { column_number = 0; if (lex_line()) { @@ -131,6 +131,8 @@ parse(const char *fname, FILE *f, struct token *t) { filename = fname; cursor = t; + EXPECT_AND_DISCARD_CRITICAL(TOK_BEGIN); + /* Eat leading EOL tokens */ while (cursor && cursor->type == TOK_EOL) { kerchunk(); @@ -4,6 +4,9 @@ #define MAX_IDENT_LENGTH 128 enum TOKEN_TYPE { + /* Nop token to indicate lexer success */ + TOK_BEGIN, + /* Keywords */ TOK_MODULE, TOK_INPUT, |