completeScope method
Implementation
bool completeScope(IntSegmentedTuple action, int scope_rhs_index) {
var kind = scopeRhs(scope_rhs_index);
if (kind == 0) return true;
var act = nextStack[nextStackTop];
if (kind > NT_OFFSET) {
var lhs_symbol = kind - NT_OFFSET;
if (baseCheck(act + lhs_symbol) != lhs_symbol) // is there a valid
// action defined on
// lhs_symbol?
{
return false;
}
act = ntAction(act, lhs_symbol);
//
// if action is a goto-reduce action, save it as a shift-reduce
// action.
//
action.add(act <= NUM_RULES ? act + ERROR_ACTION : act);
while (act <= NUM_RULES) {
nextStackTop -= (rhs(act) - 1);
act = ntAction(nextStack[nextStackTop], lhs(act));
}
nextStackTop++;
nextStack[nextStackTop] = act;
//System.err.println("Shifting nonterminal " +
//name(nonterminalIndex(lhs_symbol)));
return completeScope(action, scope_rhs_index + 1);
}
//
// Processing a terminal
//
act = tAction(act, kind);
action.add(act); // save this terminal action
// assert(act > NUM_RULES);
if (act < ACCEPT_ACTION) {
nextStackTop++;
nextStack[nextStackTop] = act;
//System.err.println("Shifting terminal " + name(terminalIndex(kind)));
return completeScope(action, scope_rhs_index + 1);
} else if (act > ERROR_ACTION) {
act -= ERROR_ACTION;
do {
nextStackTop -= (rhs(act) - 1);
act = ntAction(nextStack[nextStackTop], lhs(act));
} while (act <= NUM_RULES);
nextStackTop++;
nextStack[nextStackTop] = act;
//System.err.println("Shift-reducing terminal " + name(terminalIndex(kind)));
//assert(scopeRhs(scope_rhs_index + 1) == 0);
return true;
} else if (act > ACCEPT_ACTION &&
act < ERROR_ACTION) // conflicting actions?
{
var save_action_size = action.size();
for (var i = act;
baseAction(i) != 0;
i++) // consider only shift and shift-reduce actions
{
action.reset(save_action_size);
act = baseAction(i);
action.add(act); // save this terminal action
if (act <= NUM_RULES) // Ignore reduce actions
{
;
}
else if (act < ACCEPT_ACTION) {
nextStackTop++;
nextStack[nextStackTop] = act;
//System.err.println("(2)Shifting terminal " + name(terminalIndex(kind)));
if (completeScope(action, scope_rhs_index + 1)) return true;
} else if (act > ERROR_ACTION) {
act -= ERROR_ACTION;
do {
nextStackTop -= (rhs(act) - 1);
act = ntAction(nextStack[nextStackTop], lhs(act));
} while (act <= NUM_RULES);
nextStackTop++;
nextStack[nextStackTop] = act;
//System.err.println("(2)Shift-reducing terminal " + name(terminalIndex(kind)));
//assert(scopeRhs(scope_rhs_index + 1) == 0);
return true;
}
}
}
return false;
}