Copyright (C) 2001, Geert Vernaeve. All Rights Reserved.
package gve.calc.logic;
import gve.calc.formula.*;
publicclassMultipleMatchedimplementsMatched {
privatePart []tomatch;
privatePart []pattern;
privateMatched action;
privateMatcher matcher;
privateint count = 0;
publicMultipleMatched(Part []tomatch,Part []pattern,Matched action,Matcher m) {
if (tomatch.length != pattern.length)
thrownew Error("tomatch[] and pattern[] have different lengths");
//System.out.println("MultipleMatched with "+pattern.length+" matches");
this.tomatch = tomatch;
this.pattern = pattern;
this.action = action;
matcher = m;
}
Match tomatch[i] to pattern[i]. When all of them match, call action.foundMatch().
publicboolean match() {
return foundMatch(matcher);
}
publicboolean foundMatch(Matcher m) {
// Try to match tomatch[count] with pattern[count]
if (count == tomatch.length)
// found a match!
return action.foundMatch(m);
count++;
//System.out.println("multiplematch: match "+(count-1));
boolean result = m.match(tomatch[count-1],pattern[count-1],this);
//System.out.println("multiplematch: match "+(count-1)+" is "+result);
count--;
return result;
}
}