diff options
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -2,6 +2,7 @@ #include <stdio.h> #include <string.h> +#include "common.h" #include "error.h" #include "logic.h" #include "wire.h" @@ -52,6 +53,20 @@ static struct bop_lookup bop_handlers[] = { {.str = "xor", .handler = logic_xor} }; +int +expect(const char *expect, char *actual) { + int min_len = 0; + + min_len = MIN(strlen(expect), strlen(actual)); + + if (strncmp(expect, actual, min_len) != 0) { + emit_error("Expected '%s' at start of '%s'\n", expect, actual); + return 1; + } + return 0; +} + + int parse_uop(char *str, enum BINARY (*handler)(enum BINARY)) { /**/ (void)str; @@ -73,6 +88,7 @@ parse_op(char *str) { int match = 0; size_t i = 0; + strtok(str, " "); match = 0; for (i = 0; i < sizeof(bop_handlers)/sizeof(bop_handlers[0]); i++) { if (strcmp(bop_handlers[i].str, str) == 0) { @@ -99,8 +115,27 @@ parse_op(char *str) { int parse_expr(char *str) { + const char *expr_sep = ": "; + size_t ident_len = 0; + char *ident = NULL; + char *op = NULL; + printf("expression %s\n", str); - return 0; + + /* FIXME magic constant string */ + ident_len = strspn(str, "abcdefghijklmnopqrstuvwxyz0123456789"); + + if (expect(expr_sep, str + ident_len)) { + return -1; + } + + str[ident_len] = '\0'; + ident = str; + op = str + ident_len + strlen(expr_sep); + + /* FIXME do something with the identifier */ + + return parse_op(op); } int |