expose Parser constructor
[sbp.git] / src / edu / berkeley / sbp / Parser.java
index e884a4b..f216a38 100644 (file)
@@ -11,11 +11,11 @@ public abstract class Parser<Token, NodeType> {
     protected final Table<Token> pt;
 
     /** create a parser to parse the grammar with start symbol <tt>u</tt> */
-    protected Parser(Union u, Topology<Token> top)  { this.pt = new Table<Token>(u, top); }
-    protected Parser(Table<Token> pt)               { this.pt = pt; }
+    public Parser(Union u, Topology<Token> top)  { this.pt = new Table<Token>(u, top); }
+    Parser(Table<Token> pt)               { this.pt = pt; }
 
     /** implement this method to create the output forest corresponding to a lone shifted input token */
-    protected abstract Forest<NodeType> shiftToken(Token t, Input.Location newloc);
+    public abstract Forest<NodeType> shiftToken(Token t, Input.Location newloc);
 
     boolean helpgc = true;
 
@@ -25,15 +25,17 @@ public abstract class Parser<Token, NodeType> {
     public Forest<NodeType> parse(Input<Token> input) throws IOException, ParseFailed {
         GSS gss = new GSS();
         Input.Location loc = input.getLocation();
-        GSS.Phase current = gss.new Phase<Token>(null, this, null, input.next(), loc, null);
-        current.newNode(null, Forest.create(null, null, null, false), pt.start, true);
+        Token tok = input.next();
+        GSS.Phase current = gss.new Phase<Token>(null, this, null, tok, loc, input.getLocation(), null);
+        current.newNode(null, Forest.create(loc.createRegion(loc), null, null, false), pt.start, true);
         int count = 1;
         for(int idx=0;;idx++) {
             Input.Location oldloc = loc;
-            loc = input.getLocation();
             current.reduce();
             Forest forest = current.token==null ? null : shiftToken((Token)current.token, loc);
-            GSS.Phase next = gss.new Phase<Token>(current, this, current, input.next(), loc, forest);
+            loc = input.getLocation();
+            Token nextToken = input.next();
+            GSS.Phase next = gss.new Phase<Token>(current, this, current, nextToken, loc, input.getLocation(), forest);
             if (!helpgc) {
                 FileOutputStream fos = new FileOutputStream("out-"+idx+".dot");
                 PrintWriter p = new PrintWriter(new OutputStreamWriter(fos));