public void TestCommentParse() { CommentLexer l = new CommentLexer("/**/"); Assert.IsTrue(l.Parse(), "Не пропускает /**/"); l = new CommentLexer("/*as3 @4&*_ -dd %~f*/"); Assert.IsTrue(l.Parse(), "Не пропускает /*as3 @4&*_ -dd %~f*/"); l = new CommentLexer("/*asda \n */"); Assert.IsTrue(l.Parse(), "Не пропускает перенос строки"); }
public void TestCommentFail() { CommentLexer l = new CommentLexer("*/"); Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает */'"); l = new CommentLexer("/*"); Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает /*'"); l = new CommentLexer("/* \n"); Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает */ \n'"); l = new CommentLexer("/**/*/"); Assert.Throws <LexerException>(() => { l.Parse(); }, "Пропускает /**/*/'"); }
public static void TestExtra5() { System.Console.WriteLine("\n------------------"); System.Console.WriteLine("\nTests for ExtraTask 5"); string input = "/*ab3s*/"; Lexer L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } input = "/*a*/"; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } input = "/**/"; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } System.Console.WriteLine("\nThere should be errors:"); input = "/*abc*/adf"; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } input = "/*abc*/adf*/"; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } input = "*/a"; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } input = "a*/"; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } input = "a"; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } input = ""; L = new CommentLexer(input); try { L.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } }
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("\n--- Tests for NumLexer --- "); string input1 = "654721"; Lexer L1 = new NumLexer(input1); try { L1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input1_1 = "00124"; Lexer L1_1 = new NumLexer(input1_1); try { L1_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 2 System.Console.WriteLine("\n--- Tests for IDLexer --- "); string input2 = "a154q216"; Lexer L2 = new IDLexer(input2); try { L2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input2_1 = "bbbbb"; Lexer L2_1 = new IDLexer(input2_1); try { L2_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input2_2 = "3f67gb"; Lexer L2_2 = new IDLexer(input2_2); try { L2_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 3 System.Console.WriteLine("\n--- Tests for SignLexer --- "); string input3 = "-721"; Lexer L3 = new SignLexer(input3); try { L3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input3_1 = "+4561"; Lexer L3_1 = new SignLexer(input3_1); try { L3_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input3_2 = "-004"; Lexer L3_2 = new SignLexer(input3_2); try { L3_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 4 System.Console.WriteLine("\n--- Tests for ALtLexer --- "); string input4 = "a4a7b4"; Lexer L4 = new AltLexer(input4); try { L4.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input4_1 = "b5hh7m"; Lexer L4_1 = new AltLexer(input4_1); try { L4_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input4_2 = "4a6n7"; Lexer L4_2 = new AltLexer(input4_2); try { L4_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 5 System.Console.WriteLine("\n--- Tests for DelimLexer --- "); string input5 = "a;a,b;z,r,q"; Lexer L5 = new DelimLexer(input5); try { L5.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input5_1 = "b;a,t,,r,w;w"; Lexer L5_1 = new DelimLexer(input5_1); try { L5_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input5_2 = "a;"; Lexer L5_2 = new DelimLexer(input5_2); try { L5_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // дополнительные // 1 System.Console.WriteLine("\n--- Tests for NuSpacesLexer --- "); string input6 = "1 5 3 3 84"; Lexer L6 = new NumSpacesLexer(input6); try { L6.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input6_1 = " 5 788 1 3 9"; Lexer L6_1 = new NumSpacesLexer(input6_1); try { L6_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input6_2 = "5 3 1 6 "; Lexer L6_2 = new NumSpacesLexer(input6_2); try { L6_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 2 System.Console.WriteLine("\n--- Tests for AltElemsLexer --- "); string input7 = "aa12c23dd1"; Lexer L7 = new AltElemsLexer(input7); try { L7.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input7_1 = "m6a123nm8"; Lexer L7_1 = new AltElemsLexer(input7_1); try { L7_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input7_2 = "5pp8l12a"; Lexer L7_2 = new AltElemsLexer(input7_2); try { L7_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 3 System.Console.WriteLine("\n--- Tests for RealLexer --- "); string input8 = "21.455"; Lexer L8 = new RealLexer(input8); try { L8.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input8_1 = "45.124.13"; Lexer L8_1 = new RealLexer(input8_1); try { L8_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input8_2 = "012.45"; Lexer L8_2 = new RealLexer(input8_2); try { L8_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 4 System.Console.WriteLine("\n--- Tests for QuoteLexer --- "); string input9 = "'meow42'"; Lexer L9 = new QuoteLexer(input9); try { L9.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input9_1 = "'nn'ehe'srh"; Lexer L9_1 = new QuoteLexer(input9_1); try { L9_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input9_2 = "gkdgbk'aqfe'"; Lexer L9_2 = new QuoteLexer(input9_2); try { L9_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input9_3 = "'xgfm'fgm"; Lexer L9_3 = new QuoteLexer(input9_3); try { L9_3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } // 5 System.Console.WriteLine("\n--- Tests for CommentLexer --- "); string input10 = "/*pu pu* pu*/"; Lexer L10 = new CommentLexer(input10); try { L10.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input10_1 = "/*smrjr*/hjtej*/"; Lexer L10_1 = new CommentLexer(input10_1); try { L10_1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input10_2 = "/**/"; Lexer L10_2 = new CommentLexer(input10_2); try { L10_2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } string input10_3 = "/**/sndfy"; Lexer L10_3 = new CommentLexer(input10_3); try { L10_3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } }
public static void Main() { //ints string intPos = "154216"; string intNeg = "-154216"; Lexer L1 = new IntLexer(intPos); Lexer L3 = new IntLexer("12x3"); Lexer L2 = new IntLexer(intNeg); System.Console.WriteLine("task 1:"); try { L1.Parse(); L2.Parse(); L3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //idents string goodIdent = "abc_23d"; string badIdent = "123a"; Lexer LId1 = new IdentLexer(goodIdent); Lexer LId2 = new IdentLexer(badIdent); System.Console.WriteLine("task 2:"); try { LId1.Parse(); LId2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //not zeros string goodInt = "154216"; string badInt = "054216"; Lexer NotZeroL1 = new IntNotZeroLexer(goodInt); Lexer NotZeroL2 = new IntNotZeroLexer(badInt); System.Console.WriteLine("task 3:"); try { NotZeroL1.Parse(); NotZeroL2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //interleaved Lexer Interleave1 = new LetterDigitInterleave("a1b2c3"); Lexer Interleave2 = new LetterDigitInterleave("a1b2c33"); Lexer Interleave3 = new LetterDigitInterleave("a1b2c"); System.Console.WriteLine("task 4:"); try { Interleave1.Parse(); Interleave3.Parse(); Interleave2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //letters separated Lexer Separated1 = new LettersSeparated("a,b;c"); Lexer Separated2 = new LettersSeparated("abc"); Lexer Separated3 = new LettersSeparated("a;bc,"); System.Console.WriteLine("task 4:"); try { Separated1.Parse(); Separated2.Parse(); Separated3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 1 Lexer SpaceDigits1 = new DigitsSepBySpaces("1 2 3"); Lexer SpaceDigits2 = new DigitsSepBySpaces("1 2 3"); Lexer SpaceDigits3 = new DigitsSepBySpaces("1 "); System.Console.WriteLine("extra task 1:"); try { SpaceDigits1.Parse(); SpaceDigits2.Parse(); SpaceDigits3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 2 Lexer LettersDigitsInterleaved1 = new Lexem2("aa11bb34cc"); Lexer LettersDigitsInterleaved2 = new Lexem2("aa11bb3cc"); Lexer LettersDigitsInterleaved3 = new Lexem2("aa11bb345"); System.Console.WriteLine("extra task 2:"); try { LettersDigitsInterleaved1.Parse(); LettersDigitsInterleaved2.Parse(); LettersDigitsInterleaved3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 3 Lexer Real1 = new RealLexer("123.54"); Lexer Real2 = new RealLexer("-15.2"); Lexer Real3 = new RealLexer("11.."); System.Console.WriteLine("extra task 3:"); try { Real1.Parse(); Real2.Parse(); Real3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 4 Lexer Apostrophies1 = new ApostrophiesLexer("'Hello, world!'"); Lexer Apostrophies2 = new ApostrophiesLexer("'Howdy"); Lexer Apostrophies3 = new ApostrophiesLexer("'Hey, Hey!'blablabla"); System.Console.WriteLine("extra task 4:"); try { Apostrophies1.Parse(); Apostrophies2.Parse(); Apostrophies3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } //extra 5 Lexer Comment1 = new CommentLexer("/*hello there*/"); Lexer Comment2 = new CommentLexer("/*hello * there */"); Lexer Comment3 = new CommentLexer("/*hello * there */, General Kenobi"); System.Console.WriteLine("extra task 5:"); try { Comment1.Parse(); Comment2.Parse(); Comment3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } }
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); } }
public static void Main() { System.Console.WriteLine("Testing IntLexer:"); List <string> test_int = new List <string> { "1", "123", "+123", "-123", "+a", "+", "+1233f", " " }; foreach (var str in test_int) { IntLexer L = new IntLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse())); } System.Console.WriteLine("Testing IDLexer:"); List <string> test_id = new List <string> { "a", "a1ad", "a___", "1", "", " " }; foreach (var str in test_id) { IdLexer L = new IdLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse())); } System.Console.WriteLine("Testing NoZeroIntLexer:"); List <string> test_nozeroint = new List <string> { "1", "123", "+123", "-123", "+0", "0", "-0", " " }; foreach (var str in test_nozeroint) { NoZeroIntLexer L = new NoZeroIntLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse())); } System.Console.WriteLine("Testing LetterDigitLexer:"); List <string> test_LetterDigitLexer = new List <string> { "a", "a1", "a1a", "1", "a11", "a1aa", "", " " }; foreach (var str in test_LetterDigitLexer) { LetterDigitLexer L = new LetterDigitLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse())); } System.Console.WriteLine("Testing ListLexer:"); List <string> test_ListLexer = new List <string> { "a", "a,", "a;b", "a,b;", "ab", "", ",", " " }; foreach (var str in test_ListLexer) { ListLexer L = new ListLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1} : {2}", str, L.Parse(), string.Join(",", L.chrs))); } System.Console.WriteLine("Testing DigitListLexer:"); List <string> test_DigitListLexer = new List <string> { "1", " 1 2 3", " ", "", "1 2 3 b" }; foreach (var str in test_DigitListLexer) { DigitListLexer L = new DigitListLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1} : {2}", str, L.Parse(), string.Join(",", L.ints))); } System.Console.WriteLine("Testing GroupLexer:"); List <string> test_GroupLexer = new List <string> { "aa12c23dd1", "aaa12c23dd1", "aa12c232dd1", " ", "" }; foreach (var str in test_GroupLexer) { GroupLexer L = new GroupLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1} : {2}", str, L.Parse(), L.result)); } System.Console.WriteLine("Testing RealLexer:"); List <string> test_RealLexer = new List <string> { "+12", "12", "+0.1", "123.b", " ", "" }; foreach (var str in test_RealLexer) { RealLexer L = new RealLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse())); } System.Console.WriteLine("Testing StringLexer:"); List <string> test_StringLexer = new List <string> { "'asd'", "''", "a", "'aaa'a", "'aaa", " ", "" }; foreach (var str in test_StringLexer) { StringLexer L = new StringLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse())); } System.Console.WriteLine("Testing CommentLexer:"); List <string> test_CommentLexer = new List <string> { "/*ddd*/", "/**/", "/*fff", " ", "" }; foreach (var str in test_CommentLexer) { CommentLexer L = new CommentLexer(str); System.Console.WriteLine(System.String.Format("{0} : {1}", str, L.Parse())); } }
private static void TestCommentLexer() { System.Console.WriteLine("/----------------------------------------------/"); System.Console.WriteLine("Test CommentLexer..."); string s1 = "/**/"; string s2 = "/*ffq*fe/*/"; string s3 = "/qwe"; string s4 = "/*ewqeqe"; string s5 = "*eee*/"; Lexer L1 = new CommentLexer(s1); Lexer L2 = new CommentLexer(s2); Lexer L3 = new CommentLexer(s3); Lexer L4 = new CommentLexer(s4); Lexer L5 = new CommentLexer(s5); System.Console.WriteLine("Test for " + s1); try { L1.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } System.Console.WriteLine("Test for " + s2); try { L2.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } System.Console.WriteLine("Test for " + s3); try { L3.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } System.Console.WriteLine("Test for " + s4); try { L4.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } System.Console.WriteLine("Test for " + s5); try { L5.Parse(); } catch (LexerException e) { System.Console.WriteLine(e.Message); } System.Console.WriteLine("/----------------------------------------------/\n\n"); }