Exemplo n.º 1
0
        /// <summary>
        /// Method for defining a a method with
        /// </summary>
        /// <param name="result"></param>
        private void definmethod(string[] result)
        {
            d = 1;
            int b = Ending();

            if (b == 6)
            {
                string[] line;
                line = textarea.Lines;
                ValidateCode val     = new ValidateCode();
                var          textArr = textOrder.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                int          length  = textArr.Length;
                int          counter = 0;
                int          temp    = linenumber();
                for (int t = 1; t < length - 1; t++)
                {
                    string[] arrayOrder = Regex.Split(line[temp], "\r\n");//splits the data at next line and stores themin array
                    String[] results    = val.valid(arrayOrder[0]);
                    if (results[0] == "circle" || results[0] == "rectangle")
                    {
                        string[] arrayOrders = Regex.Split(line[temp], "\r\n");//splits the data at next line and stores themin array
                        results = val.valid(arrayOrder[0]);
                        if (results[0] == "rectangle" && result[0] == "rectangle")
                        {
                            string[] arra = { "rectangle", result[1], result[2] };
                            rectangle(arra);
                            MessageBox.Show("Rectangle Build");
                        }
                        else if (results[0] == "circle" && result[0] == "circle")
                        {
                            string[] arra = { "circle", result[1] };
                            circle(arra);
                            MessageBox.Show("circle build");
                        }
                    }
                    counter = counter + 1;
                }
            }
            else
            {
                d = 1;
                MessageBox.Show("endmethod missing");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 ///this code check commannd line by line and executes them
 /// </summary>
 private void Execute_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(textarea.Text))
     {
         textOrder = textarea.Text.Trim();
         ValidateCode val        = new ValidateCode();
         string[]     arrayOrder = Regex.Split(textOrder, "\r\n");//splits the data at next line and stores themin array
         for (int i = 0; i < arrayOrder.Length; i++)
         {
             ValidateCode v      = new ValidateCode();
             String[]     result = v.valid(arrayOrder[i]);
             getShape(result);
         }
     }
     else
     {
         MessageBox.Show("No Command to Run");
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// used to find the line for loop and if in command textbox
        /// </summary>
        /// <returns></returns>

        private int linenumber()
        {
            string[] line;
            line = textarea.Lines;
            ValidateCode val     = new ValidateCode();
            var          textArr = textOrder.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int          len     = textArr.Length;
            int          counter = 0;
            int          l       = 1;

            for (int t = 0; t <= len; t++)
            {
                string[] arrayOrder = Regex.Split(line[counter], "\r\n");//splits the data at next line and stores themin array

                string[] result1 = val.valid(arrayOrder[0]);
                if (result1[0] == "loop")
                {
                    return(counter);

                    break;
                }
                else if (result1[0] == "if")
                {
                    return(counter);

                    break;
                }
                else if (result1[0] == "circle" || result1[0] == "rectangle")
                {
                    return(counter);

                    break;
                }

                counter = counter + 1;
                l       = l + 1;
            }
            return(0);
        }
Exemplo n.º 4
0
        // method for loop case
        private int Ending()
        {
            string[] line;
            line = textarea.Lines;
            ValidateCode val     = new ValidateCode();
            var          textArr = textOrder.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            int          length  = textArr.Length;
            int          counter = 0;

            for (int t = 1; t <= length; t++)
            {
                string[] arrayOrder = Regex.Split(line[counter], "\r\n");//splits the data at next line and stores themin array
                string[] result1    = val.valid(arrayOrder[0]);
                if (result1[0] == "end")
                {
                    return(5);

                    break;
                }
                if (result1[0] == "endmethod")
                {
                    return(6);

                    break;
                }
                if (result1[0] == "endif")
                {
                    return(7);

                    break;
                }

                counter = counter + 1;
            }

            return(0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// used to check symbols and check is condition is true or false for the if case method
        /// </summary>
        /// <param name="results"></param>
        /// <param name="line"></param>
        /// <param name="counter"></param>
        private void symbolcheck(string[] results, string[] line, int counter)
        {
            ValidateCode val = new ValidateCode();

            //condition to check if radius is equal
            if (results[2] == "=")
            {
                if (results[1] == "radius")
                {
                    if (Convert.ToInt32(results[3]) == radius)
                    {
                        MessageBox.Show("Radius is equal");
                        string[] arrayOrders = Regex.Split(line[counter + 1], "\r\n");//splits the data at next line and stores themin array
                        String[] result      = val.valid(arrayOrders[0]);
                        if (result[0] == "circle")
                        {
                            string[] value = { "circle", result[1] };
                            circle(value);
                            MessageBox.Show("Circle is drawn");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Radius is not equal");
                        d = 1;
                    }
                }
            }
            // condition to check if radius is greater or not
            else if (results[2] == ">")
            {
                if (results[1] == "radius")
                {
                    if (radius > Convert.ToInt32(results[3]))
                    {
                        MessageBox.Show("Radius is greater");
                        string[] arrayOrders = Regex.Split(line[counter + 1], "\r\n");//splits the data at next line and stores themin array
                        String[] result      = val.valid(arrayOrders[0]);
                        if (result[0] == "circle")
                        {
                            string[] value = { "circle", result[1] };
                            circle(value);
                            MessageBox.Show("Circle is drawn");
                        }
                    }
                    else
                    {
                        MessageBox.Show("radius is lesser");
                        d = 1;
                    }
                }
            }
            //condition to check if radius is lesser
            else if (results[2] == "<")
            {
                if (results[1] == "radius")
                {
                    if (radius < Convert.ToInt32(results[3]))
                    {
                        MessageBox.Show("Radiius is lesser");
                        string[] arrayOrders = Regex.Split(line[counter + 1], "\r\n");//splits the data at next line and stores themin array
                        String[] r           = val.valid(arrayOrders[0]);
                        r = val.valid(arrayOrders[0]);
                        if (r[0] == "circle")
                        {
                            string[] value = { "circle", r[1] };
                            circle(value);
                            MessageBox.Show("Circle is drawn");
                        }
                    }
                    else
                    {
                        MessageBox.Show("radius is greater");
                        d = 1;
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// declaring and calling all the methods to be used in looping proccess
        /// </summary>
        /// <param name="result"></param>
        /// <param name="radius"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>

        private void loop(string[] result, int radius, int width, int height)
        {
            int b = Ending();

            d = 1;
            if (b == 5)
            {
                string[] line;
                int      a = Convert.ToInt32(result[1]);
                line = textarea.Lines;
                ValidateCode val     = new ValidateCode();
                var          textArr = textOrder.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                int          length  = textArr.Length;
                for (int s = 1; s <= a; s++)
                {
                    int temp    = linenumber();
                    int number  = linenumber();
                    int counter = 0;
                    for (int t = 1; t < length - 1; t++)
                    {
                        string[] arrayOrder = Regex.Split(line[temp], "\r\n");//splits the data at next line and stores themin array
                        //MessageBox.Show(arrayOrder[0]);
                        String[] results = val.valid(arrayOrder[0]);
                        if (results[0] == "rectangle")
                        {
                            rectangle(results);
                        }
                        else if (results[0] == "triangle")
                        {
                            triangle(results);
                        }
                        else if (results[0] == "circle")
                        {
                            circle(results);
                        }
                        else if (results[0] == "square")
                        {
                            square(results);
                        }
                        else if (results[0] == "transform")
                        {
                            transform(results);
                        }
                        else if (results[0] == "drawTo")
                        {
                            drawto(results);
                        }
                        else if (results[0] == "moveto")
                        {
                            moveTo(results);
                        }
                        else if (results[0] == "radius" && results[1] == "=")
                        {
                            string[] r = { "circle", results[1], results[2] };
                            radiusE(r);
                        }
                        else if (results[0] == "width" && results[1] == "=")
                        {
                            width = Convert.ToInt32(result[2]);
                        }
                        else if (results[0] == "height" && results[1] == "=")
                        {
                            height = Convert.ToInt32(results[2]);
                        }
                        else if (results[0] == "radius" && results[1] == "+")
                        {
                            string[] r = { "circle", results[1], results[2] };
                            radiusP(r);
                        }
                        else if (results[0] == "width" && results[1] == "+")
                        {
                            width = Convert.ToInt32(results[2]);
                        }
                        else if (results[0] == "height" && results[1] == "+")
                        {
                            height = Convert.ToInt32(results[2]);
                        }

                        counter = counter + 1;
                        temp    = temp + 1;
                    }
                }
            }
            else
            {
                MessageBox.Show("end command missing");
                d = 1;
            }
        }