From: adam Date: Tue, 11 Apr 2006 20:56:56 +0000 (-0400) Subject: checkpoint X-Git-Tag: tag_for_25-Mar~269 X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=474037fe8463b96dfaf0209be157cbf5223a0910 checkpoint darcs-hash:20060411205656-5007d-2a14a7c1cf7a3a936790ffe1f96c099d9d780c6a.gz --- diff --git a/Makefile b/Makefile index f61196e..874eaca 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,11 @@ tibdoc: edu.berkeley.sbp.jar tests/tibdoc.g \ tests/input.tibdoc +demo: edu.berkeley.sbp.jar + $(java) -cp $< edu.berkeley.sbp.misc.Demo \ + tests/demo.g \ + tests/demo.in + regress: make boot rm edu.berkeley.sbp.jar @@ -50,7 +55,7 @@ boot: edu.berkeley.sbp.jar edu.berkeley.sbp.jar: $(shell find src -name \*.java) mkdir -p bin - javac -cp tests/ArchSimA3.jar:tests/grappa.jar -d bin -sourcepath src $^ + javac -cp javax.servlet.jar:tests/ArchSimA3.jar:tests/grappa.jar -d bin -sourcepath src $^ cd bin; jar cf ../$@ . javadoc: diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 12c8cf1..3790562 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -7,7 +7,10 @@ import java.util.*; import java.lang.reflect.*; /** an efficient representation of a collection of trees (Tomita's shared packed parse forest) */ -public abstract class Forest /*extends PrintableTree>*/ implements Visitable>, IntegerMappable, GraphViz.ToGraphViz { +public abstract class Forest /*extends PrintableTree>*/ + implements Visitable>, + IntegerMappable, + GraphViz.ToGraphViz { private static int master_idx = 0; private final int idx = master_idx++; diff --git a/src/edu/berkeley/sbp/GSS.java b/src/edu/berkeley/sbp/GSS.java index 7d3758f..2154731 100644 --- a/src/edu/berkeley/sbp/GSS.java +++ b/src/edu/berkeley/sbp/GSS.java @@ -10,6 +10,7 @@ import java.lang.reflect.*; /** implements Tomita's Graph Structured Stack */ class GSS { + public static int count = 0; public GSS() { } private Phase.Node[] reducing_list = null; @@ -66,6 +67,7 @@ class GSS { singularReductions = new IntPairMap(); expectedInhibit.clear(); expectedInhibit.addAll(inhibited); + reset = false; good = false; closed = false; reducing = false; @@ -113,7 +115,7 @@ class GSS { } if (!owner.lame) newNode(parent, pending, state, fromEmptyReduction); - if (reduction!=null) inhibit(reduction, parent==null?0:parent.phase().pos); + if (reduction!=null) uninhibit(reduction, parent==null?0:parent.phase().pos); if (reduction != null) { boolean redo = true; while(redo) { @@ -156,19 +158,19 @@ class GSS { return true; } - public void uninhibit(int p, Sequence s) { + public void inhibit(int p, Sequence s) { if (s.hated!=null) for(Sequence s2 : s.hated) inhibited.remove(p, s2); } - public void inhibit(Position r, int p) { + public void uninhibit(Position r, int p) { if (r.owner().hated == null) return; // remember that dead states are still allowed to shift -- just not allowed to reduce boolean reset = false; for(Sequence seq : r.owner().hated) { if (performed.contains(p,seq)) { - uninhibit(p, seq); + inhibit(p, seq); //System.out.println("\nresetting due to " + r.owner() + " killing " + seq); //inhibited.clear(); inhibited.add(p, seq); @@ -209,8 +211,10 @@ class GSS { reset(); reduce(); } + count = 0; } + private boolean reset = false; class Reset extends RuntimeException { } /** perform all shift operations, adding promoted nodes to next */ diff --git a/src/edu/berkeley/sbp/ParseFailed.java b/src/edu/berkeley/sbp/ParseFailed.java index 619bf65..d1e60ae 100644 --- a/src/edu/berkeley/sbp/ParseFailed.java +++ b/src/edu/berkeley/sbp/ParseFailed.java @@ -37,7 +37,7 @@ public class ParseFailed extends Exception { public static String el(Object e) { String s = e.toString(); - if (s.length()==0 || s.charAt(0)!='\"' || s.charAt(s.length()-1)!='\"') return ANSI.yellow(s); + if (s.length()==0 || s.charAt(0)!='\"' || s.charAt(s.length()-1)!='\"') return /*ANSI.yellow(s)*/s; s = s.substring(1); s = s.substring(0, s.length()-1); StringBuffer ret = new StringBuffer(); @@ -45,13 +45,14 @@ public class ParseFailed extends Exception { if (s.charAt(i)=='\\' && i nodes) { String lookAhead = token==null ? "" : token.toString(); StringBuffer ret = new StringBuffer(); ret.append("\n "); ret.append(message); + /* HashMap> errors = new HashMap>(); for(Node n : nodes) { //System.out.println(n.state); @@ -72,6 +73,7 @@ public class ParseFailed extends Exception { ret.append("\n"); } } + */ return ret.toString(); } diff --git a/src/edu/berkeley/sbp/Tree.java b/src/edu/berkeley/sbp/Tree.java index 220d1dd..cdd3b8b 100644 --- a/src/edu/berkeley/sbp/Tree.java +++ b/src/edu/berkeley/sbp/Tree.java @@ -7,7 +7,10 @@ import java.util.*; import java.lang.reflect.*; /** a tree (or node in a tree); see jargon.txt for details */ -public class Tree extends PrintableTree> implements Iterable> { +public class Tree + extends PrintableTree> + implements Iterable>, + GraphViz.ToGraphViz { final T head; Tree[] children; @@ -43,4 +46,15 @@ public class Tree extends PrintableTree> implements Iterable> protected String left() { return "{"; } protected String right() { return "}"; } protected boolean ignoreSingleton() { return false; } + + public GraphViz.Node toGraphViz(GraphViz gv) { + if (gv.hasNode(this)) return gv.createNode(this); + GraphViz.Node n = gv.createNode(this); + n.label = head()==null ? "" : head().toString(); + //n.color = "red"; + for(Tree t : this) n.edge(t, null); + return n; + } + public boolean isTransparent() { return false; } + public boolean isHidden() { return false; } } diff --git a/src/edu/berkeley/sbp/misc/MetaGrammar.java b/src/edu/berkeley/sbp/misc/MetaGrammar.java index 7dda407..d73586b 100644 --- a/src/edu/berkeley/sbp/misc/MetaGrammar.java +++ b/src/edu/berkeley/sbp/misc/MetaGrammar.java @@ -530,6 +530,19 @@ public class MetaGrammar extends StringWalker { + + + + + + + + + + + + + // DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED new edu.berkeley.sbp.Tree(null, "grammar", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "=", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "s", new edu.berkeley.sbp.Tree[] { })}), new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "psx", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "ps", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "!", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "nonTerminal", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "w", new edu.berkeley.sbp.Tree[] { }), @@ -1194,3 +1207,16 @@ new edu.berkeley.sbp.Tree(null, "grammar", new edu.berkeley.sbp.Tree[] { new edu + + + + + + + + + + + + + diff --git a/src/edu/berkeley/sbp/util/ANSI.java b/src/edu/berkeley/sbp/util/ANSI.java index 750f90d..d0109df 100644 --- a/src/edu/berkeley/sbp/util/ANSI.java +++ b/src/edu/berkeley/sbp/util/ANSI.java @@ -1,10 +1,17 @@ package edu.berkeley.sbp.util; public class ANSI { - public static String black(Object o) { return "\033[30m"+o+"\033[0m"; } - public static String red(Object o) { return "\033[31m"+o+"\033[0m"; } - public static String green(Object o) { return "\033[32m"+o+"\033[0m"; } - public static String yellow(Object o) { return "\033[33m"+o+"\033[0m"; } - public static String blue(Object o) { return "\033[34m"+o+"\033[0m"; } - public static String purple(Object o) { return "\033[35m"+o+"\033[0m"; } - public static String cyan(Object o) { return "\033[36m"+o+"\033[0m"; } + //public static String black(Object o) { return "\033[30m"+o+"\033[0m"; } + public static String black(Object o) { return o+""; } + //public static String red(Object o) { return "\033[31m"+o+"\033[0m"; } + public static String red(Object o) { return o+""; } + //public static String green(Object o) { return "\033[32m"+o+"\033[0m"; } + public static String green(Object o) { return o+""; } + //public static String yellow(Object o) { return "\033[33m"+o+"\033[0m"; } + public static String yellow(Object o) { return o+""; } + //public static String blue(Object o) { return "\033[34m"+o+"\033[0m"; } + public static String blue(Object o) { return o+""; } + //public static String purple(Object o) { return "\033[35m"+o+"\033[0m"; } + public static String purple(Object o) { return o+""; } + //public static String cyan(Object o) { return "\033[36m"+o+"\033[0m"; } + public static String cyan(Object o) { return o+""; } } diff --git a/src/edu/berkeley/sbp/util/GraphViz.java b/src/edu/berkeley/sbp/util/GraphViz.java index 86d0d50..ff8f46c 100644 --- a/src/edu/berkeley/sbp/util/GraphViz.java +++ b/src/edu/berkeley/sbp/util/GraphViz.java @@ -113,6 +113,10 @@ public class GraphViz { public boolean isHidden(); } + public void show() throws IOException { + Runtime.getRuntime().exec(new String[] { "dot", "-Tsvg" }); + } + public void dump(PrintWriter pw) { IdentityHashMap done = new IdentityHashMap(); pw.println("digraph G { rankdir=LR; \n"); @@ -131,6 +135,7 @@ public class GraphViz { } for(Node n : ihm.values()) n.edges(pw); pw.println("}\n"); + pw.flush(); } } diff --git a/tests/regression.tc b/tests/regression.tc index faba28d..77af771 100644 --- a/tests/regression.tc +++ b/tests/regression.tc @@ -265,65 +265,65 @@ testcase { q = q:: [a-z]++ } -//testcase { -// -// input " -// -// -// -// while x>0 -// while y>0 -// foo() -// bar() -// -// -// while x>0 -// while y>0 -// foo() -// bar() -// -// -// -//"; -// output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}"; -// -//indent ! = ww -//outdent ! = " " outdent " " -// | " " (~[]*) "\n" -// -//w ! = " " | "\n" | "\r" -//ws ! = w* -//ww ! = sp* -//sp ! = " " -//any ! = ~[]* -// -//s = ws statement ws statement ws => smt -// -//block = "\n" indent blockBody -// &~ "\n" outdent ~[\ ] ~[]* -// -//blockBody = statement -// > statement ws blockBody => "sbb" -// -//statement = call -// | ^"while" expr block /ws -// -//expr = ident -// | call -// | expr ^">" expr /ws -// | num -// -//call = expr "()" /ws -// -//num = [0-9]++ -// -//ident = [a-z]++ &~ keyword -//keyword = "if" | "then" | "else" | "while" -// -// -// -//} -// +testcase { + + input " + + + + while x>0 + while y>0 + foo() + bar() + + + while x>0 + while y>0 + foo() + bar() + + + +"; + output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}} while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}"; + +indent = ww +outdent = " " outdent " " + | " " (~[]*) "\n" + +w = " " | "\n" | "\r" +ws = w* +ww = sp* +sp = " " +any = ~[]* + +s = smt:: !ws statement !ws statement !ws + +block = !"\n" !indent blockBody + &~ !"\n" !outdent !(~[\ ]) !(~[]*) + +blockBody = statement + > sbb:: statement ws blockBody + +statement = call + | ^"while" expr block /ws + +expr = ident + | call + | expr ^">" expr /ws + | num + +call = expr "()" /ws + +num = [0-9]++ + +ident = [a-z]++ &~ keyword +keyword = "if" | "then" | "else" | "while" + + + +} + testcase {