Skip to content
Snippets Groups Projects
Commit 016b4ba6 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Optimized some more.

Rev: lib/modules/LR.pmod/parser.pike:1.11
parent 2ebb2433
No related branches found
No related tags found
No related merge requests found
/* /*
* $Id: parser.pike,v 1.10 1998/11/14 04:22:06 grubba Exp $ * $Id: parser.pike,v 1.11 1998/11/14 15:47:58 grubba Exp $
* *
* A BNF-grammar in Pike. * A BNF-grammar in Pike.
* Compiles to a LALR(1) state-machine. * Compiles to a LALR(1) state-machine.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
//. //.
//. File: parser.pike //. File: parser.pike
//. RCSID: $Id: parser.pike,v 1.10 1998/11/14 04:22:06 grubba Exp $ //. RCSID: $Id: parser.pike,v 1.11 1998/11/14 15:47:58 grubba Exp $
//. Author: Henrik Grubbström (grubba@infovav.se) //. Author: Henrik Grubbström (grubba@infovav.se)
//. //.
//. Synopsis: LALR(1) parser and compiler. //. Synopsis: LALR(1) parser and compiler.
...@@ -767,29 +767,20 @@ static private void handle_follow_conflicts() ...@@ -767,29 +767,20 @@ static private void handle_follow_conflicts()
} }
} }
static private int go_through(object(kernel) state, object(rule) r, int offset, static private int go_through(object(kernel) state, int item_id,
object(item) current_item) object(item) current_item)
{ {
int index; int index;
object(item) i, master; object(item) i, master;
i = state->item_id_to_item[r->number + offset]; i = state->item_id_to_item[item_id];
#if 0
for (index = 0; index < sizeof(state->items); index++) {
if ((state->items[index]->r == r) &&
(state->items[index]->offset == offset)) {
/* Found the index for the current rule and offset */
i = state->items[index];
break;
}
}
#endif /* 0 */
/* What to do if not found? */ /* What to do if not found? */
if (!i) { if (!i) {
werror(sprintf("go_through: item with offset %d in rule\n%s\n" werror(sprintf("go_through: item %d not found in state\n"
"not found in state\n%s\n", "%s\n",
offset, rule_to_string(r), state_to_string(state))); item_id,
state_to_string(state)));
werror(sprintf("Backtrace:\n%s\n", describe_backtrace(backtrace()))); werror(sprintf("Backtrace:\n%s\n", describe_backtrace(backtrace())));
return(0); return(0);
} }
...@@ -801,7 +792,7 @@ static private int go_through(object(kernel) state, object(rule) r, int offset, ...@@ -801,7 +792,7 @@ static private int go_through(object(kernel) state, object(rule) r, int offset,
} }
if (i->offset < sizeof(i->r->symbols)) { if (i->offset < sizeof(i->r->symbols)) {
if (go_through(i->next_state, i->r, i->offset + 1, current_item)) { if (go_through(i->next_state, item_id + 1, current_item)) {
/* Nullable */ /* Nullable */
if ((master->offset < sizeof(master->r->symbols)) && if ((master->offset < sizeof(master->r->symbols)) &&
(intp(master->r->symbols[master->offset]))) { (intp(master->r->symbols[master->offset]))) {
...@@ -1267,8 +1258,7 @@ int compile() ...@@ -1267,8 +1258,7 @@ int compile()
/* Find items which can reduce to the nonterminal from above */ /* Find items which can reduce to the nonterminal from above */
foreach (lookup[symbol], object(item) i) { foreach (lookup[symbol], object(item) i) {
if (sizeof(i->r->symbols)) { if (sizeof(i->r->symbols)) {
if (go_through(i->next_state, i->r, i->offset+1, if (go_through(i->next_state, i->item_id + 1, transition)) {
transition)) {
/* Nullable */ /* Nullable */
object(item) master = i; object(item) master = i;
if (i->master_item) { if (i->master_item) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment