Beispiel #1
0
    public static void TestExtra1()
    {
        System.Console.WriteLine("\n------------------");
        System.Console.WriteLine("\nTests for ExtraTask 1");
        string input = "1 2   4  5        7     ";
        Lexer  L     = new DigitsLexer(input);

        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "1 2   1";
        L     = new DigitsLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "0";
        L     = new DigitsLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        System.Console.WriteLine("\nThere should be errors:");

        input = "1 2 41";
        L     = new DigitsLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "1 2 b 1";
        L     = new DigitsLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a";
        L     = new DigitsLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "";
        L     = new DigitsLexer(input);
        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }
    }
Beispiel #2
0
    public static void Main()
    {
        string input = "154216";
        Lexer  L     = new IntLexer(input);

        try
        {
            L.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }


        //Задание 1
        System.Console.WriteLine("\nTask 1:");

        input = "0";
        Lexer L1 = new NewIntLexer(input);

        try
        {
            L1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "";
        L1    = new NewIntLexer(input);
        try
        {
            L1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "365";
        L1    = new NewIntLexer(input);
        try
        {
            L1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "-22";
        L1    = new NewIntLexer(input);
        try
        {
            L1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "4-2";
        L1    = new NewIntLexer(input);
        try
        {
            L1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        //Задание 2
        System.Console.WriteLine("\nTask 2:");

        input = "";
        Lexer L2 = new IDLexer(input);

        try
        {
            L2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "d";
        L2    = new IDLexer(input);
        try
        {
            L2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "da236E0";
        L2    = new IDLexer(input);
        try
        {
            L2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "2abcd";
        L2    = new IDLexer(input);
        try
        {
            L2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }


        //Задание 3
        System.Console.WriteLine("\nTask 3:");

        input = "";
        Lexer L3 = new NewIntLexer2(input);

        try
        {
            L3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "25";
        L3    = new NewIntLexer2(input);
        try
        {
            L3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "-73060";
        L3    = new NewIntLexer2(input);
        try
        {
            L3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "012";
        L3    = new NewIntLexer2(input);
        try
        {
            L3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }


        // Задание 4
        System.Console.WriteLine("\nTask 4:");

        input = "a";
        Lexer L4 = new LetterDigitLexer(input);

        try
        {
            L4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a1b2c3";
        L4    = new LetterDigitLexer(input);
        try
        {
            L4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "aa2b3c";
        L4    = new LetterDigitLexer(input);
        try
        {
            L4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "r4c2n";
        L4    = new LetterDigitLexer(input);
        try
        {
            L4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "0a9u5";
        L4    = new LetterDigitLexer(input);
        try
        {
            L4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Задание 5
        System.Console.WriteLine("\nTask 5:");

        input = "c";
        Lexer L5 = new LettersLexer(input);

        try
        {
            L5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "c,a,b";
        L5    = new LettersLexer(input);
        try
        {
            L5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "c,a;b,5;k";
        L5    = new LettersLexer(input);
        try
        {
            L5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "ca,g,h";
        L5    = new LettersLexer(input);
        try
        {
            L5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a;b,c;d;e,";
        L5    = new LettersLexer(input);
        try
        {
            L5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "e,f,g;h";
        L5    = new LettersLexer(input);
        try
        {
            L5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Дополнительное задание 1
        System.Console.WriteLine("\nExtra Task 1:");

        input = "4";
        Lexer LL1 = new DigitsLexer(input);

        try
        {
            LL1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "4 5   2";
        LL1   = new DigitsLexer(input);
        try
        {
            LL1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "4,5   2";
        LL1   = new DigitsLexer(input);
        try
        {
            LL1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "1 2  3   4    5";
        LL1   = new DigitsLexer(input);
        try
        {
            LL1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "1 2 34  5  6";
        LL1   = new DigitsLexer(input);
        try
        {
            LL1.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Дополнительное задание 2
        System.Console.WriteLine("\nExtra Task 2:");

        input = "aa12c23dd1";
        Lexer LL2 = new DigitsLettersGroupsLexer(input);

        try
        {
            LL2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "4";
        LL2   = new DigitsLettersGroupsLexer(input);
        try
        {
            LL2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "4sd35r5d5t03ab";
        LL2   = new DigitsLettersGroupsLexer(input);
        try
        {
            LL2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "ab0k";
        LL2   = new DigitsLettersGroupsLexer(input);
        try
        {
            LL2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a4bcd5e";
        LL2   = new DigitsLettersGroupsLexer(input);
        try
        {
            LL2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "ab4c,d5e";
        LL2   = new DigitsLettersGroupsLexer(input);
        try
        {
            LL2.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }


        // Дополнительное задание 3
        System.Console.WriteLine("\nExtra Task 3:");

        input = "1.0";
        Lexer LL3 = new DoubleLexer(input);

        try
        {
            LL3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "4";
        LL3   = new DoubleLexer(input);
        try
        {
            LL3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "55.";
        LL3   = new DoubleLexer(input);
        try
        {
            LL3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = ".3";
        LL3   = new DoubleLexer(input);
        try
        {
            LL3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "12.345";
        LL3   = new DoubleLexer(input);
        try
        {
            LL3.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Дополнительное задание 4
        System.Console.WriteLine("\nExtra Task 4:");

        input = "a'bcd'";
        Lexer LL4 = new StringLexer(input);

        try
        {
            LL4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "'a'";
        LL4   = new StringLexer(input);
        try
        {
            LL4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "'a'bcd";
        LL4   = new StringLexer(input);
        try
        {
            LL4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "'a123bcd0'";
        LL4   = new StringLexer(input);
        try
        {
            LL4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "'123";
        LL4   = new StringLexer(input);
        try
        {
            LL4.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Дополнительное задание 5
        System.Console.WriteLine("\nExtra Task 5:");

        input = "/*12345";
        Lexer LL5 = new CommentLexer(input);

        try
        {
            LL5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "12/*345*/";
        LL5   = new CommentLexer(input);
        try
        {
            LL5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "/*1234*/5";
        LL5   = new CommentLexer(input);
        try
        {
            LL5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "/*12345*/";
        LL5   = new CommentLexer(input);
        try
        {
            LL5.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        // Дополнительное сложное задание
        System.Console.WriteLine("\nHard Extra Task:");

        input = "a225";
        Lexer LLL = new IDListLexer(input);

        try
        {
            LLL.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a225.abcd.e00e00.k";
        LLL   = new IDListLexer(input);
        try
        {
            LLL.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a225.abcd e00e00.k";
        LLL   = new IDListLexer(input);
        try
        {
            LLL.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }

        input = "a225..abcd.e00e00.k";
        LLL   = new IDListLexer(input);
        try
        {
            LLL.Parse();
        }
        catch (LexerException e)
        {
            System.Console.WriteLine(e.Message);
        }
    }