public class MetaGrammar {
- public static boolean harsh = false;
+ public static boolean harsh = true;
public static void main(String[] args) throws Exception {
if (args.length != 2) {
}
public static Union make(Tree t, String s) { return make(t, s, new ReflectiveMeta()); }
public static Union make(Tree t, String s, ReflectiveMeta rm) {
+ System.out.println("Head: " + t.head());
Tree.TreeFunctor<Object,Object> red = (Tree.TreeFunctor<Object,Object>)t.head();
MG.Grammar g = (MG.Grammar)red.invoke(t.children());
Context cx = new Context(g,rm);
public static class MG {
- public static @bind.as("grammar") class Grammar {
+ public static @bind.as Object grammar(Object[] o) {
+ if (o==null) return null;
+ if (o[0] != null && o[0] instanceof Grammar) return o[0];
+ Grammar g = new Grammar();
+ g.nonterminals = (NonTerminal[])Reflection.lub((Object[])o);
+ return g;
+ }
+ public static @bind.as class Grammar {
public NonTerminal get(String s) {
for(NonTerminal nt : nonterminals)
if (nt.name.equals(s))
return nt;
return null;
}
- public @bind.arg("NonTerminal") NonTerminal[] nonterminals;
+ public @bind.arg NonTerminal[] nonterminals;
public String toString() {
String ret = "[ ";
for(NonTerminal nt : nonterminals) ret += nt + ", ";
}
public static class NonTerminal extends Un {
public String name = null;
- public @bind.as("=") NonTerminal(@bind.arg("Word") String name,
+ public @bind.as("NonTerminal") NonTerminal(@bind.arg("Word") String name,
@bind.arg("RHS") Seq[][] sequences) {
this.name = name;
this.sequences = sequences;
else if (tag!=null) {
ret = cx.rm.resolveTag(tag, cx.cnt, els, labels, drops);
} else {
- int idx = -1;
- for(int i=0; i<els.length; i++)
- if (!drops[i])
- if (idx==-1) idx = i;
- else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(els,false));
- if (idx != -1) ret = Sequence.singleton(els, idx);
- else ret = Sequence.drop(els, false);
+ ret = cx.rm.tryResolveTag(tag, cx.cnt, els, labels, drops);
+ if (ret == null) {
+ int idx = -1;
+ for(int i=0; i<els.length; i++)
+ if (!drops[i])
+ if (idx==-1) idx = i;
+ else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(els,false));
+ if (idx != -1) ret = Sequence.singleton(els, idx);
+ else ret = Sequence.drop(els, false);
+ }
}
if (this.follow != null)
ret.follow = infer(this.follow.build(cx));