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

📄 quotedchar.java

📁 JAVA在编译原理上的应用。
💻 JAVA
字号:
package lolo.scans;/** A class to scan for one quoted character. * * @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 QuotedChar extends Scan {    /** Holds the unescaped recognized quoted character. */    protected final char[] found = new char[1];    /** Marks the current state. */    protected transient boolean start, middle, end;    /** Is the character escaped? */    protected transient boolean escape;         public void reset() {        start = true;        middle = end = escape = false;    }        /** The quote character. */    protected final char quote;        /** Returns the quote character.     *     * @return the quote character.     */    protected char getQuote() {        return quote;    }    /** Just calls <tt>this('\'')</tt>. */    public QuotedChar() {        this('\'');    }    /** Constructs a recognizer to scan for a quoted character. <tt>quote</tt> is     * the quote character.     *     * @param quote the quoted character.     */    public QuotedChar(char quote) {        if (quote == '\\')            throw new IllegalArgumentException("illegal quote character \\");        this.quote = quote;    }        public State nextChar(char ch) {        // start state        if (start) {            start = false;            middle = true;            return stateObject.set(                ch == quote,    // more                false           // found            );        }                // middle state        if (middle) {            if (!escape)    // nicht im escape modus                if (ch == '\\')                    escape = true;                else {                    end = true; middle = false;                    found[0] = ch;                }            else {          // escape modus                if (ch == quote)                    found[0] = quote;                else switch (ch) {                    case 't':	found[0] = '\t'; break;                    case 'n':	found[0] = '\n'; break;                    case '\\':	found[0] = '\\'; break;                    case 'r':	found[0] = '\r'; break;                    case 'b':	found[0] = '\b'; break;                    default:	return stateObject.set(                                    false,   // more                                    false   // found                                );                }                end = true; middle = false;            }            return stateObject.set(                true,   // more                false   // found            );        }                // end state	    return stateObject.set (            false,	    // more            ch == quote	// found	    );    }        /** Returns a hash code value for this object.     *     * @return a hash code value for this object.     */    public int hashCode() {        return new Character(quote).hashCode();    }    /** Indicates whether some other object is &quot;equal to&quot; this one.     *      * @return <tt>true</tt> the argument is a <tt>QuotedChar</tt> and uses the same quote character,     * <tt>false</tt> otherwise.     */    public boolean equals(Object o) {        if (o == null || !(o instanceof QuotedChar))            return false;        return this == o || quote == ((QuotedChar) o).quote;    }        public void action(char [] buffer, int off, int len) {        if (action != null)            action.action(this, found, 0, 1);    }    /** Returns a string representation of the object.     *     * @return a string representation of the object.     */    public String toString() {        return getClass().getName()+"["+quote+"]";    }}

⌨️ 快捷键说明

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