X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=ead35511fd0c1986b994c4b610c0a2bc4ccff118;hp=ddee582a4c91bc2e95d8179d639012da5274e036;hb=842f3c9b981b35721bb50d49e85c11085b2040a3;hpb=ebb5fe5647046306f415e31e4967b23169c9004e diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index ddee582..ead3551 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -11,7 +11,7 @@ import java.lang.reflect.*; /** a parser which translates streams of Tokens of type T into a Forest */ public abstract class Parser { - private final Table pt; + public final Table pt; /** create a parser to parse the grammar with start symbol u */ protected Parser(Union u) { this.pt = new Table(u, top()); } @@ -36,16 +36,15 @@ public abstract class Parser { public Forest parse(Token.Stream input) throws IOException, Failed { GSS gss = new GSS(); Token.Location loc = input.getLocation(); - GSS.Phase current = gss.new Phase(null, input.next(1), loc); + GSS.Phase current = gss.new Phase(null, this, null, input.next(1, 0, 0), loc, null); current.newNode(null, null, pt.start, true); int count = 1; for(;;) { loc = input.getLocation(); //current.checkFailure(); - GSS.Phase next = gss.new Phase(current, input.next(count), loc); current.reduce(); Forest forest = current.token==null ? null : shiftedToken((T)current.token, loc); - current.shift(next, forest); + GSS.Phase next = gss.new Phase(current, this, current, input.next(count, gss.resets, gss.waits), loc, forest); count = next.hash.size(); if (current.isDone()) return (Forest)current.finalResult; current = next; @@ -55,7 +54,7 @@ public abstract class Parser { // Exceptions ////////////////////////////////////////////////////////////////////////////// - public static class Failed extends Exception { + public static class Failed extends RuntimeException { private final Token.Location location; private final String message; public Failed() { this("", null); } @@ -83,6 +82,8 @@ public abstract class Parser { static class Table extends Walk.Cache { public final Walk.Cache cache = this; + + public HashMapBag byPosition = new HashMapBag(); private void walk(Element e, HashSet hs) { if (e==null) return; @@ -247,6 +248,7 @@ public abstract class Parser { // register ourselves in the all_states hash so that no // two states are ever created with an identical position set all_states.put(hs, this); + for(Position p : hs) byPosition.add(p,this); // Step 1a: examine all Position's in this state and compute the mappings from // sets of follow tokens (tokens which could follow this position) to sets @@ -381,7 +383,7 @@ public abstract class Parser { private void finish(GSS.Phase.Node parent, Forest result, GSS.Phase target) { State state = parent.state.gotoSetNonTerminals.get(position.owner()); if (state!=null) - target.newNode(parent, result, state, numPop<=0); + target.newNode(parent, result, state, numPop<=0, this); } } }