X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=c37d1a81d9a289554ca05a0ab196acccb9e1c926;hp=99e2d084e6ca58795c6d261228dfcee2d1060e70;hb=93b9f1a57460257f71a4cef17419a723e294550d;hpb=78a166e98747ddeb79310ccba340f292fa8a6dca diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index 99e2d08..c37d1a8 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -1,8 +1,9 @@ -// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license +// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license package edu.berkeley.sbp; import edu.berkeley.sbp.util.*; import edu.berkeley.sbp.Sequence.Position; +import edu.berkeley.sbp.Sequence.Position; import java.io.*; import java.util.*; @@ -66,10 +67,10 @@ public abstract class Parser { _last = c; switch(c) { case edu.berkeley.sbp.chr.CharAtom.left: - buf += "\033[31m{\033[0m"; + buf += "\033[31m>\033[0m"; break; case edu.berkeley.sbp.chr.CharAtom.right: - buf += "\033[31m}\033[0m"; + buf += "\033[31m<\033[0m"; break; case -1: // FIXME case '\n': @@ -106,7 +107,7 @@ public abstract class Parser { // Table ////////////////////////////////////////////////////////////////////////////// /** an SLR(1) parse table which may contain conflicts */ - class Table extends Grammar { + class Table extends Grammar implements Serializable { /** the start state */ final State start; @@ -118,13 +119,13 @@ public abstract class Parser { private int master_state_idx = 0; /** all the states for this table */ - HashSet> all_states = new HashSet>(); + private transient HashSet> all_states = new HashSet>(); /** all the doomed states in this table */ - HashMap,State> doomed_states = new HashMap,State>(); + private transient HashMap,State> doomed_states = new HashMap,State>(); /** all the non-doomed states in this table */ - HashMap,State> normal_states = new HashMap,State>(); + private transient HashMap,State> normal_states = new HashMap,State>(); Topology emptyTopology() { return Parser.this.emptyTopology(); } @@ -192,7 +193,7 @@ public abstract class Parser { // al will be sorted in DECREASING order (al[0] >= al[1]) ArrayList al = new ArrayList(); for(State s : all_states) { - for(Object po : s) { + for(Object po : s.positions()) { Sequence.Position p = (Sequence.Position)po; if (al.contains(p)) continue; int i=0; @@ -263,17 +264,17 @@ public abstract class Parser { * space+time complexity in otherwise simple grammars. There * is an example of this in the regression suite. */ - class State implements IntegerMappable, Iterable { + class State implements IntegerMappable, Serializable { public final int idx = master_state_idx++; - private final HashSet hs; + private final transient HashSet hs; public HashSet> conjunctStates = new HashSet>(); - HashMap> gotoSetNonTerminals = new HashMap>(); + HashMap> gotoSetNonTerminals = new HashMap>(); private transient TopologicalBag> gotoSetTerminals = new TopologicalBag>(); - private TopologicalBag reductions = new TopologicalBag(); - private HashSet eofReductions = new HashSet(); + private TopologicalBag reductions = new TopologicalBag(); + private HashSet eofReductions = new HashSet(); private TopologicalBag> shifts = new TopologicalBag>(); private boolean accept = false; @@ -285,7 +286,9 @@ public abstract class Parser { public boolean doomed() { return doomed; } boolean isAccepting() { return accept; } - public Iterator iterator() { return hs.iterator(); } + + Iterable positions() { return hs; } + boolean canShift(Token t) { return oshifts!=null && oshifts.contains(t); } void invokeShifts(Token t, GSS.Phase phase, Result r) { oshifts.invoke(t, phase, r); } boolean canReduce(Token t) { @@ -399,10 +402,12 @@ public abstract class Parser { if (seq.needs.contains(y) || seq.hates.contains(y)) { // FIXME: assumption that no sequence is ever both usefully (non-lamely) matched // and also directly lamely matched - ((HashMap)gotoSetNonTerminals).put(y, dead_state); + for(Position pp = y.firstp(); pp != null; pp = pp.next()) + ((HashMap)gotoSetNonTerminals).put(pp, dead_state); continue OUTER; } - gotoSetNonTerminals.put(y, s); + for(Position pp = y.firstp(); pp != null; pp = pp.next()) + gotoSetNonTerminals.put(pp, s); } }