X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmisc%2FMetaGrammar.java;h=1c563e8421cee540996e277d92bb474d5ed639a8;hp=fe92f6392b4856150a4c4550fab6131c0a3184d5;hb=96f3b65f99a63e97b2a9345e00b12aeab01d9548;hpb=624e7fac78d26d8106c6e96330378d25319cf125 diff --git a/src/edu/berkeley/sbp/misc/MetaGrammar.java b/src/edu/berkeley/sbp/misc/MetaGrammar.java index fe92f63..1c563e8 100644 --- a/src/edu/berkeley/sbp/misc/MetaGrammar.java +++ b/src/edu/berkeley/sbp/misc/MetaGrammar.java @@ -35,11 +35,11 @@ public class MetaGrammar extends ReflectiveWalker { public Element _rightparen_(Object e) { return SELF; } public PreSequence _amp_(PreSequence p, Object[] o) { - p.needs.add(new PreSequence(o, null, true)); + p.needs.add(new PreSequence(o, null, true).buildSequence(null, true, false)); return p; } public PreSequence _amp__tilde_(PreSequence p, Object[] o) { - p.hates.add(new PreSequence(o, null, true)); + p.hates.add(new PreSequence(o, null, true).buildSequence(null, true, false)); return p; } @@ -126,30 +126,6 @@ public class MetaGrammar extends ReflectiveWalker { return CharToken.set(ret); } - public String sify(Object arg) { - if (arg==null) return ""; - if (arg instanceof String) return (String)arg; - Object[] args = (Object[])arg; - while(true) { - args = Reflection.lub(args); - if (args instanceof String[]) { - StringBuffer ret = new StringBuffer(); - for(String s : ((String[])args)) ret.append(s); - return ret.toString(); - } - if (args instanceof Character[]) break; - if (!(args instanceof Object[])) break; - args = (Object[])args[0]; - } - if (args instanceof Character[]) { - char[] c = new char[args.length]; - for(int i=0; i temp = new HashSet(); for(PreSequence pre : s[i]) { - pre.hatess.addAll(seqs); + pre.hates.addAll(seqs); Sequence seq = pre.buildSequence(n, false, dropAll); temp.add(seq); - //for(Sequence dom : seqs) seq.hates.add(dom); n.add(seq); } seqs.addAll(temp); @@ -227,9 +202,8 @@ public class MetaGrammar extends ReflectiveWalker { } public static class PreSequence { - public final HashSet needs = new HashSet(); - public final HashSet hates = new HashSet(); - public final HashSet hatess = new HashSet(); + public final HashSet needs = new HashSet(); + public final HashSet hates = new HashSet(); public /*final*/ String tag; public final Object[] o; public final boolean keeper; @@ -265,21 +239,10 @@ public class MetaGrammar extends ReflectiveWalker { } public Sequence buildSequence(Union u) { return buildSequence(u, false, false); } public Sequence buildSequence(Union u, boolean lame, boolean dropAll) { - - HashSet and = new HashSet(); - HashSet not = new HashSet(); - for(PreSequence p : needs) { - Sequence ps = p.buildSequence(u, true, dropAll); - u.add(ps); - and.add(ps); - } - for(Sequence p : hatess) not.add(p); - for(PreSequence p : hates) { - Sequence ps = p.buildSequence(u, true, dropAll); - u.add(ps); - not.add(ps); - } - + HashSet and = needs; + HashSet not = hates; + for(Sequence s : and) u.add(s); + for(Sequence s : not) u.add(s); HashSet set = new HashSet(); Element[] expansion = expand(u, set); boolean keeper = this.keeper; @@ -346,29 +309,6 @@ public class MetaGrammar extends ReflectiveWalker { public static final Tree meta = - - - - - - - - - - - - - - - - - - - - - - - // DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED new Tree(null, "gram", new Tree[] { new Tree(null, null, new Tree[] { }), new Tree(null, "grammar", new Tree[] { new Tree(null, null, new Tree[] { new Tree(null, "::=", new Tree[] { new Tree(null, null, new Tree[] { new Tree(null, "s", new Tree[] { })}), @@ -931,3 +871,4 @@ new Tree(null, "gram", new Tree[] { new Tree(null, null, new Tree[] { }), +