示例#1
0
        public void Inline2018OneFile(string nameofFile)
        {
            TextValid textValid         = new TextValid();
            int       decissonNumb      = 0;
            int       decissonForOutput = 0;

            try
            {
                using (StreamReader reader = new StreamReader(nameofFile)) //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\.\$\#_]+)\]"; //ovde je kao trebao na kraju ici zagrada )

                    while ((str = reader.ReadLine()) != null)
                    {
                        if (str != "")
                        {
                            decissonForOutput = 0;
                            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, matchsec)); //saljem matchsec jer matchfir ima drukcije definisane grupe,i ako matche-uje sve
                                if (decissonNumb != 0)
                                {
                                    break;
                                }
                                decissonForOutput = 1;
                            }
                            else if (str.Equals(collectorOfSecondRegex))
                            {
                                decissonNumb = Convert.ToInt32(textValid.ComplexVarCheck(str, matchsec, arrayList));
                                if (decissonNumb != 0)
                                {
                                    break;
                                }
                                decissonForOutput = 1;
                            }
                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

                            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*|(\[([\w\d\.\$\#_]+)\]\s*\=\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;
                            }
                            if (stringOfAdvencInlineStrings.Length > 0)
                            {
                                stringOfAdvencInlineStrings = "";
                                foreach (Match m in matchInlineAvanc)
                                {
                                    if (m.Value.Contains("@{"))
                                    {
                                        des = 1;
                                    }
                                    else if (m.Value.Contains("}"))
                                    {
                                        des          = 0;
                                        decissonNumb = textValid.InlineReplace(stringOfAdvencInlineStrings, oprtAritm, oprtAritamAndString, ref str, arrayList, oprtInlineBase);
                                        if (decissonNumb != 0)
                                        {
                                            break;
                                        }
                                        stringOfAdvencInlineStrings = "";
                                    }
                                    if (des != 0)
                                    {
                                        stringOfAdvencInlineStrings += m.Groups[1].Value;
                                    }
                                }
                            }

                            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            if (decissonNumb != 0)
                            {
                                break;
                            }
                            str = textValid.VarReplaceWithVal(str, arrayList); //zamjena variabli sa njihovim vrijednostima
                            str = textValid.ToUpper(str);                      //converts lowCase to UperCase and removes <all_caps> and </all_caps>
                            if (Regex.IsMatch(str, @"include\s*(.+\.txt)"))    //provjerava jel postoji include file
                            {
                                Match matchForInclude = Regex.Match(str, @"include\s*(.+\.txt)");
                                if (str.Equals(matchForInclude.ToString()))
                                {
                                    Inline2018OneFile(matchForInclude.Groups[1].Value);
                                    decissonForOutput = 1;
                                }
                                else
                                {
                                    Console.WriteLine("Nepravilna linija koda kod include->{0}", str);
                                    break;
                                }
                            }
                            if (decissonForOutput == 0)
                            {
                                Match matchstring = Regex.Match(str, @"[\w\d\.\#\$\s\-_]+"); //da li sad string sadrzi samo dozvoljene karakter za <tekst>
                                if (!str.Equals(matchstring.ToString()))
                                {
                                    Console.WriteLine("Ne dozvoljen tekst se pojavio ->{0}", str);
                                    break;
                                }

                                Console.WriteLine(str);
                            }
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                Console.WriteLine(Ex.ToString());
            }
        }
示例#2
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();
        }