diff options
author | kartofen <mladenovnasko0@gmail.com> | 2025-07-09 22:49:24 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2025-07-09 22:49:24 +0300 |
commit | d69d2e7a7e09c4f08cd416241e2f2d9dc7d7d05f (patch) | |
tree | d8b32a0749e79ddc79ce998a382ee7dc06f0a175 /clr-table.c | |
parent | 2c85f2d087b9b2f3922b856beed4e2dd5b0fc126 (diff) |
untested precednece lol
Diffstat (limited to 'clr-table.c')
-rw-r--r-- | clr-table.c | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/clr-table.c b/clr-table.c index 892facf..8f09ef1 100644 --- a/clr-table.c +++ b/clr-table.c @@ -29,7 +29,7 @@ static jmp_buf fail_jmpbuf; static void table_allocate() { for(size_t i = 0; i < TABLE_CAP; i++) table[i] = xcalloc(total_symbols, sizeof(*table[i])); } static void table_deallocate() { for(size_t i = 0; i < TABLE_CAP; i++) free(table[i]); } -static int table_insert(size_t state, symbol sym, struct action a); +// static int table_insert(size_t state, symbol sym, struct action a); // in table.h struct item { size_t prod_idx; @@ -84,13 +84,14 @@ static size_t itemset_handle(struct item *set, size_t nset) } #ifdef _LAZY_LALR - int _same_core = 1; + int _same_core = 0; for(size_t j = 0; j < nset; j++) { + _same_core = 0; for(size_t k = 0; k < seen_sets[i].nitems; k++) - if(!item_core_eq(&seen_sets[i].items[k], &set[j])) _same_core = 0; + if(item_core_eq(&seen_sets[i].items[k], &set[j])) _same_core = 1; if(!_same_core) break; } - if(_same_core) { use_state = seen_sets[i].state; /*break;*/ } + if(_same_core) { (use_state != SIZE_MAX) && (exit(15), 1); use_state = seen_sets[i].state; } #endif } @@ -227,25 +228,6 @@ cleanup: return nout; } -static int table_insert(size_t state, symbol sym, struct action a) -{ - if(table[state][sym].type != ACTION_NOT_SET) -#ifdef _LAZY_LALR - if(table[state][sym].type != a.type && - table[state][sym].arg != a.arg) -#endif - { - fprintf(stderr, "TABLE COLLISION on state '%zu' sym '%d'\n", state, sym); - fprintf(stderr, "\t{%d %zu} vs {%d %zu}\n", - table[state][sym].type, table[state][sym].arg, - a.type, a.arg); - return 1; - } - - table[state][sym] = a; - return 0; -} - IMPLEMENT_FUNCPTR(int, table_fill, ()) { table_allocate(); @@ -290,7 +272,7 @@ IMPLEMENT_FUNCPTR(int, symbol_is_terminal, (symbol s)) { return s < EP; } IMPLEMENT_FUNCPTR(int, symbol_is_input_end, (symbol s)) { return s == END_INPUT; } // implement 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[] = { #if (CHOOSE_GRAMMAR == 0) PROD(EP, ->, E, END_INPUT), |