public void testMatch() { ATerm t = _factory.parse("node(\"Pico-eval\",box,182,21,62,26)"); List<Object> result = t.match("node(<str>,<fun>,<int>,<int>,<int>,<int>)"); test_assert(result != null); t = _factory.parse("f(1,2,3)"); result = t.match("f(1,2,3)"); test_assert(result != null); // System.out.println("pass: testMatch"); }
public ATerm oneStepInnermost(ATerm subject) { List<Object> list; // fib(zero) -> suc(zero) list = subject.match(lhs[0]); if (list != null) { return rhs[0]; } // fib(suc(zero)) -> suc(zero) list = subject.match(lhs[1]); if (list != null) { return rhs[1]; } // fib(suc(suc(X))) -> plus(fib(X),fib(suc(X))) list = subject.match(lhs[2]); if (list != null) { final ATerm X = (ATerm) list.get(0); final ATerm X1 = normalize(_factory.makeAppl(fib, X)); final ATerm X2 = normalize(_factory.makeAppl(fib, _factory.makeAppl(suc, X))); return _factory.makeAppl(plus, X1, X2); } // plus(zero,X) -> X list = subject.match(lhs[3]); if (list != null) { return (ATerm) list.get(0); } // plus(suc(X),Y) -> plus(X,suc(Y))) list = subject.match(lhs[4]); if (list != null) { return _factory.make(rhs[4], list); } return fail; }
final List<Object> submatches = arg.match(pattern_arg); if (submatches == null) return false;
list = subject.match(lhs[ruleNumber]); if (list != null) { return rhs[ruleNumber]; } ruleNumber++; list = subject.match(lhs[ruleNumber]); if (list != null) { return rhs[ruleNumber]; } ruleNumber++; list = subject.match(lhs[ruleNumber]); if (list != null) list = subject.match(lhs[ruleNumber]); if (list != null) { return _factory.make(rhs[ruleNumber], list); } ruleNumber++; list = subject.match(lhs[ruleNumber]); if (list != null) { return _factory.make(rhs[ruleNumber], list); } ruleNumber++; list = subject.match(lhs[ruleNumber]); if (list != null) list = subject.match(lhs[ruleNumber]); if (list != null)
test(T[0].match("f(1,2,3)") != null, "match-1a"); List<Object> result = T[1].match("<term>"); result = T[1].match("[<list>]"); result = T[1].match("[<int>,<list>]"); result = _factory.parse("f(a)").match("f(<term>)"); result = _factory.parse("f(a)").match("<term>"); result = _factory.parse("f(a)").match("<fun(<term>)>"); result = _factory.parse("a").match("<fun>"); result = T[0].match("f(1,<int>,3)"); test(result != null && result.size() == 1 && result.get(0).equals(new Integer(2)), "match-3"); result = T[1].match("[<list>]"); test(result != null && result.size() == 1 && result.get(0).equals(T[1]), "match-6a"); result = T[1].match("[<int>,<list>]"); test(result != null && result.size() == 2 && result.get(0).equals(new Integer(1)), "match-6b"); test(result != null && result.get(1).equals(_factory.parse("[2,3]")), "match-6c"); result = empty.match("[]"); result = empty.match("[<list>]");
List<Object> submatches = _first.match(l.getFirst()); if (submatches == null) return false;