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

📄 lexerautomaton.java

📁 用JAVA写的shell程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    private static final int I_END_OF_INPUT    = 2;
    private static final int I_HAT             = 3;
    private static final int I_LT              = 4;
    private static final int I_GT              = 5; 
    private static final int I_SEMI            = 6; 
    private static final int I_DOLLAR          = 7;
    private static final int I_SINGLE_QUOTE    = 8;
    private static final int I_DOUBLE_QUOTE    = 9;
    private static final int I_ESCAPE          = 10;
    private static final int I_OTHER           = 11;
    private static final int I_EOL             = 12;
    private static final int I_AMPERSAND       = 13;
    private static final int I_BANG            = 14;
    private static final int N_INPUT_CLASSES   = 15;

    private Transition[][] _transition;
    private int _state;
    private char _char;
    private int _char_classification;
    private int _token_type;
    private StringBuffer _token;

    //------------------------------------------------------------

    abstract class Transition
    {
        abstract void apply();
    }

    //------------------------------------------------------------

    class Transition_UNKNOWN_HAT extends Transition
    {
        void apply()
        {
            _state = S_PIPE;
            _token_type = Lexer.PIPE;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_LT extends Transition
    {
        void apply()
        {
            _state = S_REDIRECT_IN;
            _token_type = Lexer.REDIRECT_IN;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_GT extends Transition
    {
        void apply()
        {
            _state = S_REDIRECT_OUT;
            _token_type = Lexer.REDIRECT_OUT;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_SEMI extends Transition
    {
        void apply()
        {
            _state = S_SEPARATOR;
            _token_type = Lexer.SEPARATOR;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_DOLLAR extends Transition
    {
        void apply()
        {
            _state = S_VARIABLE;
            _token_type = Lexer.VARIABLE;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_QUOTE_1 extends Transition
    {
        void apply()
        {
            _state = S_QUOTE_1;
            _token_type = Lexer.QUOTED_STRING;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_QUOTE_2 extends Transition
    {
        void apply()
        {
            _state = S_QUOTE_2;
            _token_type = Lexer.QUOTED_STRING;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_WHITESPACE extends Transition
    {
        void apply()
        {
            // Stay in S_UNKNOWN. Don't add whitespace to token.
        }
    }

    class Transition_UNKNOWN_AMPERSAND extends Transition
    {
        void apply()
        {
            _state = S_BACKGROUND;
            _token_type = Lexer.AMPERSAND;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_ESCAPE extends Transition
    {
        void apply()
        {
            _state = S_ESCAPED;
            _token_type = Lexer.STRING;
        }
    }

    class Transition_UNKNOWN_BANG extends Transition
    {
        void apply()
        {
            _state = S_BANG;
            _token.append(_char);
        }
    }

    class Transition_UNKNOWN_EOL extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_UNKNOWN_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_STRING;
            _token_type = Lexer.STRING;
            _token.append(_char);
        }
    }

    class Transition_PIPE_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_REDIRECT_IN_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_REDIRECT_OUT_GT extends Transition
    {
        void apply()
        {
            _state = S_APPEND;
            _token_type = Lexer.APPEND;
            _token.append(_char);
        }
    }

    class Transition_REDIRECT_OUT_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_SEPARATOR_AMPERSAND extends Transition
    {
        void apply()
        {
            _state = S_BACKGROUND;
            _token_type = Lexer.AMPERSAND;
            _token.append(_char); 
       }
    }

    class Transition_SEPARATOR_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_VARIABLE_OTHER extends Transition
    {
        void apply()
        {
            _state = S_VARIABLE_NAME;
            _token.append(_char);
        }
    }

    class Transition_VARIABLE_DEFAULT extends Transition
    {
        void apply()
        {
            error();
        }
    }

    class Transition_STRING_ESCAPE extends Transition
    {
        void apply()
        {
            _state = S_ESCAPED;
            _token.append(_char);
        }
    }

    class Transition_STRING_AMPERSAND extends Transition
    {
        void apply()
        {
            _state = S_BACKGROUND;
            _token_type = Lexer.AMPERSAND;
            _token.append(_char);
        }
    }

    class Transition_STRING_OTHER extends Transition
    {
        void apply()
        {
            // Stay in S_STRING
            _token.append(_char);
        }
    }

    class Transition_STRING_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_QUOTE_1_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_QUOTED_1;
            _token.append(_char);
        }
    }

    class Transition_QUOTE_2_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_QUOTED_2;
            _token.append(_char);
        }
    }

    class Transition_APPEND_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_VARIABLE_NAME_AMPERSAND extends Transition
    {
        void apply()
        {
            _state = S_BACKGROUND;
            _token_type = Lexer.AMPERSAND;
            _token.append(_char);
        }
    }

    class Transition_VARIABLE_NAME_OTHER extends Transition
    {
        void apply()
        {
            // Stay in S_VARIABLE_NAME
            _token.append(_char);
        }
    }

    class Transition_VARIABLE_NAME_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_QUOTED_1_QUOTE_1 extends Transition
    {
        void apply()
        {
            _state = S_QUOTE_1_DONE;
            _token.append(_char);
        }
    }

    class Transition_QUOTED_1_EOL extends Transition
    {
        void apply()
        {
            error();
        }
    }

    class Transition_QUOTED_1_DEFAULT extends Transition
    {
        void apply()
        {
            // Stay in S_QUOTED_1
            _token.append(_char);
        }
    }

    class Transition_QUOTED_2_QUOTE_2 extends Transition
    {
        void apply()
        {
            _state = S_QUOTE_2_DONE;
            _token.append(_char);
        }
    }

    class Transition_QUOTED_2_EOL extends Transition
    {
        void apply()
        {
            error();
        }
    }

    class Transition_QUOTED_2_DEFAULT extends Transition
    {
        void apply()
        {
            // Stay in S_QUOTED_2
            _token.append(_char);
        }
    }

    class Transition_QUOTE_1_DONE_AMPERSAND extends Transition
    {
        void apply()
        {
            _state = S_BACKGROUND;
            _token_type = Lexer.AMPERSAND;
            _token.append(_char);
        }
    }

    class Transition_QUOTE_1_DONE_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_QUOTE_2_DONE_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_QUOTE_2_DONE_AMPERSAND extends Transition
    {
        void apply()
        {
            _state = S_BACKGROUND;
            _token_type = Lexer.AMPERSAND;
            _token.append(_char);
        }
    }

    class Transition_ESCAPED_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_STRING;
            _token.append(_char);
        }
    }

    class Transition_BANG_BANG extends Transition
    {
        void apply()
        {
            _state = S_LAST_COMMAND;
            _token_type = Lexer.LAST_COMMAND;
            _token.append(_char);
        }
    }

    class Transition_BANG_OTHER extends Transition
    {
        void apply()
        {
            _state = S_DONE;
            _token_type = Lexer.EARLIER_COMMAND;
            _token.append(_char);
        }
    }

    class Transition_BANG_DEFAULT extends Transition
    {
        void apply()
        {
            error();
        }
    }

    class Transition_LAST_COMMAND_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_EARLIER_COMMAND_OTHER extends Transition
    {
        void apply()
        {
            // Stay in S_EARLIER_COMMAND
            _token.append(_char);
        }
    }

    class Transition_EARLIER_COMMAND_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_BACKGROUND_DEFAULT extends Transition
    {
        void apply()
        {
            _state = S_DONE;
        }
    }

    class Transition_DONE_DEFAULT extends Transition
    {
        void apply()
        {
            error();
        }
    }

    class Transition_ERROR_DEFAULT extends Transition
    {
        void apply()
        {
            error();
        }
    }
}

⌨️ 快捷键说明

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