X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FParser.java;h=fa2f7d153c8d865873d15dba2171600ed9ed325a;hb=a8478f5ddfbfbc8d910d09f27163cbd55752d3b6;hp=e884a4bc768af4ab14ed5314a104c69e302a7693;hpb=2c1c0293545f3d12c23220fd05c663e6aa3f3de1;p=sbp.git diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index e884a4b..fa2f7d1 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -1,3 +1,5 @@ +// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license + package edu.berkeley.sbp; import edu.berkeley.sbp.*; import edu.berkeley.sbp.util.*; @@ -11,11 +13,11 @@ public abstract class Parser { protected final Table pt; /** create a parser to parse the grammar with start symbol u */ - protected Parser(Union u, Topology top) { this.pt = new Table(u, top); } - protected Parser(Table pt) { this.pt = pt; } + public Parser(Union u, Topology top) { this.pt = new Table(u, top); } + Parser(Table pt) { this.pt = pt; } /** implement this method to create the output forest corresponding to a lone shifted input token */ - protected abstract Forest shiftToken(Token t, Input.Location newloc); + public abstract Forest shiftToken(Token t, Input.Location newloc); boolean helpgc = true; @@ -23,23 +25,25 @@ public abstract class Parser { /** parse input, and return the shared packed parse forest (or throw an exception) */ public Forest parse(Input input) throws IOException, ParseFailed { - GSS gss = new GSS(); + GSS gss = new GSS(input); Input.Location loc = input.getLocation(); - GSS.Phase current = gss.new Phase(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(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(current, this, current, input.next(), loc, forest); + loc = input.getLocation(); + Token nextToken = input.next(); + GSS.Phase next = gss.new Phase(current, this, current, nextToken, loc, input.getLocation(), forest); if (!helpgc) { FileOutputStream fos = new FileOutputStream("out-"+idx+".dot"); PrintWriter p = new PrintWriter(new OutputStreamWriter(fos)); GraphViz gv = new GraphViz(); for(Object n : next) - ((GSS.Phase.Node)n).toGraphViz(gv); + ((Node)n).toGraphViz(gv); gv.dump(p); p.flush(); p.close();