slashslashcomment.java

来自「JAVA在编译原理上的应用。」· Java 代码 · 共 54 行

JAVA
54
字号
package lolo.scans;/** A recognizer class to scan for C++ comments: all characters from <tt>//</tt> up to the end of line.  * <p>By default these symbols 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 SlashSlashComment extends Scan {    /** Sets <tt>ignore</tt> to <tt>true</tt>.     *     * @see lolo.Scan#ignore     */    {        ignore = true;    }    /** The legal characters. */ // A means ANY    protected static final String chars = "A/\r\n";    /** The state table. */    protected static final int newState [][] = {        // current state, input => newstate        // ANY  /  \r   \n        {  4,   1,  4,  4   },  // state 0, find first /        {  4,   2,  4,  4   },  // state 1, okay and need second /        {  2,   2,  3,  3   }   // state 2, okay and need more characters                                // state 3, comment found                                // state 4, error	};    /** The current state. */    protected transient int state;        public void reset() {        state = 0;    }        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;        state = newState[state][input];        switch(state) {            case 4:	 break;    // error state, parse ends            case 0:	 new RuntimeException("illegal state "+state); // cann't be..            case 1:            case 2:	 more = true; break;            case 3:	 found = true; break;            default: new RuntimeException("illegal state "+state); // cann't be..        }                            return stateObject.set(more, found);    }}

⌨️ 快捷键说明

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