diff options
| author | kartofen <kartofen.mail.0@protonmail.com> | 2025-07-09 22:49:24 +0300 |
|---|---|---|
| committer | kartofen <kartofen.mail.0@protonmail.com> | 2025-07-09 22:49:24 +0300 |
| commit | b7642dc9269b3b3525c08b170e01e0711577accf (patch) | |
| tree | d8b32a0749e79ddc79ce998a382ee7dc06f0a175 /parts/grammar.h | |
| parent | 2955d9bcb8ae535e7f44a54363a6f30a6d16e271 (diff) | |
untested precednece lol
Diffstat (limited to 'parts/grammar.h')
| -rw-r--r-- | parts/grammar.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/parts/grammar.h b/parts/grammar.h index d1bf176..4505b1a 100644 --- a/parts/grammar.h +++ b/parts/grammar.h @@ -3,10 +3,20 @@ #include <stddef.h> // size_t +enum precedence_flag { + PRECEDENCE_NO_ASSOC, + PRECEDENCE_RIGHT_ASSOC, + PRECEDENCE_LEFT_ASSOC, +}; + +#define PRECEDENCE_NUM(prec) ((prec) >> 2) +#define PRECEDENCE_FLAG(prec) ((prec) & 0x3) + extern struct production { symbol LHS; symbol *RHS; size_t nRHS; + unsigned int precedence; } *grammar; extern size_t total_productions; @@ -29,7 +39,7 @@ void grammar_print_cstyle() printf("{%d, (symbol[]){", grammar[i].LHS); for(size_t j = 0; j < grammar[i].nRHS; j++) printf("%d, ", grammar[i].RHS[j]); - printf("}, %zu},\n", grammar[i].nRHS); + printf("}, %zu, %d},\n", grammar[i].nRHS, grammar[i].precedence); } } |
