X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FGSS.java;h=311fd29322d250285566a33b4579b7ac3f1319bb;hp=74cbb484bf568609be666fb79efc2994d345ae11;hb=08aa6cdd07a882fdedf7a6d5c7bd0d754460965b;hpb=9ded11559a1b6f817e99355b1c9e2c88042e91d4 diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index 74cbb48..311fd29 100644 --- a/src/edu/berkeley/sbp/GSS.java +++ b/src/edu/berkeley/sbp/GSS.java @@ -5,21 +5,6 @@ import java.io.*; import java.util.*; import java.lang.reflect.*; -////////////////////////////////////////////////////////////////////////////// -// TODO: -// -// - fix public/package/private status -// - -////////////////////////////////////////////////////////////////////////////// -// Optimizations to add -// -// ** NOTE: not all of these are appropriate for this class -- it is -// simply a list of optimizations not implemented. This -// class is meant to remain simple and easy to understand; -// optimizations which obscure that do not belong here (they -// should go into the compiled version instead) - /** implements Tomita's Graph Structured Stack */ class GSS { @@ -42,7 +27,7 @@ class GSS { public Forest.Ref finalResult = null; /** all nodes, keyed by the value returned by code() */ - private HashMap hash = new HashMap(); /* ALLOC */ + /*private*/ HashMap hash = new HashMap(); /* ALLOC */ /** the number of nodes in this phase */ private int numNodes = 0; @@ -60,6 +45,8 @@ class GSS { private String error = "generic syntax error"; public void checkFailure() throws Parser.Failed { + if (token==null && finalResult==null) + throw new Parser.Failed(error, getLocation()); if (numNodes <= 0) throw new Parser.Failed(error, getLocation()); } @@ -81,6 +68,8 @@ class GSS { private void newNode2(Node p, Node parent, Forest pending, Parser.Table.State state, boolean fromEmptyReduction) { p.holder.merge(pending); if (p.parents().contains(parent)) return; + //if (p.fe && p.phase() != parent.phase()) throw new Error("yep yep"); + //if (!p.fe && p.phase() == parent.phase()) throw new Error("yep yep2"); p.parents().add(parent, true); if (p!=parent && !fromEmptyReduction) p.queueReductions(parent); } @@ -96,7 +85,7 @@ class GSS { //return; } while(false); - Node n = new Node(parent, pending, state); // ALLOC + Node n = new Node(parent, pending, state, fromEmptyReduction); // ALLOC n.queueEmptyReductions(); if (!fromEmptyReduction) n.queueReductions(parent); } @@ -123,7 +112,7 @@ class GSS { } public void invoke(Parser.Table.State st, Forest result, Node n) { - next.newNode(n, result, st, true); + next.newNode(n, result, st, false); } private Phase next = null; @@ -197,6 +186,7 @@ class GSS { public FastSet parents() { return this; } public void queueReductions() { + if (!reducing) return; if (allqueued) return; allqueued = true; int where = parents().size(); @@ -222,7 +212,9 @@ class GSS { state.invokeReductions(token, this, null, null); } - private Node(Node parent, Forest pending, Parser.Table.State state) { + private boolean fe; + private Node(Node parent, Forest pending, Parser.Table.State state, boolean fe) { + this.fe = fe; this.state = state; Phase start = parent==null ? null : parent.phase(); if (pending != null) this.holder().merge(pending);