为什么会这样(1.输入命令后我的所有命令都不起作用,并且输入1行输入后输入停止工作)?...

所以我要在Dint中添加浮点数/双打,对吗? 好吧,当我添加双打时,Dint开始表现得很奇怪,我对Java一无所知,而导致此错误的原因是Java不会停止,并且在编译过程中不会引发任何错误。 感谢您的帮助并阅读我的帖子! Dint.java

public class Dint {
    public static void main(String[] args) {
        System.out.println("Welcome Dint ISE v0.1.1! use \"help\" for commands, and use \"changelog\" for recent changes!\n");
        Scanner Input = new Scanner(System.in);
        String In = Input.nextLine();
        boolean Program = true;
        String[] PFuncs = new String[500];
        String[] PFuncVals = new String[500];
        String[] PStrs = new String[1000];
        String[] PStrVals = new String[1000];
        String[] PInts = new String[1000];
        int[] PIntVals = new int[1000];
        String[] PDoubles = new String[1000];
        double[] PDoubleVals = new double[1000];
        parser DintCode = new parser();
        while(Program) {
            String tok = "";
            String string = "";
            String command = "";
            String Number_string = "";
            String Double_string = "";
            String Backup_Tok = "";
            String FCS = "";
            boolean Pbool = false; 
            int Number_numberInt = 0;
            double Double_doubleDouble = 0.00;
            int[] numberS = new int[256];
            double[] doubleS = new double[256];
            int state = 0;
            int castStringTo = 0;
            int castIntTo = 0;
            int castIntNameTo = 0;
            int castIntValTo = 0;
            int castDoubleTo = 0;
            int castDoubleNameTo = 0;
            int castDoubleValTo = 0;
            int castStrNameTo = 0;
            int castStrValTo = 0;
            int castFuncNameTo = 0;
            int castFuncValTo = 0;
            String[] strings = new String[256];
            for(int i = 0; i < In.length();) {
                tok += In.charAt(i);
                if(state == 1) {
                    string += In.charAt(i);
                    if(tok.equals("\\\"")) {
                        string += "\"";
                    } else if(tok.equals("\\n")) {
                        string += "\n";
                    }
                    if(!(tok.equals("\""))) {
                        tok = "";
                    }
                } else if(state == 2) {
                    Backup_Tok += tok;
                    if(tok.equals("0") || tok.equals("1") || tok.equals("2") || tok.equals("3") || tok.equals("4") || tok.equals("5") || tok.equals("6") || tok.equals("7") || tok.equals("8") || tok.equals("9")) {
                        Number_string += tok;
                        tok = "";
                    }
                    if(Backup_Tok.equals("<Random>")) {
                        Backup_Tok = "";
                        Random rand = new Random();
                        Integer Rand_PNumber = rand.nextInt(100);
                        Rand_PNumber += 1;
                        Number_string = Rand_PNumber.toString();
                        tok = "";
                        Rand_PNumber = 0;
                    }
                    if(!(tok.equals("|"))) {
                        tok = "";
                    }
                } else if(state == 3) {
                    FCS += In.charAt(i);
                    if(!(tok == "}")) {
                        tok = "";
                    }
                } else if(state == 4) {
                    Backup_Tok += tok;
                    if(tok.equals("0") || tok.equals("1") || tok.equals("2") || tok.equals("3") || tok.equals("4") || tok.equals("5") || tok.equals("6") || tok.equals("7") || tok.equals("8") || tok.equals("9") || tok.equals(".")) {
                        Number_string += tok;
                        tok = "";
                    }
                    if(Backup_Tok.equals("<pi>")) {
                        Backup_Tok = "";
                        Double_string = "3.14";
                        tok = "";
                    }
                    if(!(tok.equals("/"))) {
                        tok = "";
                    }
                }
                if(tok.equals(" ")) {
                    tok = "";
                } else if(tok.equals("\"") && (state == 0 || state == 1)) {
                    if(state == 0) {
                        state = 1;
                    } else if(state == 1) {
                        state = 0;
                        string = string.substring(0, string.length() - 1);
                        strings[castStringTo] = string;
                        castStringTo++;
                        string = "";
                    }
                    tok = "";
                } else if(tok.equals("|") && (state == 0 || state == 2)) {
                    if(state == 0) {
                        state = 2;
                    } else if(state == 2) {
                        try {
                            state = 0;
                            Number_numberInt = Integer.parseInt(Number_string);
                            numberS[castIntTo] = Number_numberInt;
                            castIntTo++;
                            Number_numberInt = 0;
                        } catch(Exception e) {
                            System.out.println("NoIntError: Tried to parse value <Int> but was returned with <String> = or <Null> = <Blank>\n <Value> = "+Number_string);
                        }
                        Number_string = "";
                } else if(tok.equals("/") && (state == 0 || state == 4)) {
                    if(state == 0) {
                        state = 4;
                    } else if(state == 4) {
                        try {
                            state = 0;
                            Double_doubleDouble = Double.parseDouble(Double_string);
                            doubleS[castDoubleTo] = Double_doubleDouble;
                            castDoubleTo++;
                            Double_doubleDouble = 0;
                        } catch(Exception e) {
                            System.out.println("NoDoubleError: Tried to parse value <Double> but was returned with <String> = or <Null> = <Blank>\n <Value> = "+Number_string);
                        }
                        Double_string = "";
                    }
                    tok = "";
                } else if(tok.equals("{") && state == 0) {
                    if(state == 0) {
                        state = 3;
                    }
                } else if(tok.equals("}")) {
                    if(state == 3) {
                        state = 0;
                        FCS = FCS.substring(0, FCS.length() - 1);
                    }
                } else if(tok.equals("out") && state == 0) {
                    command = "print";
                    tok = "";
                } else if(tok.equals("help") && state == 0) {
                    command = "help";
                    tok = "";
                } else if(tok.equals("exit")) {
                    System.exit(0);
                } else if(tok.equals("int")) {
                    PInts[castIntNameTo] = strings[0];
                    PIntVals[castIntValTo] = numberS[0];
                    tok = "";
                } else if(tok.equals("double")) {
                    PDoubles[castDoubleNameTo] = strings[0];
                    PDoubleVals[castDoubleValTo] = doubleS[0];
                    tok = "";
                } else if(tok.equals("String")) {
                    PStrs[castStrNameTo] = strings[0];
                    PStrVals[castStrValTo] = strings[1];
                    castStrNameTo++;
                    castStrValTo++;
                    tok = "";
                } else if(tok.equals("function")) {
                    PFuncs[castFuncNameTo] = strings[0];
                    PFuncVals[castFuncValTo] = FCS;
                    castFuncNameTo++;
                    castFuncValTo++;
                    FCS = "";
                    tok = "";
                } else if(tok.equals("@Functions")) {
                    for(int iterator = 0; iterator < PFuncs.length;) {
                        if(!(PFuncs[iterator] == null)) {
                            System.out.println("FUNCTION: \""+PFuncs[iterator]+"\" - CODE: "+PFuncVals[iterator]);
                        }
                        iterator++;
                    }
                    tok = "";
                } else if(tok.equals("if")) {
                    command = "if";
                    tok = "";
                } else if((tok.equals("true") || tok.equals("1")) && state == 0) {
                    Pbool = true;
                } else if((tok.equals("false") && tok.equals("0")) && state == 0) {
                    Pbool = false;
                } else if(tok.equals("@GlobalBoolean")) {
                    command = "Bool";
                    tok = "";
                } else if(tok.equals("@Variables")) {
                    for(int iterator = 0; iterator < PStrs.length;) {
                        if(!(PStrs == null)) {
                            System.out.println(PStrs[iterator]+": "+PStrVals[iterator]);
                        }
                        iterator++;
                    }
                    for(int iterator = 0; iterator < PInts.length;) {
                        if(!(PInts == null)) {
                            System.out.println(PInts[iterator]+": "+PIntVals[iterator]);
                        }
                        iterator++;
                    }
                } else if(tok.equals("clr") || tok.equals("cls")) {
                    System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                } else if(tok.equals("@CodeBlock")) {
                    command = "SeeCB";
                    tok = "";
                } else if(tok.equals("changelog")) {
                    command = "changelog";
                    tok = "";
                } else if(tok.equals("PI")) {
                    doubleS[castDoubleTo] = 3.14;
                    castDoubleTo++;
                } else if(tok.equals("<null>")) {
                    strings[castStringTo] = null;
                    castStringTo++;
                } else {
                    boolean somethingFound = false;
                    for(int iterator = 0; iterator < PInts.length;) {
                        if(tok.equals(PInts[iterator])) {
                            numberS[castIntTo] = PIntVals[iterator];
                            somethingFound = true;
                        }
                        iterator++;
                    }
                    for(int iterator = 0; iterator < PStrs.length;) {
                        if(tok.equals(PStrs[iterator])) {
                            strings[castStringTo] = PStrVals[iterator];
                            somethingFound = true;
                        }
                        iterator++;
                    }
                    if(somethingFound == true) {
                        tok = "";
                        break;
                    }
                }
            i++;
            }
        }
    DintCode.parse(command,strings,numberS,doubleS,Pbool,FCS);
    FCS = "";
    In = Input.nextLine();
        }
    }
}
class parser {
    public static void parse(String cmd,String[] strings,int[] nums,double[] dbls,boolean conditions,String codeBlock) {
        if(cmd.equals("print")) {
            try {
                for(int i = 0; i < strings.length; ++i) {
                    if(!(strings[i] == null)) {
                        System.out.println(strings[i]);
                    }
                }
                for(int i = 0; i < nums.length; ++i) {
                    if(!(nums[i] == 0)) {
                        System.out.println(nums[i]);
                    }
                } for(int i = 0; i < dbls.length; ++i) {
                    if(!(dbls[i] == 0.00)) {
                        System.out.println(dbls[i]);
                    }
                }
            } catch(Exception e) {
                System.out.println(e);
            }
        } else if(cmd.equals("help")) {
            if(strings[0] == null || strings[0].equals("")) {
                System.out.println("\"out\":\n\tSYNTAX:\n\t\tout <String | Int: message>\n\tTYPE:\n\t\tCommand\n\tDESCRIPTION:\n\t\tPrints any pending strings/numbers, if there is more than 1 \n\t\tstring/number, each string/number will be printed on a new line.\n\tEXAMPLE:\n\t\tout \"Hello World!\"");
                System.out.println("\"help\":\n\tSYNTAX:\n\t\thelp <String: command>\n\tTYPE:\n\t\tSub-Command\n\tDESCRIPTION:\n\t\tReturns all help info (if no topic is specified) to the user.\n\tEXAMPLE:\n\t\thelp \"help\"");
                System.out.println("\"exit\":\n\tSYNTAX:\n\t\texit\n\tTYPE:\n\t\tCommand\n\tDESCRIPTION:\n\t\tKills the program.\n\tEXAMPLE:\n\t\texit");
                System.out.println("\"int\":\n\tSYNTAX:\n\t\t<String: var name> <Int: value> int\n\tTYPE:\n\t\tObject\n\tDESCRIPTION:\n\t\tCreates a variable of type \"int\".\n\tEXAMPLE:\n\t\t\"MyRandomInt\" |<Random>| int");
                System.out.println("\"double\":\n\tSYNTAX:\n\t\t<String: var name> <Double: value> double\n\tTYPE:\n\t\tObject\n\tDESCRIPTION:\n\t\tCreates a variable of type \"double\".\n\tEXAMPLE:\n\t\t\"MyDouble\" /0.33/ double");
                System.out.println("\"String\":\n\tSYNTAX:\n\t\t<String: var name> <String: value> String\n\tTYPE:\n\t\tObject\n\tDESCRIPTION:\n\t\tCreates a variable of type \"String\".\n\tEXAMPLE:\n\t\t\"myString\" \"Hello World!\" String");
                System.out.println("\"function\":\n\tSYNTAX:\n\t\t<String: var name> {<line of code>} function\n\tTYPE:\n\t\tCommand\n\tDESCRIPTION:\n\t\tCreates a function.\n\tEXAMPLE:\n\t\t\"myFunc\" {out \"Hi!\"} function");
                System.out.println("\"cls\":\n\tSYNTAX:\n\t\tcls\n\tTYPE:\n\t\tSub-Command\n\tDESCRIPTION:\n\t\tClears the screen by adding \\n whitespace.\n\tEXAMPLE:\n\t\tcls");
                System.out.println("\"PI\":\n\tSYNTAX:\n\t\tPI\n\tTYPE:\n\t\tConst\n\tDESCRIPTION:\n\t\tMathematical PI.\n\tEXAMPLE:\n\t\tout PI");
                //System.out.println();
                //System.out.println();
                //System.out.println();
                //System.out.println();
            } else if(strings[0].equals("out")) {
                System.out.println("SYNTAX:\n\tout <String | Int: message>\nTAGS / PARAMETERS:\n\tNone");
            } else if(strings[0].equals("help")) {
                System.out.println("SYNTAX:\n\thelp <String: topic>\nTAGS / PARAMETERS:\n\t<String> - Topic");
            } else if(strings[0].equals("exit")) {
                System.out.println("SYNTAX:\n\texit\nTAGS / PARAMETERS:\n\tNone");
            }
            else {
                System.out.println("The topic \""+strings[0]+"\" could not be found...");
            }
        } else if(cmd.equals("if")) {
            if(conditions == true) {
                //
            }
        } else if(cmd.equals("Bool")) {
            System.out.println(conditions);
        } else if(cmd.equals("SeeCB")) {
            System.out.println(codeBlock);
        } else if(cmd.equals("changelog")) {
            //System.out.println();
            //System.out.println();
            //System.out.println();
            //System.out.println();
            System.out.println("Version v0.1.1:\n\t-Added a way to make create random numbers (\"<Random>\").\n\t-Added examples for each command from the \"help\" command.\n\t-Added a \"double\" data type.\n\t-Added \"PI\" as a built-in Const variable.");
        }
    }
}

manifest.txt

Main-Class: Dint

from: https://dev.to//calin92540842/why-do-1-none-of-my-commands-work-after-i-type-them-and-2-input-stop-working-after-1-line-of-input-5dmo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值