⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setmn.java

📁 JAVA在编译原理上的应用。
💻 JAVA
字号:
package lolo.scans;/** A recognizer class to scan for many characters from a set of characters.  * * @author <a href="http://www.inf.uos.de/bernd" target="_blank">Bernd K&uuml;hl</a>           (<a href="mailto:bernd@informatik.uni-osnabrueck.de">bernd@informatik.uni-osnabrueck.de</a>) */public class SetMN extends Set {    /** The lower limit. */    protected final int m;    /** The upper limit. */    protected final int n;    /** Constructs a recognizer which scans at least <tt>m</tt> and at most <tt>n</tt> characters.     * If <tt>inside</tt> is <tt>true</tt> the characters have to be inside <tt>set</tt>,     * else they have to be oustide of <tt>set</tt>.     *     * @param set the set of characters.     * @param inside marks if the symbol characters have to be inside or outside <tt>set</tt>.     * @param m the minimal number of characters.     * @param n the maximum number of characters.     */    public SetMN(String set, boolean inside, int m, int n) throws IllegalArgumentException {        super(set, inside);        if (m < 1)            throw new IllegalArgumentException("m < 1");        if (n < m)            throw new IllegalArgumentException("n <= m");        this.m = m;        this.n = n;    }        /** Counts the current number of recognized characters. */    protected transient int jog;    public void reset() {        jog = 0;    }        public State nextChar(char ch) {        jog ++;        boolean b = inside ? set.indexOf(ch) >= 0 : set.indexOf(ch) < 0;        return stateObject.set(            b && jog < n,	// more            b && jog >= m	// found        );    }    /** Indicates whether some other object is &quot;equal to&quot; this one.     *      * @return whether some other object is &quot;equal to&quot; this one.     */    public boolean equals(Object o) {        if (o == null || !(o instanceof SetMN)) return false;        if (this == o) return true;        SetMN setmn = (SetMN) o;        return setmn.m == m && setmn.n == n && setmn.inside == inside && setmn.set.equals(set);    }    /** Returns a hash code value for this object.     *     * @return a hash code value for this object.     */    public int hashCode() {        return set.hashCode()+            new Integer(m).hashCode()+            new Integer(n).hashCode()+            new Boolean(inside).hashCode();    }        /** Returns a string representation of the object.     *     * @return a string representation of the object.     */    public String toString() {        return getClass().getName()+"["+set+","+inside+","+m+","+n+"]";    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -