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

📄 ccomment.java

📁 JAVA在编译原理上的应用。
💻 JAVA
字号:
package lolo.scans;/** A recognizer class to scan for (optional nested) C comments.  * <p>By default <tt>CComment</tt> will be ignored. * * @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 CComment extends SlashSlashComment {    /** Scan for nested comments? */    protected final boolean nested;    /** Counts the number of open and nested comments. */    protected transient int numberOpenComments;        /** Constructs a recognizer which scans for unnnested C comments. */    public CComment() {        this(false);    }    /** Constructs a recognizer which scans for C comments.     * If <tt>nested</tt> is <tt>true</tt>, the recognizer scans for nested comments.     *      * @param nested marks if the recognizers scans nested comments.     */    public CComment(boolean nested) {        this.nested = nested;    }        public void reset() {        state = numberOpenComments = 0;    }    /** The legal characters. */ // A means ANY    protected static final String chars = "A*/";    /** The state table. */    protected static final int newState [][] = {	// current state, input -> newstate	// ANY  *   /  	{  7,   7,  1   },  // state 0, find /	{  7,   2,  7   },  // state 1, find * for /*	{  2,   5,  3   },  // state 2, find * for */ or / for nested /*	{  2,   4,  3   },  // state 3, find * for nested /*	{  2,   5,  3   },	// state 4, find * for */ or / for nested /*	{  2,   5,  6   }	// state 5, find / for */	                    // state 6, comment end found, check open comment count for end	                    // state 7, error    };    public State nextChar(char ch) {        // is ch a legal input character?        int input = chars.indexOf(ch);        if (input < 0) input = 0;                boolean found = false, more = false;        if (state == 1 && newState[state][input] == 2)            numberOpenComments++;	// found /*        state = newState[state][input];        switch(state) {            case 7:	break;    // error state, parse ends            case 0:	new RuntimeException("illegal state "+state); // cann't be..            case 1: //	/            case 2:	//	/* ...            case 3:	//	/* ... /            case 5:	// /* .... *                    more = true; break;            case 4:	// /* ... /*                    numberOpenComments++;                    more = true; break;            case 6:	// /* */                    numberOpenComments--;                    if (nested && numberOpenComments > 0) {                        more = true;                        state = 2; // find * for */                    } else                        found = true;                    break;            default: new RuntimeException("illegal state "+state); // cann't be..        }                return stateObject.set(more, found);    }        /** Returns a string representation.     *     * @return a string representation.     */    public String toString() {        return getClass().getName()+(nested ? "[nested]" : "");    }}

⌨️ 快捷键说明

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