piggy-back the next shift directly onto the reduce
This commit is contained in:
parent
bbbaf1634c
commit
7cd143c0c4
1 changed files with 13 additions and 8 deletions
|
|
@ -268,12 +268,7 @@ bool h_lrengine_step(HLREngine *engine, const HLRAction *action)
|
||||||
|
|
||||||
assert(action->type == HLR_SHIFT || action->type == HLR_REDUCE);
|
assert(action->type == HLR_SHIFT || action->type == HLR_REDUCE);
|
||||||
|
|
||||||
if(action->type == HLR_SHIFT) {
|
if(action->type == HLR_REDUCE) {
|
||||||
h_slist_push(left, (void *)(uintptr_t)engine->state);
|
|
||||||
h_slist_drop(right); // symbol (discard)
|
|
||||||
h_slist_push(left, h_slist_drop(right)); // semantic value
|
|
||||||
engine->state = action->nextstate;
|
|
||||||
} else {
|
|
||||||
assert(action->type == HLR_REDUCE);
|
assert(action->type == HLR_REDUCE);
|
||||||
size_t len = action->production.length;
|
size_t len = action->production.length;
|
||||||
HCFChoice *symbol = action->production.lhs;
|
HCFChoice *symbol = action->production.lhs;
|
||||||
|
|
@ -318,8 +313,18 @@ bool h_lrengine_step(HLREngine *engine, const HLRAction *action)
|
||||||
// this is LR, building a right-most derivation bottom-up, so no reduce can
|
// this is LR, building a right-most derivation bottom-up, so no reduce can
|
||||||
// follow a reduce. we can also assume no conflict follows for GLR if we
|
// follow a reduce. we can also assume no conflict follows for GLR if we
|
||||||
// use LALR tables, because only terminal symbols (lookahead) get reduces.
|
// use LALR tables, because only terminal symbols (lookahead) get reduces.
|
||||||
const HLRAction *next = h_lr_lookup(engine->table, engine->state, symbol);
|
action = h_lr_lookup(engine->table, engine->state, symbol);
|
||||||
assert(next == NULL || next->type == HLR_SHIFT);
|
if(action == NULL)
|
||||||
|
return false; // no handle after reduce; terminate
|
||||||
|
assert(action->type == HLR_SHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this could be the original action, or a shift piggy-backed onto reduce
|
||||||
|
if(action->type == HLR_SHIFT) {
|
||||||
|
h_slist_push(left, (void *)(uintptr_t)engine->state);
|
||||||
|
h_slist_drop(right); // symbol (discard)
|
||||||
|
h_slist_push(left, h_slist_drop(right)); // semantic value
|
||||||
|
engine->state = action->nextstate;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue