- Annotation Tutorial
- MUST HAVE BETTER ERROR MESSAGES
+ - when ambiguity encountered, show text region (where-to-where)
- use for developing java15.g
- java15.g
______________________________________________________________________________
v1.1
+ - broader regression testing (for stuff like error messages, etc)
+
- More topology untangling [later]
- tib: use the lexer only for indentation increases/decreases
- grammar highlighting?
public String toString() {
// FIXME: print the input region that was ambiguously matched
StringBuffer sb = new StringBuffer();
- sb.append("unresolved ambiguity; shared subtrees are shown as \"*\" ");
+ sb.append("unresolved ambiguity at "+ambiguity.getRegion()+"; shared subtrees are shown as \"*\" ");
for(Tree<?> result : ht) {
sb.append("\n possibility: ");
StringBuffer sb2 = new StringBuffer();
abstract void gather(HashSet<Forest<NodeType>> ignore);
abstract void edges(GraphViz.Node n);
boolean ambiguous() { return false; }
-
+
+ abstract Input.Region getRegion();
// One //////////////////////////////////////////////////////////////////////////////
/** if true, the last child's children are considered children of this node */
private final boolean lift;
+ Input.Region getRegion() { return location; }
+
private One(Input.Region loc, NodeType head, Forest<NodeType>[] children, boolean lift) {
this.location = loc;
this.head = head;
public Many() { }
+ Input.Region getRegion() { return hp.iterator().next().getRegion(); } // all should be identical
+
public Tree<NodeType> expand1() throws Ambiguous {
touched();
if (hp.size() > 1) {
private Phase next = null;
private Phase prev;
private Input.Location location;
+ private Input.Location nextLocation;
public final Parser parser;
private Forest forest;
- public Phase(Phase prev, Parser parser, Phase previous, Tok token, Input.Location location, Forest forest) throws ParseFailed {
+ public Phase(Phase prev, Parser parser, Phase previous, Tok token, Input.Location location, Input.Location nextLocation, Forest forest) throws ParseFailed {
this.prev = prev;
this.forest = forest;
this.parser = parser;
this.pos = previous==null ? 0 : previous.pos+1;
this.token = token;
this.location = location;
+ this.nextLocation = nextLocation;
performed.clear();
reset();
}
}
public Input.Location getLocation() { return location; }
+ public Input.Location getNextLocation() { return nextLocation; }
/** add a new node (merging with existing nodes if possible)
* @param parent the parent of the new node
for(Node child : ((Forest.Many<?>)result).parents) {
if (only != null && child!=only) continue;
holder[pos] = result;
- if (pos==0) child.finish(r, r.rewrite(child.phase().getLocation().createRegion(phase().getLocation())), target);
+ if (pos==0) child.finish(r, r.rewrite(child.phase().getNextLocation().createRegion(target.getLocation())), target);
else child.reduce(r, pos-1, target, null);
}
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);
+ Token tok = input.next();
+ GSS.Phase current = gss.new Phase<Token>(null, this, null, tok, loc, input.getLocation(), null);
current.newNode(null, Forest.create(null, 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));
boolean cr = false;
private int count = 0;
public boolean isCR() { return cr; }
- public Character next() throws IOException {
+ public Character _next() throws IOException {
cr = false;
int i = r.read();
if (i==-1) { System.err.print("\r...done \r"); return null; }
public static abstract class Input<Token> implements edu.berkeley.sbp.Input<Token> {
- public abstract Token next() throws IOException;
+ public abstract Token _next() throws IOException;
public abstract boolean isCR();
long then = 0;
private Cartesian.Location location = new Cartesian.Location(0, 1);
public edu.berkeley.sbp.Input.Location getLocation() { return location; }
- public Token next(int numstates, int resets, int waits) throws IOException {
+ public Token next() throws IOException {
int line = location.getRow();
int col = location.getCol();
- Token t = next();
+ Token t = _next();
if (t==null) return null;
String s = " line "+line+", col " + col;
while(s.length() < 20) s += " ";
- s += "[ambiguity level: " + (numstates-1) + "] [resets: " + resets + "] [waits: " + waits + "]";
+ //s += "[ambiguity level: " + (numstates-1) + "] [resets: " + resets + "] [waits: " + waits + "]";
long now = System.currentTimeMillis();
if (now-then > 10) {
then = now;
Sequence multSequence = Sequence.create("mult", mult, null, false);
// uncomment this line to disambiguate
- multSequence = multSequence.andnot(Sequence.create("add", add, null, false));
+ //multSequence = multSequence.andnot(Sequence.create("add", add, null, false));
expr.add(Sequence.create(paren, 1));
expr.add(addSequence);
expr.add(multSequence);
expr.add(Sequence.create(atom('0', '9')));
- String input = "8+(1+3)*7";
+ String input = "(1+3*8)*7";
System.out.println("input: \""+input+"\"");