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
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:
import java.lang.reflect.*;
/** an efficient representation of a collection of trees (Tomita's shared packed parse forest) */
-public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/ implements Visitable<Forest.Body<T>>, IntegerMappable, GraphViz.ToGraphViz {
+public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/
+ implements Visitable<Forest.Body<T>>,
+ IntegerMappable,
+ GraphViz.ToGraphViz {
private static int master_idx = 0;
private final int idx = master_idx++;
/** implements Tomita's Graph Structured Stack */
class GSS {
+ public static int count = 0;
public GSS() { }
private Phase.Node[] reducing_list = null;
singularReductions = new IntPairMap<Forest>();
expectedInhibit.clear();
expectedInhibit.addAll(inhibited);
+ reset = false;
good = false;
closed = false;
reducing = false;
}
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) {
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);
reset();
reduce();
}
+ count = 0;
}
+ private boolean reset = false;
class Reset extends RuntimeException { }
/** perform all shift operations, adding promoted nodes to <tt>next</tt> */
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();
if (s.charAt(i)=='\\' && i<s.length()-1) ret.append(s.charAt(++i));
else ret.append(s);
}
- return ANSI.purple(ret.toString());
+ return /*ANSI.purple(ret.toString())*/ret.toString();
}
public static String error(String message, Object token, Iterable<Node> nodes) {
String lookAhead = token==null ? "<EOF>" : token.toString();
StringBuffer ret = new StringBuffer();
ret.append("\n ");
ret.append(message);
+ /*
HashMap<String,HashSet<String>> errors = new HashMap<String,HashSet<String>>();
for(Node n : nodes) {
//System.out.println(n.state);
ret.append("\n");
}
}
+ */
return ret.toString();
}
import java.lang.reflect.*;
/** a tree (or node in a tree); see jargon.txt for details */
-public class Tree<T> extends PrintableTree<Tree<T>> implements Iterable<Tree<T>> {
+public class Tree<T>
+ extends PrintableTree<Tree<T>>
+ implements Iterable<Tree<T>>,
+ GraphViz.ToGraphViz {
final T head;
Tree<T>[] children;
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; }
}
+
+
+
+
+
+
+
+
+
+
+
+
+
// 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[] { }),
+
+
+
+
+
+
+
+
+
+
+
+
+
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+""; }
}
public boolean isHidden();
}
+ public void show() throws IOException {
+ Runtime.getRuntime().exec(new String[] { "dot", "-Tsvg" });
+ }
+
public void dump(PrintWriter pw) {
IdentityHashMap<Node,Node> done = new IdentityHashMap<Node,Node>();
pw.println("digraph G { rankdir=LR; \n");
}
for(Node n : ihm.values()) n.edges(pw);
pw.println("}\n");
+ pw.flush();
}
}
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 {