getNtermIndex method
int
getNtermIndex(
- int start,
- int sym,
- int buffer_position
)
Implementation
int getNtermIndex(int start, int sym, int buffer_position) {
var highest_symbol = sym - NT_OFFSET,
tok = tokStream.getKind(buffer[buffer_position]);
tokStream.reset(buffer[buffer_position + 1]);
//
// Initialize stack index of temp_stack and initialize maximum
// position of state stack that is still useful.
//
tempStackTop = 0;
tempStack[tempStackTop] = start;
var act = ntAction(start, highest_symbol);
if (act > NUM_RULES) // goto action?
{
tempStack[tempStackTop + 1] = act;
act = tAction(act, tok);
}
while (act <= NUM_RULES) {
//
// Process all goto-reduce actions following reduction,
// until a goto action is computed ...
//
do {
tempStackTop -= (rhs(act) - 1);
if (tempStackTop < 0) return nonterminalIndex(highest_symbol);
if (tempStackTop == 0) highest_symbol = lhs(act);
act = ntAction(tempStack[tempStackTop], lhs(act));
} while (act <= NUM_RULES);
tempStack[tempStackTop + 1] = act;
act = tAction(act, tok);
}
return nonterminalIndex(highest_symbol);
}