コード例 #1
0
        public static void lineSeparator(string[] algorithmLines)
        {
            int currentIndentation;
            int prevIndentation = 0;
            int lastLine        = 0;

            for (int line = 0; line < algorithmLines.Length; line++)
            {
                if (Regexp.Check(@"^[\t\r\n\s]*$", algorithmLines[line]))
                {
                    continue;
                }

                currentIndentation = currentLineIndentation(algorithmLines[line]);

                if (currentIndentation > prevIndentation)
                {
                    openBlock(line, currentIndentation);
                }

                else if (currentIndentation < prevIndentation)
                {
                    for (int a = currentIndentation; a < prevIndentation; a++)
                    {
                        closeBlock(line);
                    }
                }

                prevIndentation = currentIndentation;
                lastLine        = line;
            }

            closeAllUnclosedBlock(lastLine);
        }
コード例 #2
0
ファイル: Var.cs プロジェクト: mig1023/graphmath
 public static bool isIncDecrement(string algorithmLine)
 {
     if (Regexp.Check(@"(\+|\-)\=\s*[0-9]+\s*\n?\r?$", algorithmLine))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #3
0
ファイル: Var.cs プロジェクト: mig1023/graphmath
 public static bool isVariable(string algorithmLine)
 {
     if (Regexp.Check(@"=\s*\-?\s*[0-9]+\s*\n?\r?$", algorithmLine))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #4
0
ファイル: Var.cs プロジェクト: mig1023/graphmath
        public static bool IncrementDecrement(string varName, string value)
        {
            Match condition = Regexp.Check(@"(\+|\-)\=\s*([0-9]+)\s*\n?\r?$", value, param: true);

            int change = (condition.Groups[1].Value == "-" ? -1 : 1);

            if (allVars.ContainsKey(varName))
            {
                allVars[varName].Value += Double.Parse(condition.Groups[2].Value) * change;
                return(true);
            }

            return(false);
        }
コード例 #5
0
ファイル: Var.cs プロジェクト: mig1023/graphmath
        public static string parseVariable(string algorithmLine)
        {
            int equalitySign = algorithmLine.IndexOf('=');

            if (equalitySign == -1)
            {
                return("");
            }

            if (algorithmLine.IndexOf("==") >= 0)
            {
                return("");
            }

            if (Regexp.Check(@"(\+\=|\-\=|\*\=)", algorithmLine))
            {
                equalitySign -= 1;
            }

            return(algorithmLine.Substring(0, equalitySign).Trim());
        }
コード例 #6
0
        static int currentLineIndentation(string line)
        {
            int currentIndentation = 0;

            Match matchSpace = Regexp.Check(@"^(\s+)", line, param: true);

            if (matchSpace.Success)
            {
                currentIndentation =
                    matchSpace.Groups[1].Value.ToCharArray().Where(c => c == ' ').Count() / 4;
            }

            Match matchTabs = Regexp.Check(@"^(\t+)", line, param: true);

            if (matchTabs.Success)
            {
                currentIndentation =
                    matchTabs.Groups[1].Value.ToCharArray().Where(c => c == Convert.ToChar(9)).Count();
            }

            return(currentIndentation);
        }
コード例 #7
0
        public static int check(string exp)
        {
            Match condition = Regexp.Check(@"\(\s*(\d+)\s*(==|>=|<=|>|<)\s*(\d+)\s*\)", exp, param: true);

            if (!condition.Success)
            {
                return(0);
            }

            else if (condition.Groups[2].Value == "==" && (condition.Groups[1].Value == condition.Groups[3].Value))
            {
                return(1);
            }

            else if (condition.Groups[2].Value == ">" && (int.Parse(condition.Groups[1].Value) > int.Parse(condition.Groups[3].Value)))
            {
                return(1);
            }

            else if (condition.Groups[2].Value == "<" && (int.Parse(condition.Groups[1].Value) < int.Parse(condition.Groups[3].Value)))
            {
                return(1);
            }

            else if (condition.Groups[2].Value == ">=" && (int.Parse(condition.Groups[1].Value) >= int.Parse(condition.Groups[3].Value)))
            {
                return(1);
            }

            else if (condition.Groups[2].Value == "<=" && (int.Parse(condition.Groups[1].Value) <= int.Parse(condition.Groups[3].Value)))
            {
                return(1);
            }

            else
            {
                return(2);
            }
        }
コード例 #8
0
ファイル: Draw.cs プロジェクト: mig1023/graphmath
        public static bool drawAlgorithmLine(string algorithmLine, int line)
        {
            algorithmLine = Var.replaceVariable(algorithmLine);

            string varName = Var.parseVariable(algorithmLine);

            if (Regexp.Check(@"^[\t\r\n\s]*$", algorithmLine))
            {
                return(true);
            }

            else if (algorithmLine.IndexOf("if") > -1)
            {
                int conditionResult = Conditional.check(algorithmLine);

                if (conditionResult == 0)
                {
                    return(false);
                }
                else if (conditionResult == 2)
                {
                    Block.allBlocks[line + 1].skipThisBlock = true;
                }
                else
                {
                    Block.allBlocks[line + 1].skipThisBlock = false;
                }

                return(true);
            }

            else if (algorithmLine.IndexOf("else") > -1)
            {
                int startLine = Block.startOfThisBlock(line);

                if (startLine == -1)
                {
                    return(false);
                }

                if (Block.allBlocks[startLine].skipThisBlock == true)
                {
                    Block.allBlocks[line + 1].skipThisBlock = false;
                }
                else
                {
                    Block.allBlocks[line + 1].skipThisBlock = true;
                }

                return(true);
            }

            else if (algorithmLine.IndexOf("repeat") > -1)
            {
                string[] p = Parse.parseStrParam(algorithmLine);

                if (p.Length != 3)
                {
                    return(false);
                }

                return(Loop.createNewLoop(
                           varName: p[0],
                           startLine: Block.allBlocks[line + 1].startLine,
                           endLine: Block.allBlocks[line + 1].endLine,
                           currentVar: int.Parse(p[1]),
                           endStatment: int.Parse(p[2])
                           ));
            }

            else if (Var.isIncDecrement(algorithmLine))
            {
                return(Var.IncrementDecrement(varName, algorithmLine));
            }

            else if (Var.isVariable(algorithmLine))
            {
                return(Var.createNewVar(varName, algorithmLine));
            }

            else if (algorithmLine.IndexOf("vector") > -1)
            {
                int[] p = Parse.parseParam(algorithmLine);

                if (p.Length != 4)
                {
                    return(false);
                }

                if (varName != "")
                {
                    Vector.createNewVector(varName, p);
                }

                return(Draw.drawLine(p, Brushes.White));
            }

            else if (algorithmLine.IndexOf("sum") > -1)
            {
                return(Draw.drawSumVector(Parse.parseStrParam(algorithmLine)));
            }

            else if (algorithmLine.IndexOf("point") > -1)
            {
                int[] p = Parse.parseParam(algorithmLine);

                if (p.Length != 2)
                {
                    return(false);
                }

                return(Draw.drawPoint(p, Brushes.Red));
            }

            else if (algorithmLine.IndexOf("sin") > -1)
            {
                return(Draw.drawSimpleFuntion(Math.Sin, Parse.parseParam(algorithmLine)));
            }

            else if (algorithmLine.IndexOf("cos") > -1)
            {
                return(Draw.drawSimpleFuntion(Math.Cos, Parse.parseParam(algorithmLine)));
            }

            else if (algorithmLine.IndexOf("tg") > -1)
            {
                return(Draw.drawSimpleFuntion(Math.Tan, Parse.parseParam(algorithmLine)));
            }

            else
            {
                return(false);
            }
        }