Пример #1
0
        static void Main(string[] args)
        {
            TextValid textValid    = new TextValid();
            ArrayList arrayList    = new ArrayList();
            int       decissonNumb = 0;

            try
            {
                using (StreamReader reader = new StreamReader("Code.txt")) //whe 0-element
                {
                    string str                 = "";
                    string oprtAritm           = @"\[([\w\d\.\$\#_]+)\]\s*\=\s*|([\d\(\)\+\-\/\*\s]+)|\[([\w\d\.\$\#_]+)\]";
                    string oprtAritamAndString = @"\[([\w\d\.\$\#_]+)\]\s*\=\s*|" + "\u0022" + @"([\w\d\s\.\$\#_]+)" + "\u0022" + @"|([\d\(\)\+\-\/\*\s]+|\[([\w\d\.\$\#_]+)\])";

                    while ((str = reader.ReadLine()) != null)
                    {
                        decissonNumb = textValid.checkForInvalidChar(str); //checks if string contains unregulat characters
                        if (decissonNumb != 0)
                        {
                            break;
                        }

                        decissonNumb = textValid.BraceCheck(str);//checks if the braces [] are ok
                        if (decissonNumb != 0)
                        {
                            break;
                        }

                        decissonNumb = textValid.AllCapsCheck(str);//checks if the <all_caps> are ok
                        if (decissonNumb != 0)
                        {
                            break;
                        }

                        MatchCollection matchfir = Regex.Matches(str, oprtAritm); //za provjeru aritmetickih variabli
                        string          collectorOfFirstRegex = "", collectorOfSecondRegex = "";
                        foreach (Match mfir in matchfir)
                        {
                            collectorOfFirstRegex += mfir.ToString();
                        }
                        MatchCollection matchsec = Regex.Matches(str, oprtAritamAndString); //za provjeru slozenog izraza
                        foreach (Match m in matchsec)
                        {
                            collectorOfSecondRegex += m.ToString();
                        }

                        if (str.Equals(collectorOfFirstRegex))
                        {
                            decissonNumb = Convert.ToInt32(textValid.ArithmeticVarCheck(str, matchfir, arrayList));
                            if (decissonNumb != 0)
                            {
                                break;
                            }
                        }
                        else if (str.Equals(collectorOfSecondRegex))
                        {
                            decissonNumb = Convert.ToInt32(textValid.ComplexVarCheck(str, matchsec, arrayList));
                            if (decissonNumb != 0)
                            {
                                break;
                            }
                        }
                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                        string          oprtInlineBase                 = @"\@\{(.*?)\}";
                        ArrayList       arrayOfBaseInlinestrings       = new ArrayList();
                        string          stringarrayOfBaseInlinestrings = "";
                        MatchCollection matchInlineBase                = Regex.Matches(str, oprtInlineBase); //prepostavimo da su {} zagrade dobre i "" i @,napisati funkciju koja ce to provjeravati
                        foreach (Match m in matchInlineBase)
                        {
                            stringarrayOfBaseInlinestrings += m.Groups[1].Value;
                        }

                        string          oprtInlineAdvenc            = @"\@\{\s*|(" + "\u0022" + @"([\w\d\s\.\$\#_]+)" + "\u0022" + @"|([\d\(\)\+\-\/\*\s]+)|\[([\w\d\.\$\#_]+)\])|\s*\}";
                        ArrayList       arrayOfAdvencInlineStrings  = new ArrayList();
                        string          stringOfAdvencInlineStrings = "";
                        int             des = 0;
                        MatchCollection matchInlineAvanc = Regex.Matches(str, oprtInlineAdvenc);
                        foreach (Match m in matchInlineAvanc)
                        {
                            if (m.Value.Contains("@{"))
                            {
                                des = 1;
                            }
                            else if (m.Value.Contains("}"))
                            {
                                des = 0;
                            }
                            if (des != 0)
                            {
                                stringOfAdvencInlineStrings += m.Groups[1].Value;
                            }
                        }


                        if (!stringarrayOfBaseInlinestrings.Equals(stringOfAdvencInlineStrings))
                        {
                            Console.WriteLine("Doslo je do greske u <izraz>->{0}", str);
                            break;
                        }



                        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                        string          oprtPutingVar = @"\s*\=\[([\w\d\.\$\#_]+)\]|\[([\w\d\.\$\#_]+)\]";
                        MatchCollection matchthired   = Regex.Matches(str, oprtPutingVar); //za zamjenu [var] sa pravim vrijednostima
                        foreach (Match mthir in matchthired)
                        {
                            if (mthir.Groups[2].Value != "" && !Regex.IsMatch(str, @"\[([\w\d\.\$\#_]+)\]\s*\=\s*"))
                            {
                                Console.WriteLine("Ne pravilno definisan ispis variable->{0}", str);
                                break;
                            }
                            else if (mthir.Groups[1].Value != "")
                            {
                                foreach (Variable var in arrayList)
                                {
                                    if (var.nameOfVar == mthir.Groups[1].Value)
                                    {
                                        str = str.Replace("[" + var.nameOfVar + "]", var.strings);
                                    }
                                }
                            }
                        }


                        Console.WriteLine(str);
                        //ovde treba dodati da se prom ubaci ako treba i onda da se izvrsi ToUpper
                        str = textValid.ToUpper(str); //converts lowCase to UperCase and removes <all_caps> and </all_caps>
                                                      // Console.WriteLine("{0}", str);
                                                      // Console.WriteLine(holeText);
                    }
                }
            }
            catch (Exception Ex)
            {
                Console.WriteLine(Ex.ToString());
            }
            Console.ReadLine();
        }