X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FMetaGrammarBindings.java;h=d33758c87374e7bb3818ff0e8fff7b2384fb869c;hp=dc35dfc3180c5ecf84e1ffaee147a4652d8784a9;hb=f3b4ef0d81d572694905f4fe284cac6311a29ea4;hpb=babae49de7b777a5847f277bb74c88e77c67568a diff --git a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java index dc35dfc..d33758c 100644 --- a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java +++ b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java @@ -15,7 +15,13 @@ public class MetaGrammarBindings { /** A grammar (a set of nonterminals) */ public static class GrammarNode extends HashMap { public @bind.as("Grammar") GrammarNode(NonTerminalNode[] nonterminals) { - for(NonTerminalNode nt : nonterminals) this.put(nt.name, nt); } + for(NonTerminalNode nt : nonterminals) { + if (nt==null) continue; + if (this.get(nt.name)!=null) + throw new RuntimeException("duplicate definition of nonterminal \""+nt.name+"\""); + this.put(nt.name, nt); + } + } public String toString() { String ret = "[ "; for(NonTerminalNode nt : values()) ret += nt + ", "; @@ -36,14 +42,14 @@ public class MetaGrammarBindings { public abstract static class UnionNode extends ElementNode { public Seq[][] sequences; - public void build(Context cx, Union u) { + public void build(Context cx, Union u, NonTerminalNode cnt) { HashSet bad2 = new HashSet(); for(int i=0; i bad2 = new HashSet(); Union urep = new Union(); @@ -84,7 +95,7 @@ public class MetaGrammarBindings { if (sequences.length==1) u2 = u; for(int j=0; j)Atom.toAtom(e).complement()); + return infer((Topology)Atom.toAtom(e).complement().minus(CharRange.braces)); } }; } public static @bind.as("Word") String word(String s) { return s; } @@ -359,7 +372,7 @@ public class MetaGrammarBindings { public Context(Tree t, GrammarBindingResolver rm) { this.rm = rm; Tree.TreeFunctor red = (Tree.TreeFunctor)t.head(); - this.grammar = (GrammarNode)red.invoke(t.children()); + this.grammar = (GrammarNode)red.invoke(t); } public Union peek(String name) { return map.get(name); } public void put(String name, Union u) { map.put(name, u); } @@ -374,7 +387,7 @@ public class MetaGrammarBindings { } else { String old = cnt; cnt = name; - nt.build(this, ret); + nt.build(this, ret, nt); cnt = old; } return ret;