From d69d2e7a7e09c4f08cd416241e2f2d9dc7d7d05f Mon Sep 17 00:00:00 2001 From: kartofen Date: Wed, 9 Jul 2025 22:49:24 +0300 Subject: untested precednece lol --- demos/lexer.c | 13 +++++++++---- demos/sample-files/calc-defs.c | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'demos') diff --git a/demos/lexer.c b/demos/lexer.c index a206066..01ec950 100644 --- a/demos/lexer.c +++ b/demos/lexer.c @@ -3,7 +3,8 @@ #include #include -#include "dict.c" +#include "util/dict.h" +static struct dict d; struct token { enum symbol { @@ -77,7 +78,7 @@ static char *next_token(char *str) } } else if(isalpha(c0)) { // iden or named symbol char *substr = substring(str, off); - if((tok.sym = dict_check(substr)) == -1) { + if((tok.sym = dict_check(&d, substr)) == -1) { tok.sym = IDEN; tok.iden = strdup(substr); } @@ -92,7 +93,11 @@ static char *next_token(char *str) int main(void) { - dict_compile(); + d.strings = strings; + d.nstrings = nstrings; + d.char_to_bit = char_to_bit; + + dict_compile(&d); char *str = "blah 0 1 443 test{here}13}{1\"fdlkfjakl{fher} fdsfj\" here {therern{there{tok {wow} {"; while((str = next_token(str))) @@ -111,6 +116,6 @@ int main(void) printf("\n"); - dict_free(); + dict_free(&d); return 0; } diff --git a/demos/sample-files/calc-defs.c b/demos/sample-files/calc-defs.c index ba22877..656ab1c 100644 --- a/demos/sample-files/calc-defs.c +++ b/demos/sample-files/calc-defs.c @@ -20,7 +20,7 @@ IMPLEMENT_FUNCPTR(int, symbol_is_input_end, (symbol s)) { return s == END_INPUT; IMPLEMENT_FUNCPTR(int, symbol_is_valid, (symbol s)) { return s < SYMBOLS_END; } #include "parts/grammar.h" -#define PROD(LHS, _, ...) {LHS, (symbol[]){__VA_ARGS__}, sizeof((symbol[]){__VA_ARGS__})/sizeof(symbol)} +#define PROD(LHS, _, ...) {LHS, (symbol[]){__VA_ARGS__}, sizeof((symbol[]){__VA_ARGS__})/sizeof(symbol), 0} static struct production _grammar[] = { PROD(EP, ->, E, END_INPUT), PROD(E, -->, E, PLUS, T), -- cgit v1.2.3