Ejemplo n.º 1
0
 /// <summary>
 /// Draw a polygon according to user defined coordinates
 /// </summary>
 /// <param name="canvass">Canvass in which the polygon is drawn</param>
 public override void draw(Canvass canvass)
 {
     canvass.g.DrawPolygon(canvass.pen, points);//Draw a polygon
     if (canvass.fill)
     {
         canvass.g.FillPolygon(canvass.brush, points);//Draws a filled polygon if fill is true
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Draws a circle according to given radius
 /// </summary>
 /// <param name="canvass">Canvass in which the triangle is drawn</param>
 public override void draw(Canvass canvass)
 {
     canvass.g.DrawEllipse(canvass.pen, canvass.xPos, canvass.yPos, (radius * 2), (radius * 2));//Draws a circle
     if (canvass.fill)
     {
         canvass.g.FillEllipse(canvass.brush, canvass.xPos, canvass.yPos, (radius * 2), (radius * 2));//Draws a filled circle if fill is true
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Draw a square/rectangle according to set height and width
 /// </summary>
 /// <param name="canvass">Canvass in which the square/rectangle is drawn</param>
 public override void draw(Canvass canvass)
 {
     canvass.g.DrawRectangle(canvass.pen, canvass.xPos, canvass.yPos, width, height);//Draw a rectangle
     if (canvass.fill)
     {
         canvass.g.FillRectangle(canvass.brush, canvass.xPos, canvass.yPos, width, height);//Draws a filled rectangle if fill is true
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Using given instructions creates a for loop
        /// </summary>
        /// <param name="data">User input for 'for' loop</param>
        /// <param name="MyCanvass">Canvass in which the user given instruction is implemented</param>
        /// <param name="n">Line where the compiler has reached</param>
        /// <param name="z"></param>
        public void LoopFor(List <String> data, Canvass MyCanvass, int n, int z)
        {
            string tempData = string.Join("\n", data);

            String[]      val      = tempData.Split('\n');
            String[]      cmd      = val[0].Split(' ');
            int           x        = 0;
            bool          var1     = false;
            List <String> tempList = new List <string>();
            int           tempInt  = 1;

            while (tempInt < val.Length)
            {
                tempList.Add(val[tempInt]);
                tempInt++;
            }
            try
            {
                if (cmd[1].Equals("for"))
                {
                    if (!int.TryParse(cmd[2], out x))
                    {
                        if (!MyCanvass.v.DataExists(cmd[2]))
                        {
                            var1 = true;
                        }
                        else
                        {
                            x = MyCanvass.v.GetData(cmd[2]);
                        }
                    }
                }
                if (var1)
                {
                    MyCanvass.syntax.ParmChecking(false, cmd[2], n - z, MyCanvass, lineNum);
                    lineNum = lineNum + 20;
                }
                else
                {
                    for (int b = 0; b < x; b++)
                    {
                        tempData = string.Join("\n", tempList);
                        multiCommand(tempData, MyCanvass);
                    }
                }
            }
            catch
            {
                MyCanvass.syntax.ParmChecking(false, "", n - z, MyCanvass, lineNum);
                lineNum = lineNum + 20;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Draws a triangle according to given hypotenuse, base and adjactent
        /// </summary>
        /// <param name="canvass">Canvass in which the triangle is drawn</param>
        public override void draw(Canvass canvass)
        {
            PointF a = new Point(canvass.xPos, canvass.yPos);
            PointF b = new Point(canvass.xPos, canvass.yPos + bse);
            PointF c = new PointF(canvass.xPos + adj, canvass.yPos + hyp);

            PointF[] pnt = { a, b, c };
            canvass.g.DrawPolygon(canvass.pen, pnt);//Draws a triangle
            if (canvass.fill)
            {
                canvass.g.FillPolygon(canvass.brush, pnt);//Draws a filled triangle if fill is true
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Using given instructions creates a method
        /// </summary>
        /// <param name="data">User input for method</param>
        /// <param name="MyCanvass">Canvass in which the user given instruction is implemented</param>
        /// <param name="n">Line where the compiler has reached</param>
        /// <param name="z"></param>
        public void MethodSelect(List <String> data, Canvass MyCanvass, int n, int z)
        {
            string tempData = string.Join("\n", data);

            String[] val  = tempData.Split('\n');
            String[] cmd  = val[0].Split(' ');
            String   x    = null;
            bool     var1 = false;

            String[] method      = cmd[1].Split('(', ')');
            String[] methodValue = null;

            MyCanvass.m.StoreData(method[0], method[1]);
            List <String> tempList = new List <string>();
            int           tempInt  = 1;

            while (tempInt < val.Length)
            {
                tempList.Add(val[tempInt]);
                tempInt++;
            }

            try
            {
                if (MyCanvass.m.DataExists(method[0]))
                {
                    x           = MyCanvass.m.GetData(method[0]);
                    methodValue = x.Split(',');
                }
                else
                {
                    var1 = true;
                }
                if (var1)
                {
                    MyCanvass.syntax.ParmChecking(false, cmd[1], n - z, MyCanvass, lineNum);
                    lineNum = lineNum + 20;
                }
                else
                {
                    tempData = string.Join("\n", tempList);
                    String methodCmd = method[0] + "command";
                    MyCanvass.m.StoreData(methodCmd, tempData);
                }
            }
            catch
            {
                MyCanvass.syntax.ParmChecking(false, "", n - z, MyCanvass, lineNum);
                lineNum = lineNum + 20;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Displays error when entered command does not exist
        /// </summary>
        /// <param name="MyCanvass">Canvass on which error message is displayed</param>
        /// <param name="n">For the line number of the command</param>
        /// <param name="x">For the location in the canvass where error message is dispalyed</param>
        public void CommandChecking(Canvass MyCanvass, int n, int x)
        {
            Font       drawFont  = new Font("Arial", 10);       //create font
            SolidBrush drawBrush = new SolidBrush(Color.Black); //create brush

            n++;
            if (n != 0)
            {
                if (x == 0)
                {
                    MyCanvass.reset();                                                                               //resets if error has never been found prevoiusly
                }
                MyCanvass.g.DrawString("Command on line " + (n) + " does not exist", drawFont, drawBrush, 0, 0 + x); //displays where and what the problem is(in case of multiline commands)(for component2)
            }
            else
            {
                MyCanvass.g.DrawString("Command does not exist", drawFont, drawBrush, 0, 0); //displays if the command is not recognized
            }
            MyCanvass.err = true;                                                            //sets the err to true
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Displays error when number of enetered parameters are not valid in the context
        /// </summary>
        /// <param name="e">Whenever an exception is caught which checking for the validity of parameter</param>
        /// <param name="MyCanvass">Canvass on which error message is displayed</param>
        /// <param name="n">For the line number of the command</param>
        /// <param name="x">For the location in the canvass where error message is dispalyed</param>
        public void ParmChecking(Exception e, Canvass MyCanvass, int n, int x)
        {
            Font       drawFont  = new Font("Arial", 10);       //create font
            SolidBrush drawBrush = new SolidBrush(Color.Black); //create brush

            if (x == 0)
            {
                MyCanvass.reset();//resets if error has never been found prevoiusly
            }
            if ((n + 1) == 0)
            {
                //displays if number of parameters are invalid
                MyCanvass.g.DrawString("Wrong number of parameters inputted", drawFont, drawBrush, 0, 0 + x);
            }
            else
            {
                //displays if number of parameters are invalid(for multi line commands)(for component2)
                MyCanvass.g.DrawString("Wrong number of parameters inputted on line " + (n + 1), drawFont, drawBrush, 0, 0 + x);
            }
            MyCanvass.err = true;//sets the err to true
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Runs further according to given command in cmdLine or ProgramWindow
 /// </summary>
 /// <param name="command">User input in cmdLine(Single line textbox)</param>
 /// <param name="mulCommand">User input in ProgramWindow(Multi line rich textbox)</param>
 /// <param name="MyCanvass">Canvass in which the user given instruction is implemented</param>
 public void Command(String command, String mulCommand, Canvass MyCanvass)
 {
     //to reset err value and canvass after execution in case of an error
     if (MyCanvass.err)
     {
         MyCanvass.reset();
         MyCanvass.err = false;//sets err to false
     }
     //if there no input in rich text box(program window)
     if (mulCommand.Length.Equals(0))
     {
         singleCommand(command, MyCanvass);
     }
     //if 'run' is used in command line
     else if (command.Equals("run"))
     {
         multiCommand(mulCommand, MyCanvass);
     }
     else
     {
         multiCommand(mulCommand, MyCanvass);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Displays error when enetered parameters are not valid in the context
 /// </summary>
 /// <param name="par">Boolean value which recives value according to validity of parameters</param>
 /// <param name="data">String where the invalid parameter is found</param>
 /// <param name="n">For the line number of the command</param>
 /// <param name="MyCanvass">Canvass on which error message is displayed</param>
 /// <param name="x">For the location in the canvass where error message is dispalyed</param>
 public void ParmChecking(bool par, String data, int n, Canvass MyCanvass, int x)
 {
     if (!par)
     {
         Font       drawFont  = new Font("Arial", 10);       //create font
         SolidBrush drawBrush = new SolidBrush(Color.Black); //create brush
         if (x == 0)
         {
             MyCanvass.reset();//resets if error has never been found prevoiusly
         }
         if ((n + 1) == 0)
         {
             //displays if parameters are invalid
             MyCanvass.g.DrawString("Paramater " + data + " is invalid", drawFont, drawBrush, 0, 0 + x);
         }
         else
         {
             //displays if parameters are invalid(for multi line commands)(for component2)
             MyCanvass.g.DrawString("Paramater " + data + " on line " + (n + 1) + " is invalid", drawFont, drawBrush, 0, 0 + x);
         }
         MyCanvass.err = true;//sets the err to true
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// abstract method for drawing shapes in inheriting classes
 /// </summary>
 /// <param name="canvass">Canvass in which the specifies shape is drawn</param>
 public abstract void draw(Canvass canvass);
Ejemplo n.º 12
0
 /// <summary>
 /// Initialize form components and Load canvass
 /// </summary>
 public Form1()
 {
     InitializeComponent();
     MyCanvass = new Canvass(Graphics.FromImage(OutputBitmap));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Splits given instruction in ProgramWindow and executes Simple Programming Language(spl) based on the number of lines
        /// </summary>
        /// <param name="command">User input in ProgramWindow(Multi line rich textbox)</param>
        /// <param name="MyCanvass">Canvass in which the user given instruction is implemented</param>
        public void multiCommand(String command, Canvass MyCanvass)
        {
            String[] val = command.Split('\n');
            int      n   = 0;
            int      x   = 0;

            //loop for input in rich text box/program window
            while (n < val.Length)
            {
                String[] cmd = val[n].Split(' ');
                if (cmd[0].Equals("while"))
                {
                    List <String> data = new List <string>();
                    do
                    {
                        x++;
                        data.Add(val[n]);
                        n++;
                        cmd = val[n].Split(' ');
                    }while (!cmd[0].Equals("endwhile"));
                    LoopWhile(data, MyCanvass, n, x);
                }
                else if (cmd[0].Equals("if"))
                {
                    List <String> data = new List <string>();
                    do
                    {
                        x++;
                        data.Add(val[n]);
                        n++;
                        cmd = val[n].Split(' ');
                    }while (!cmd[0].Equals("endif"));
                    ConditionIf(data, MyCanvass, n, x);
                }
                else if (cmd[0].Equals("loop"))
                {
                    List <String> data = new List <string>();
                    do
                    {
                        x++;
                        data.Add(val[n]);
                        n++;
                        cmd = val[n].Split(' ');
                    }while (!cmd[0].Equals("endfor"));
                    LoopFor(data, MyCanvass, n, x);
                }
                else if (cmd[0].Equals("method"))
                {
                    List <String> data = new List <string>();
                    do
                    {
                        x++;
                        data.Add(val[n]);
                        n++;
                        cmd = val[n].Split(' ');
                    }while (!cmd[0].Equals("endmethod"));
                    MethodSelect(data, MyCanvass, n, x);
                }
                else
                {
                    spl(cmd, MyCanvass, n);
                }

                n++;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Simple Programming Language(spl) which check the user inputted commands for errors and exception and runs if no error is found
        /// </summary>
        /// <param name="cmd">String command provided by user</param>
        /// <param name="MyCanvass">Canvass in which the user given instruction is implemented</param>
        /// <param name="n">line where the compiler has reached</param>
        public void spl(String[] cmd, Canvass MyCanvass, int n)
        {
            try
            {
                String[] method = cmd[0].Split('(', ')');
                //Checks if entered command exists(if not call displays error also stops further execution) also checks for validity of parameters and number of parametes
                if (cmd[0].Equals("drawto"))
                {
                    String[] data = cmd[1].Split(',');
                    int      x    = 0;
                    int      y    = 0;
                    bool     var1 = false;
                    try
                    {
                        if (!int.TryParse(data[0], out x))
                        {
                            if (!MyCanvass.v.DataExists(data[0]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                x = MyCanvass.v.GetData(data[0]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[0], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out y))
                        {
                            if (!MyCanvass.v.DataExists(data[1]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                y = MyCanvass.v.GetData(data[1]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[1], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        MyCanvass.DrawLine(x, y);
                    }
                }
                else if (cmd[0].Equals("moveto"))
                {
                    String[] data = cmd[1].Split(',');;
                    int      x    = 0;
                    int      y    = 0;
                    bool     var1 = false;
                    try
                    {
                        if (!int.TryParse(data[0], out x))
                        {
                            if (!MyCanvass.v.DataExists(data[0]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                x = MyCanvass.v.GetData(data[0]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[0], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out y))
                        {
                            if (!MyCanvass.v.DataExists(data[1]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                y = MyCanvass.v.GetData(data[1]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[1], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        MyCanvass.MoveTo(x, y);
                    }
                }
                else if (cmd[0].Equals("rectangle"))
                {
                    String[] data = cmd[1].Split(',');;
                    int      x    = 0;
                    int      y    = 0;
                    bool     var1 = false;
                    try
                    {
                        if (!int.TryParse(data[0], out x))
                        {
                            if (!MyCanvass.v.DataExists(data[0]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                x = MyCanvass.v.GetData(data[0]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[0], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out y))
                        {
                            if (!MyCanvass.v.DataExists(data[1]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                y = MyCanvass.v.GetData(data[1]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[1], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        Shape rect = new DrawSquare(x, y);
                        rect.draw(MyCanvass);
                    }
                }
                else if (cmd[0].Equals("triangle"))
                {
                    String[] data = cmd[1].Split(',');;
                    int      x    = 0;
                    int      y    = 0;
                    int      z    = 0;
                    bool     var1 = false;
                    try
                    {
                        if (!int.TryParse(data[0], out x))
                        {
                            if (!MyCanvass.v.DataExists(data[0]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                x = MyCanvass.v.GetData(data[0]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[0], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                        if (!int.TryParse(data[1], out y))
                        {
                            if (!MyCanvass.v.DataExists(data[1]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                y = MyCanvass.v.GetData(data[1]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[1], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                        if (!int.TryParse(data[2], out z))
                        {
                            if (!MyCanvass.v.DataExists(data[2]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                z = MyCanvass.v.GetData(data[2]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, data[2], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        Shape tri = new DrawTriangle(x, y, z);
                        tri.draw(MyCanvass);
                    }
                }
                else if (cmd[0].Equals("square"))
                {
                    int  x    = 0;
                    bool var1 = false;
                    try
                    {
                        if (!int.TryParse(cmd[1], out x))
                        {
                            if (!MyCanvass.v.DataExists(cmd[1]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                x = MyCanvass.v.GetData(cmd[1]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, cmd[1], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        Shape sqr = new DrawSquare(x, x);
                        sqr.draw(MyCanvass);
                    }
                }
                else if (cmd[0].Equals("circle"))
                {
                    int  x    = 0;
                    bool var1 = false;
                    try
                    {
                        if (!int.TryParse(cmd[1], out x))
                        {
                            if (!MyCanvass.v.DataExists(cmd[1]))
                            {
                                var1 = true;
                            }
                            else
                            {
                                x = MyCanvass.v.GetData(cmd[1]);
                            }
                            if (var1)
                            {
                                MyCanvass.syntax.ParmChecking(false, cmd[1], n, MyCanvass, lineNum);
                                lineNum = lineNum + 20;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        Shape circle = new DrawCircle(x);
                        circle.draw(MyCanvass);
                    }
                }
                else if (cmd[0].Equals("polygon"))
                {
                    String[]   data       = cmd[1].Split(',');
                    List <int> tempPoints = new List <int>();
                    int        i          = 0;
                    int        x          = 0;
                    bool       var1       = false;
                    try
                    {
                        while (data.Length > i)
                        {
                            if (!int.TryParse(data[i], out x))
                            {
                                if (!MyCanvass.v.DataExists(data[i]))
                                {
                                    var1 = true;
                                }
                                else
                                {
                                    tempPoints.Add(MyCanvass.v.GetData(data[i]));
                                }
                                if (var1)
                                {
                                    MyCanvass.syntax.ParmChecking(false, data[i], n, MyCanvass, lineNum);
                                    lineNum = lineNum + 20;
                                }
                            }
                            tempPoints.Add(x);
                            i++;
                        }
                    }
                    catch (Exception e)
                    {
                        MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        int[] arr  = tempPoints.ToArray();
                        Shape poly = new DrawPolygon(arr);
                        poly.draw(MyCanvass);
                    }
                }
                else if (cmd[0].Equals("pen"))
                {
                    Color color = Color.FromName(cmd[1]);
                    if (color.IsKnownColor == false)
                    {
                        MyCanvass.syntax.ParmChecking(false, cmd[1], n, MyCanvass, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        MyCanvass.set_Pen_Color(color);
                    }
                }
                else if (cmd[0].Equals("fill"))
                {
                    bool valOn  = cmd[1].Equals("on");
                    bool valOff = cmd[1].Equals("off");
                    if (valOn == false && valOff == false)
                    {
                        MyCanvass.syntax.ParmChecking(false, cmd[1], n, MyCanvass, lineNum);
                        lineNum = lineNum + 20;
                    }
                    if (!MyCanvass.err)
                    {
                        if (valOn)
                        {
                            MyCanvass.fill = true;
                        }
                        else if (valOff)
                        {
                            MyCanvass.fill = false;
                        }
                    }
                }
                else if (cmd[0].Equals("clear"))
                {
                    if (!MyCanvass.err)
                    {
                        MyCanvass.clear();
                    }
                }
                else if (cmd[0].Equals("reset"))
                {
                    if (!MyCanvass.err)
                    {
                        MyCanvass.reset();
                    }
                }
                else if (cmd[0].Equals("exit"))
                {
                    if (!MyCanvass.err)
                    {
                        Application.Exit();
                    }
                }
                else if (MyCanvass.m.DataExists(method[0]))
                {
                    String[] methodValue   = (MyCanvass.m.GetData(method[0])).Split(',');
                    String   methodCmd     = method[0] + "command";
                    String   methodCommand = MyCanvass.m.GetData(methodCmd);
                    String[] userValue     = method[1].Split(',');
                    int      x             = 0;
                    while (methodValue.Length > x)
                    {
                        String[] valueStore = (methodValue[x] + " = " + userValue[x]).Split(' ');
                        spl(valueStore, MyCanvass, n);
                        x++;
                    }
                    multiCommand(methodCommand, MyCanvass);
                }
                else if (cmd[1].Equals("="))
                {
                    try
                    {
                        if (cmd[3].Equals("+"))
                        {
                            int  varValue;
                            int  x    = 0;
                            int  y    = 0;
                            bool var1 = false;
                            try
                            {
                                if (!int.TryParse(cmd[2], out x))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[2]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        x = MyCanvass.v.GetData(cmd[2]);
                                    }

                                    /*syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                     * lineNum = lineNum + 20;*/
                                }
                                if (!int.TryParse(cmd[4], out y))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[4]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        y = MyCanvass.v.GetData(cmd[4]);
                                    }
                                }
                                if (var1)
                                {
                                    MyCanvass.syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                    lineNum = lineNum + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                                lineNum = lineNum + 20;
                            }
                            varValue = x + y;
                            MyCanvass.v.AppendData(cmd[0], varValue);
                        }
                        if (cmd[3].Equals("-"))
                        {
                            int  varValue;
                            int  x    = 0;
                            int  y    = 0;
                            bool var1 = false;
                            try
                            {
                                if (!int.TryParse(cmd[2], out x))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[2]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        x = MyCanvass.v.GetData(cmd[2]);
                                    }

                                    /*syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                     * lineNum = lineNum + 20;*/
                                }
                                if (!int.TryParse(cmd[4], out y))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[4]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        y = MyCanvass.v.GetData(cmd[4]);
                                    }
                                }
                                if (var1)
                                {
                                    MyCanvass.syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                    lineNum = lineNum + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                                lineNum = lineNum + 20;
                            }
                            varValue = x - y;
                            MyCanvass.v.AppendData(cmd[0], varValue);
                        }
                        if (cmd[3].Equals("/"))
                        {
                            int  varValue;
                            int  x    = 0;
                            int  y    = 0;
                            bool var1 = false;
                            try
                            {
                                if (!int.TryParse(cmd[2], out x))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[2]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        x = MyCanvass.v.GetData(cmd[2]);
                                    }

                                    /*syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                     * lineNum = lineNum + 20;*/
                                }
                                if (!int.TryParse(cmd[4], out y))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[4]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        y = MyCanvass.v.GetData(cmd[4]);
                                    }
                                }
                                if (var1)
                                {
                                    MyCanvass.syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                    lineNum = lineNum + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                                lineNum = lineNum + 20;
                            }
                            varValue = x / y;
                            MyCanvass.v.AppendData(cmd[0], varValue);
                        }
                        if (cmd[3].Equals("*"))
                        {
                            int  varValue;
                            int  x    = 0;
                            int  y    = 0;
                            bool var1 = false;
                            try
                            {
                                if (!int.TryParse(cmd[2], out x))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[2]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        x = MyCanvass.v.GetData(cmd[2]);
                                    }

                                    /*syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                     * lineNum = lineNum + 20;*/
                                }
                                if (!int.TryParse(cmd[4], out y))
                                {
                                    if (!MyCanvass.v.DataExists(cmd[4]))
                                    {
                                        var1 = true;
                                    }
                                    else
                                    {
                                        y = MyCanvass.v.GetData(cmd[4]);
                                    }
                                }
                                if (var1)
                                {
                                    MyCanvass.syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                    lineNum = lineNum + 20;
                                }
                            }
                            catch (Exception e)
                            {
                                MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                                lineNum = lineNum + 20;
                            }
                            varValue = x * y;
                            MyCanvass.v.AppendData(cmd[0], varValue);
                        }
                    }
                    catch
                    {
                        int x = 0;
                        try
                        {
                            bool var1 = false;
                            if (!int.TryParse(cmd[2], out x))
                            {
                                if (!MyCanvass.v.DataExists(cmd[2]))
                                {
                                    var1 = true;
                                }
                                else
                                {
                                    x = MyCanvass.v.GetData(cmd[2]);
                                }
                                if (var1)
                                {
                                    MyCanvass.syntax.ParmChecking(false, cmd[2], n, MyCanvass, lineNum);
                                    lineNum = lineNum + 20;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            MyCanvass.syntax.ParmChecking(e, MyCanvass, n, lineNum);
                            lineNum = lineNum + 20;
                        }
                        if (!MyCanvass.err)
                        {
                            if (!MyCanvass.v.DataExists(cmd[0]))
                            {
                                MyCanvass.v.StoreData(cmd[0], x);
                            }
                            else
                            {
                                MyCanvass.v.AppendData(cmd[0], x);
                            }
                        }
                    }
                }
                else
                {
                    MyCanvass.syntax.CommandChecking(MyCanvass, n, lineNum);
                    lineNum = lineNum + 20;
                }
            }
            catch
            {
                MyCanvass.syntax.CommandChecking(MyCanvass, n, lineNum);
                lineNum = lineNum + 20;
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Splits given instruction in cmdLine and executes Simple Programming Language(spl)
 /// </summary>
 /// <param name="command">User input in cmdLine(Single line textbox)</param>
 /// <param name="MyCanvass">Canvass in which the user given instruction is implemented</param>
 public void singleCommand(String command, Canvass MyCanvass)
 {
     String[] cmd = command.Split(' ');
     spl(cmd, MyCanvass, -1);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Using given instructions creates a while loop
        /// </summary>
        /// <param name="data">User input for 'while' loop</param>
        /// <param name="MyCanvass">Canvass in which the user given instruction is implemented</param>
        /// <param name="n">Line where the compiler has reached</param>
        /// <param name="z"></param>
        public void LoopWhile(List <String> data, Canvass MyCanvass, int n, int z)
        {
            string tempData = string.Join("\n", data);

            String[]      val      = tempData.Split('\n');
            String[]      cmd      = val[0].Split(' ');
            int           x        = 0;
            bool          var1     = false;
            List <String> tempList = new List <string>();
            int           tempInt  = 1;

            while (tempInt < val.Length)
            {
                tempList.Add(val[tempInt]);
                tempInt++;
            }

            try
            {
                if (cmd[1].Split('<').Length > 1)
                {
                    String[] tempVal = cmd[1].Split('<');
                    if (!int.TryParse(tempVal[1], out x))
                    {
                        if (!MyCanvass.v.DataExists(tempVal[1]))
                        {
                            var1 = true;
                        }
                        else
                        {
                            x = MyCanvass.v.GetData(tempVal[1]);
                        }
                    }
                    if (var1)
                    {
                        MyCanvass.syntax.ParmChecking(false, tempVal[1], n - z, MyCanvass, lineNum);
                        lineNum = lineNum + 20;
                    }
                    else
                    {
                        if (!MyCanvass.v.DataExists(tempVal[0]))
                        {
                            var1 = true;
                        }
                        if (var1)
                        {
                            MyCanvass.syntax.ParmChecking(false, tempVal[0], n - z, MyCanvass, lineNum);
                            lineNum = lineNum + 20;
                        }
                        else
                        {
                            while (MyCanvass.v.GetData(tempVal[0]) < x)
                            {
                                tempData = string.Join("\n", tempList);
                                multiCommand(tempData, MyCanvass);
                            }
                        }
                    }
                }
                else if (cmd[1].Split('>').Length > 1)
                {
                    String[] tempVal = cmd[1].Split('>');
                    if (!int.TryParse(tempVal[1], out x))
                    {
                        if (!MyCanvass.v.DataExists(tempVal[1]))
                        {
                            var1 = true;
                        }
                        else
                        {
                            x = MyCanvass.v.GetData(tempVal[1]);
                        }
                    }
                    if (var1)
                    {
                        MyCanvass.syntax.ParmChecking(false, tempVal[1], n - z, MyCanvass, lineNum);
                        lineNum = lineNum + 20;
                    }
                    else
                    {
                        if (!MyCanvass.v.DataExists(tempVal[0]))
                        {
                            var1 = true;
                        }
                        if (var1)
                        {
                            MyCanvass.syntax.ParmChecking(false, tempVal[0], n - z, MyCanvass, lineNum);
                            lineNum = lineNum + 20;
                        }
                        else
                        {
                            while (MyCanvass.v.GetData(tempVal[0]) > x)
                            {
                                tempData = string.Join("\n", tempList);
                                multiCommand(tempData, MyCanvass);
                            }
                        }
                    }
                }
                else if (cmd[1].Split('=').Length > 1)
                {
                    String[] tempVal = cmd[1].Split('=');
                    if (!int.TryParse(tempVal[2], out x))
                    {
                        if (!MyCanvass.v.DataExists(tempVal[2]))
                        {
                            var1 = true;
                        }
                        else
                        {
                            x = MyCanvass.v.GetData(tempVal[2]);
                        }
                    }
                    if (var1)
                    {
                        MyCanvass.syntax.ParmChecking(false, tempVal[2], n - z, MyCanvass, lineNum);
                        lineNum = lineNum + 20;
                    }
                    else
                    {
                        if (!MyCanvass.v.DataExists(tempVal[0]))
                        {
                            var1 = true;
                        }
                        if (var1)
                        {
                            MyCanvass.syntax.ParmChecking(false, tempVal[0], n - z, MyCanvass, lineNum);
                            lineNum = lineNum + 20;
                        }
                        else
                        {
                            while (MyCanvass.v.GetData(tempVal[0]) == x)
                            {
                                tempData = string.Join("\n", tempList);
                                multiCommand(tempData, MyCanvass);
                            }
                        }
                    }
                }
                else
                {
                    MyCanvass.syntax.ParmChecking(false, "", n - z, MyCanvass, lineNum);
                    lineNum = lineNum + 20;
                }
            }
            catch
            {
                MyCanvass.syntax.ParmChecking(false, "", n - z, MyCanvass, lineNum);
                lineNum = lineNum + 20;
            }
        }