Example #1
0
        public static void interpret(string command, string[] args)
        {
            ;
            if (isCommand(command))
            {
                if (command.ToLower().Trim().Equals("##"))
                {
                    // we are a commend
                    return;
                }
                if (command.ToLower().Trim().Equals("print"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for PRINT: Line " + Program.line);
                    }

                    //Console.WriteLine (Registry.exists(args[0].Trim()));
                    //Console.WriteLine ("CONSOLE GET " + Registry.get(args[1]).Trim());

                    if (Registry.exists(args [1].Trim()))                         // PRINT : x

                    {
                        Console.WriteLine(Registry.get(args [1]).Trim());
                    }
                    else                         // PRINT : This is a test
                    {
                        Console.WriteLine(arrayToChars(args));
                    }
                    return;
                }
                if (command.ToLower().Trim().Equals("add"))
                {
                    if (args.Length < 2)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for ADD: Line " + Program.line);
                    }
                    bool suc = Registry.add(args [0], args [1]);
                    if (suc == false)
                    {
                        Console.WriteLine("EXECUTION ERROR: Cannot create VALUE {1} with KEY {0} : Value may be locked: Line " + Program.line, args [1], args [0]);
                    }
                    return;
                }
                if (command.ToLower().Trim().Equals("set"))
                {
                    if (args.Length < 2)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for SET: Line " + Program.line);
                    }
                    bool suc = Registry.set(args [1], args [2]);
                    if (suc == false)
                    {
                        Console.WriteLine("EXECUTION ERROR: Cannot set VALUE {1} to KEY {0} : Value may be locked: Line " + Program.line, args [1], args [0]);
                    }
                    return;
                }
                if (command.ToLower().Trim().Equals("rem"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for REM: Line " + Program.line);
                    }
                    bool suc = Registry.rem(args [1]);
                    if (suc == false)
                    {
                        Console.WriteLine("EXECUTION ERROR: Cannot REMOVE {0}: Line " + Program.line, args [0]);
                    }
                    return;
                }
                if (command.ToLower().Trim().Equals("clear"))
                {
                    Console.Clear();
                    return;
                }
                if (command.ToLower().Trim().Equals("exit"))
                {
                    if (args.Length == 0)
                    {
                        Console.WriteLine("EXECUTION ERROR: Cannot invoke exit with no value: Line " + Program.line);
                        return;
                    }
                    Program.run = false;
                    try {
                        Program.code = int.Parse(regParse(args [1]));
                    } catch (Exception e) {
                        Console.WriteLine("FATAL ERROR: Cannot invoke exit with no value: Line " + Program.line);
                        return;
                    }
                    return;
                }
                if (command.ToLower().Trim().Equals("arith"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for ARITH: Line " + Program.line);
                    }
                    if (args [2].Contains("+"))
                    {
                        string[] xpr = args [2].Split('+');
                        Registry.add(args [1], arithmatic(xpr [0], "+", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("-"))
                    {
                        string[] xpr = args [2].Split('-');
                        Registry.add(args [1], arithmatic(xpr [0], "-", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("/"))
                    {
                        string[] xpr = args [2].Split('/');
                        Registry.add(args [1], arithmatic(xpr [0], "/", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("*"))
                    {
                        string[] xpr = args [2].Split('*');
                        Registry.add(args [1], arithmatic(xpr [0], "*", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("%"))
                    {
                        string[] xpr = args [2].Split('%');
                        Registry.add(args [1], arithmatic(xpr [0], "%", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("^"))
                    {
                        string[] xpr = args [2].Split('^');
                        Registry.add(args [1], arithmatic(xpr [0], "^", xpr [1]));
                        return;
                    }

                    if (args [2].Contains("<<"))
                    {
                        char[] leftShift = new char[2];
                        leftShift [0] = '<';
                        leftShift [1] = '<';
                        string[] xpr = args [2].Split(leftShift);
                        Registry.add(args [1], arithmatic(xpr [0], "<<", xpr [1]));
                        return;
                    }
                    if (args [2].Contains(">>"))
                    {
                        char[] leftShift = new char[2];
                        leftShift [0] = '>';
                        leftShift [1] = '>';
                        string[] xpr = args [2].Split(leftShift);
                        Registry.add(args [1], arithmatic(xpr [0], ">>", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("^^"))
                    {
                        char[] leftShift = new char[2];
                        leftShift [0] = '^';
                        leftShift [1] = '^';
                        string[] xpr = args [2].Split(leftShift);
                        Registry.add(args [1], arithmatic(xpr [0], "^^", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("||"))
                    {
                        char[] leftShift = new char[2];
                        leftShift [0] = '|';
                        leftShift [1] = '|';
                        string[] xpr = args [2].Split(leftShift);
                        Registry.add(args [1], arithmatic(xpr [0], "||", xpr [1]));
                        return;
                    }
                    if (args [2].Contains("&&"))
                    {
                        char[] leftShift = new char[2];
                        leftShift [0] = '&';
                        leftShift [1] = '&';
                        string[] xpr = args [2].Split(leftShift);
                        Registry.add(args [1], arithmatic(xpr [0], "&&", xpr [1]));
                        return;
                    }
                }
                if (command.ToLower().Trim().Equals("read"))                      // READ : var
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to READ: Line" + Program.line);
                    }
                    Console.Write(">>");
                    string input = Console.ReadLine();
                    Registry.add(args [1], input);
                }
                //arith
                if (command.ToLower().Trim().Equals("arith#sin"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for SIN: Line " + Program.line);
                    }
                    Registry.add(args [1], "" + Math.Sin(double.Parse(regParse(args [2]))));
                }
                if (command.ToLower().Trim().Equals("arith#cos"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for COS: Line " + Program.line);
                    }
                    Registry.add(args [1], "" + Math.Cos(double.Parse(regParse(args [2]))));
                }
                if (command.ToLower().Trim().Equals("arith#tan"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for TAN: Line " + Program.line);
                    }
                    Registry.add(args [1], "" + Math.Tan(double.Parse(regParse(args [2]))));
                }
                if (command.ToLower().Trim().Equals("arith#sqrt"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments for SQRT: Line " + Program.line);
                    }
                    Registry.add(args [1], "" + Math.Sqrt(double.Parse(regParse(args [2]))));
                }
                if (command.ToLower().Trim().Equals("goto"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to GOTO: Line " + Program.line);
                    }
                    try {
                        Program.currentLine = int.Parse(args [1]) - 1;
                        //Console.WriteLine(Program.currentLine);
                    } catch (Exception e) {
                        Console.WriteLine("FATAL ERROR: {0} : Line: {1}", e.Message, Program.line);
                    }
                }
                if (command.ToLower().Trim().Equals("lock"))
                {
                    if (!isConstant(args [1]))
                    {
                        Console.WriteLine("EXECUTION ERROR: Cannot lock a system constant: Line " + Program.line);
                    }
                    else
                    {
                        bool suc = Registry.lockvar(args [1]);
                        if (suc == false)
                        {
                            Console.WriteLine("EXECUTION ERROR: Cannot lock: " + args [1] + ": Line " + Program.line);
                        }
                    }
                }
                if (command.ToLower().Trim().Equals("unlock"))
                {
                    if (!isConstant(args [1]))
                    {
                        Console.WriteLine("EXECUTION ERROR: Cannot unlock a system constant: Line " + Program.line);
                    }
                    else
                    {
                        bool suc = Registry.unlockvar(args [1]);
                        if (suc == false)
                        {
                            Console.WriteLine("EXECUTION ERROR: Cannot unlock: " + args [1] + ": Line " + Program.line);
                        }
                    }
                }
                if (command.ToLower().Trim().Equals("dump"))
                {
                    for (int i = 0; i < Registry.getDataList().ToArray().Length; i++)
                    {
                        RegistryData d = Registry.getDataList().ToArray() [i];
                        Console.WriteLine("Variable: {0} Value: {1}", d.Key, d.Data);
                    }
                }
                if (command.ToLower().Trim().Equals("rand"))
                {
                    if (args.Length < 1)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to RAND: Line " + Program.line);
                        return;
                    }
                    Registry.add(args [1], new Random().Next() + "");
                }

                if (command.ToLower().Trim().Equals("bsl"))
                {
                    if (args.Length < 3)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to BSL: Line " + Program.line);
                        return;
                    }
                    Registry.add(args [1], "" + (int.Parse(regParse(args [2])) << int.Parse(regParse(args [3]))));
                }
                if (command.ToLower().Trim().Equals("bsr"))
                {
                    if (args.Length < 3)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to BSL: Line " + Program.line);
                        return;
                    }
                    Registry.add(args [1], "" + (int.Parse(regParse(args [2])) >> int.Parse(regParse(args [3]))));
                }
                if (command.ToLower().Trim().Equals("bor"))
                {
                    if (args.Length < 3)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to BSL: Line " + Program.line);
                        return;
                    }
                    Registry.add(args [1], "" + (int.Parse(regParse(args [2])) | int.Parse(regParse(args [3]))));
                }
                if (command.ToLower().Trim().Equals("band"))
                {
                    if (args.Length < 3)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to BSL: Line " + Program.line);
                        return;
                    }
                    Registry.add(args [1], "" + (int.Parse(regParse(args [2])) & int.Parse(regParse(args [3]))));
                }
                if (command.ToLower().Trim().Equals("bxor"))
                {
                    if (args.Length < 3)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to BSL: Line " + Program.line);
                        return;
                    }
                    Registry.add(args [1], "" + (int.Parse(regParse(args [2])) ^ int.Parse(regParse(args [3]))));
                }
                if (command.ToLower().Trim().Equals("bnot"))
                {
                    if (args.Length < 2)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to BNOT: Line " + Program.line);
                        return;
                    }
                    Registry.add(args [1], "" + (~int.Parse(regParse(args[2]))));
                }
                // conversion from int to char TOCHAR : var var
                if (command.ToLower().Trim().Equals("tochar"))
                {
                    if (args.Length < 2)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to TOCHAR: Line " + Program.line);
                        return;
                    }
                    try{
                        Registry.add(args[1], "" + ((char)int.Parse(regParse(args[2]))));
                    }catch (Exception e) {
                        Console.WriteLine("FATAL ERROR: {0}: Line " + Program.line, e.Message);
                    }
                }
                // conversion from int to char TOCHAR : var var
                if (command.ToLower().Trim().Equals("toint"))
                {
                    if (args.Length < 2)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to TOINT: Line " + Program.line);
                        return;
                    }
                    try{
                        Registry.add(args[1], "" + ((int)(regParse(args[2]).ToCharArray()[0])));
                    }catch (Exception e) {
                        Console.WriteLine("FATAL ERROR: {0}: Line " + Program.line, e.Message);
                    }
                }
                if (command.ToLower().Trim().Equals("concat"))
                {
                    if (args.Length < 3)
                    {
                        Console.WriteLine("COMPILATION ERROR: Not Enough Arguments to CONCAT: Line " + Program.line);
                        return;
                    }
                    String a = regParse(args[2]);
                    String b = regParse(args[3]);
                    Registry.add(args[1], a + b);
                }
            }
            else
            {
                Console.WriteLine("COMPILATION ERROR: Unknown command {0}: Line " + Program.line, command);
            }
        }