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

📄 flt.java

📁 JAVA在编译原理上的应用。
💻 JAVA
字号:
package lolo.scans;/** A class to scan for floating point numbers. Legal floating point numbers are: * <ul type=disc> * <li><tt>22</tt>, <tt>22.</tt>, <tt>22.2</tt>, <tt>.22</tt> * <li><tt>22e2</tt>, <tt>22.e2</tt>, <tt>22.2e2</tt>, <tt>.22e2</tt> * <li><tt>22e+2</tt>, <tt>22.e+2</tt>, <tt>22.2e+2</tt>, <tt>.22e+2</tt> * <li><tt>22e-2</tt>, <tt>22.e-2</tt>, <tt>22.2e-2</tt>, <tt>.22e-2</tt> * </ul> * * A leading sign (<tt>+</tt> or <tt>-</tt>) can be switched on or off. * * @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 Flt extends Scan {    /** The legal characters. */    protected static final String chars = "+-.0123456789eE";    /** The state table. */    protected static final int newState [][] = {        // current state, input => newstate        //+  -  .  0  1  2  3  4  5  6  7  8  9  e  E        { 8, 8, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 8 },  // state 0        { 8, 8, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 8 },  // state 1        { 8, 8, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5 },  // state 2        { 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8 },  // state 3        { 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5 },  // state 4        { 6, 6, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8 },  // state 5        { 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8 },  // state 6        { 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8 },  // state 7        { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }   // state error    };    /** The current state. */    protected transient int state;        /** Does this recognizer scan a leading sign. */    protected boolean allowLeadingSign;        /** Returns wether a leading sign is scanned.     *     * @return returns wether a leading sign is scanned.     */    public boolean getAllowLeadingSign() { return allowLeadingSign; }    /** Constructs a Flt and sets wether a leading sign is scanned.     *     * @params bol marks if a leading sign is scanned.     */    public Flt(boolean bol) {        newState[0] = (allowLeadingSign = bol) ?            new int[] { 1, 1, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 8 } :            new int[] { 8, 8, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 8 };    }    /** Constructs a Flt and sets no leading sign. */    public Flt() {        this(false);    }        public void reset() {        state = 0;//System.err.println("\treset "+this);    }        public State nextChar(char ch) {        // is ch a legal input character?        int input;        if ((input = chars.indexOf((int) ch)) < 0)            return stateObject.set(                false,  // more                false   // found            );            boolean found = false, more = false;//System.err.print("\told state "+state+", input "+input+", ch "+ch+", new state ");        state = newState[state][input];//System.err.println(state);        switch(state) {            case 8:	 break;    // error state, parse ends            case 0:	 new RuntimeException("illegal state "+state); // cann't be..            case 1:	 more = true; break;            case 2:	 found = more = true; break;            case 3:	 more = true; break;            case 4:	 found = more = true; break;            case 5:	 more = true; break;            case 6:	 more = true; break;            case 7:	 found = more = true; break;            default: new RuntimeException("illegal state "+state); // cann't be..        }                            return stateObject.set(more, found);    }    /** Indicates whether some other object is &quot;equal to&quot; this one.     *     * @return Indicates whether some other object is &quot;equal to&quot; this one.     */    public boolean equals(Object obj) {        if (obj == null || !(obj instanceof Flt)) return false;        return this.allowLeadingSign == ((Flt) obj).allowLeadingSign;    }    }

⌨️ 快捷键说明

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