예제 #1
0
 static void Main(string[] args)
 {
     Console.WriteLine("Cross-Pointer-Calculation-Language   (C)Michael Wang");
     Console.WriteLine("XPCL Interpreter 1");
     lines = File.ReadAllLines(Environment.CurrentDirectory + "\\main.xpcl");
     resx = new VariableManager("resx.txt");
     executor = new Executor();
     for(int i = 0; i < lines.Length;i++)
     {
         ArgumentData data = new ArgumentData(lines[i]);
         if (data.argument == "exec")
         {
             for (int x = 0; x < data.commands.Length; x++)
             {
                 executor.ExecuteCommand(data.commands[x], resx);
             }
         }
         if(data.argument == "point")
         {
             i = int.Parse(data.commands[0]);
         }
         if(data.argument == "equalsvar")
         {
             string a = (string)resx.GetValue(data.commands[0]);
             string b = (string)resx.GetValue(data.commands[1]);
             if(a == b)
             {
                 i = int.Parse(data.commands[2]);
             }
         }
         if (data.argument == "equalsinput")
         {
             string a = (string)resx.GetValue(data.commands[0]);
             Console.WriteLine("");
             Console.Write(">:");
             string b = Console.ReadLine();
             if (a == b)
             {
                 i = int.Parse(data.commands[1]);
             }
         }
         if(data.argument == "frominp")
         {
             Console.WriteLine("");
             Console.Write(">:");
             string a = Console.ReadLine();
             resx.WriteValue(data.commands[0], a);
         }
         if(data.argument == "help")
         {
             Console.WriteLine("Command Help for XPCL version 1");
             Console.WriteLine("Name of nodes (first argument):\n" +
                 "exec/      Executor-executes all commands\n"+
                 "point/     Pointer -points to a line of code to execute\n"
                +"frominp/   Writes a input to a variable\n"
                +"equalsvar/ checks whether 2 variables equal\n"
                +"equalsinmput/ checks whether 2 inputs equal"+"\n\nExecutor Commands:\n"
                +"start      starts a new process");
         }
     }
 }
예제 #2
0
        public void ExecuteCommand(string command, VariableManager manager)
        {
            ArgumentData data = new ArgumentData(command, '-');

            if (data.argument == "printstr" || data.argument == "print")
            {
                for (int i = 0; i < data.commands.Length; i++)
                {
                    Console.WriteLine(data.commands[i]);
                }
            }
            if (data.argument == "printvar")
            {
                for (int i = 0; i < data.commands.Length; i++)
                {
                    Console.WriteLine(manager.GetValue(data.commands[i]));
                }
            }
            if (data.argument == "multiply")
            {
                double a = double.Parse((string)manager.GetValue(data.commands[0]));
                double b = double.Parse((string)manager.GetValue(data.commands[1]));
                double c = double.Parse((string)manager.GetValue(data.commands[2]));
                c = a * b;
                manager.WriteValue(data.commands[2], c.ToString());
            }
            if (data.argument == "add")
            {
                double a = double.Parse((string)manager.GetValue(data.commands[0]));
                double b = double.Parse((string)manager.GetValue(data.commands[1]));
                double c = double.Parse((string)manager.GetValue(data.commands[2]));
                c = a + b;
                manager.WriteValue(data.commands[2], c.ToString());
            }
            if (data.argument == "divide")
            {
                double a = double.Parse((string)manager.GetValue(data.commands[0]));
                double b = double.Parse((string)manager.GetValue(data.commands[1]));
                double c = double.Parse((string)manager.GetValue(data.commands[2]));
                c = a / b;
                manager.WriteValue(data.commands[2], c.ToString());
            }
            if (data.argument == "subtract")
            {
                double a = double.Parse((string)manager.GetValue(data.commands[0]));
                double b = double.Parse((string)manager.GetValue(data.commands[1]));
                double c = double.Parse((string)manager.GetValue(data.commands[2]));
                c = a - b;
                manager.WriteValue(data.commands[2], c.ToString());
            }
            if (data.argument == "readkey")
            {
                Console.ReadKey();
            }
            if (data.argument == "settitle")
            {
                Console.Title = data.commands[0];
            }
            if (data.argument == "stop")
            {
                Console.WriteLine("Stopping");
                Process.GetCurrentProcess().Kill();
            }
            if (data.argument == "clr" || data.argument == "cls" || data.argument == "clear")
            {
                Console.Clear();
            }
            if (data.argument == "writevar")
            {
                if (IsNumber(data.commands[1]))
                {
                    manager.WriteValue(data.commands[0], data.commands[1]);
                }
                else
                {
                    manager.WriteValue(data.commands[0], (string)manager.GetValue(data.commands[1]));
                }
            }
            if (data.argument == "wait")
            {
                Thread.Sleep(int.Parse((string)data.commands[0]));
            }
            if (data.argument == "random")
            {
                Random rand = new Random();
                for (int i = 0; i < data.commands.Length; i++)
                {
                    manager.WriteValue(data.commands[i], rand.Next().ToString());
                }
            }
            if (data.argument == "start")
            {
                for (int i = 0; i < data.commands.Length; i++)
                {
                    Process.Start(Environment.CurrentDirectory + "\\" + data.commands[i]);
                }
            }
            if (data.argument == "read")
            {
                string temp = File.ReadAllText(data.commands[0]);
                manager.WriteValue(data.commands[1], temp);
            }
        }