Copyright (C) 2001, Geert Vernaeve. All Rights Reserved.
package gve.calc.logic; import java.util.Hashtable; import java.util.Enumeration; import gve.calc.formula.*;
A FallbackMatcher uses another Matcher (the fallback) if it cannot find the type or value of a given symbol. It never modifies the contents of the fallback.
public class FallbackMatcher extends Matcher { private Matcher fallback; public FallbackMatcher(Matcher fallback) { this.fallback = fallback; } public Object clone() { throw new Error("sorry, no clone (yet)."); } public Part getPatternType(String symbol) { Part result = super.getPatternType(symbol); if (result == null) result = fallback.getPatternType(symbol); return result; } public Part getPatternType(Identifier symbol) { return getPatternType(symbol.getString()); } public Part getTomatchType(String symbol) { Part result = super.getTomatchType(symbol); if (result == null) result = fallback.getTomatchType(symbol); return result; } public Part getMatchedValue(String symbol) { Part result = super.getMatchedValue(symbol); if (result == null) result = fallback.getMatchedValue(symbol); return result; } public Enumeration tomatchSymbols() { return new FallbackEnumeration(super.tomatchSymbols(),fallback.tomatchSymbols()); } public Enumeration matchedSymbols() { return new FallbackEnumeration(super.matchedSymbols(),fallback.matchedSymbols()); } public void dump() { fallback.dump(); super.dump(); } protected boolean isFunction(String fname) { if(super.isFunction(fname)) return true; return fallback.isFunction(fname); } }