os

An operating system
git clone https://erai.gay/code/os/
Log | Files | Refs | README | LICENSE

commit 51db3e4e2505435e44e67efede4d5d221391804e
parent 740f7e3a62b8d53fae9498805e75130c2912be78
Author: erai <erai@omiltem.net>
Date:   Wed, 23 Apr 2025 18:11:09 -0400

move lalr action to end of reduce

Diffstat:
Mlalr.om | 15+++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lalr.om b/lalr.om @@ -1482,21 +1482,19 @@ func dolalr(c: *compiler, name: *byte, out: *file) { stack_len = stack_len + 1; l.stack_len = l.stack_len + 1; state = act_out; + memset((&l.stack[l.stack_len]) as *byte, 0, sizeof(*l.stack)); tok = gettok(l); } else if act == 'r' { - if call_table[act_out] { - l.sem_len = pos_table[act_out]; - l.sem = &l.stack[l.stack_len - l.sem_len]; - call_table[act_out](l); - } if act_len != 0 { if act_len > stack_len { die("stack underflow"); } - memcpy((&l.stack[l.stack_len - act_len]) as *byte, (&l.stack[l.stack_len]) as *byte, sizeof(*l.stack)); + memcpy((&l.stack[l.stack_len - act_len]) as *byte, (&l.stack[l.stack_len - 1]) as *byte, sizeof(*l.stack)); stack_len = stack_len - act_len; l.stack_len = l.stack_len - act_len; state = stack[stack_len]; + } else { + memset((&l.stack[l.stack_len]) as *byte, 0, sizeof(*l.stack)); } ensure_arr(l.a, (&stack) as **void, &stack_cap, stack_len + 1, sizeof(*stack)); ensure_arr(l.a, (&l.stack) as **void, &l.stack_cap, l.stack_len + 2, sizeof(*l.stack)); @@ -1504,6 +1502,11 @@ func dolalr(c: *compiler, name: *byte, out: *file) { stack_len = stack_len + 1; l.stack_len = l.stack_len + 1; state = goto_table[state * prod_len + act_out]; + if call_table[act_out] { + l.sem_len = pos_table[act_out]; + l.sem = &l.stack[l.stack_len - l.sem_len - 1]; + call_table[act_out](l); + } } else if act == 'a' { if tok != term_len - 1 { die("accept not at eof");