diff --git a/Module1/Lexer.cs b/Module1/Lexer.cs index 377861d0f465d06abe783068227f2191b964b686..220ad6e5616c3cda796dabb6a704eff479e2b2d0 100644 --- a/Module1/Lexer.cs +++ b/Module1/Lexer.cs @@ -126,9 +126,7 @@ namespace Lexer NextCh(); if (currentCharValue == -1) - { Error(); - } var builder1 = new StringBuilder(); @@ -320,7 +318,45 @@ namespace Lexer public override bool Parse() { - throw new NotImplementedException(); + NextCh(); + + List<int> res = new List<int>(); + + if (currentCharValue == -1) + { + Error(); + } + + if (!char.IsDigit(currentCh)) + Error(); + else + { + res.Add(currentCh - '0'); + NextCh(); + } + + while (currentCh == ' ') + { + NextCh(); + if (char.IsDigit(currentCh)) + { + res.Add(currentCh - '0'); + NextCh(); + } + else if (currentCh == ' ') + continue; + else + Error(); + } + + if (currentCharValue != -1) + { + Error(); + } + + parseResult = res; + + return true; } } @@ -342,7 +378,55 @@ namespace Lexer public override bool Parse() { - throw new NotImplementedException(); + NextCh(); + + StringBuilder res = new StringBuilder(""); + + if (currentCharValue == -1) + { + Error(); + } + + while (char.IsLetterOrDigit(currentCh)) + { + if (char.IsLetter(currentCh)) + { + res.Append(currentCh); + NextCh(); + } + else + Error(); + if (char.IsLetter(currentCh)) + { + res.Append(currentCh); + NextCh(); + if (currentCharValue == -1) + break; + } + if (char.IsDigit(currentCh)) + { + res.Append(currentCh); + NextCh(); + if (currentCharValue == -1) + break; + } + if (char.IsDigit(currentCh)) + { + res.Append(currentCh); + NextCh(); + if (currentCharValue == -1) + break; + } + } + + if (currentCharValue != -1) + { + Error(); + } + + parseResult = res.ToString(); + + return true; } } @@ -366,7 +450,80 @@ namespace Lexer public override bool Parse() { - throw new NotImplementedException(); + NextCh(); + + StringBuilder res = new StringBuilder(""); + + if (currentCharValue == -1) + { + Error(); + } + + if (char.IsDigit(currentCh)) + { + if (currentCh == '0') + { + res.Append(currentCh); + NextCh(); + if (currentCharValue == -1) + { + parseResult = double.Parse(res.ToString()); + return true; + } + else if (currentCh != '.' && currentCharValue != -1) + Error(); + else if (currentCh == '.') + { + res.Append(currentCh); + NextCh(); + if (!char.IsDigit(currentCh)) + Error(); + } + else + Error(); + } + else + { + while (char.IsDigit(currentCh)) + { + res.Append(currentCh); + NextCh(); + } + if (currentCharValue == -1) + { + parseResult = double.Parse(res.ToString()); + return true; + } + else if (currentCh != '.' && currentCharValue != -1) + Error(); + else if (currentCh == '.') + { + res.Append(currentCh); + NextCh(); + if (!char.IsDigit(currentCh)) + Error(); + } + else + Error(); + } + + } + else + Error(); + + while (char.IsDigit(currentCh)) + { + res.Append(currentCh); + NextCh(); + } + + if (currentCharValue != -1) + { + Error(); + } + + parseResult = double.Parse(res.ToString()); + return true; } } @@ -390,7 +547,41 @@ namespace Lexer public override bool Parse() { - throw new NotImplementedException(); + NextCh(); + + StringBuilder res = new StringBuilder(""); + + if (currentCharValue == -1) + { + Error(); + } + + if (currentCh != '\'') + Error(); + res.Append(currentCh); + NextCh(); + + while (currentCh != '\'') + { + if (currentCharValue == -1) + Error(); + res.Append(currentCh); + NextCh(); + } + + if (currentCh != '\'') + Error(); + res.Append(currentCh); + NextCh(); + + if (currentCharValue != -1) + { + Error(); + } + + parseResult = res.ToString(); + + return true; } } @@ -413,7 +604,45 @@ namespace Lexer public override bool Parse() { - throw new NotImplementedException(); + NextCh(); + + StringBuilder res = new StringBuilder(""); + + if (currentCharValue == -1) + Error(); + + if (currentCh != '/') + Error(); + res.Append(currentCh); + NextCh(); + if (currentCh != '*') + Error(); + res.Append(currentCh); + NextCh(); + + while (true) + { + if (currentCharValue == -1) + Error(); + if (currentCh == '*') + { + res.Append(currentCh); + NextCh(); + if (currentCh == '/') + { + res.Append(currentCh); + NextCh(); + if (currentCharValue != -1) + Error(); + break; + } + } + res.Append(currentCh); + NextCh(); + } + + parseResult = res.ToString(); + return true; } } @@ -437,7 +666,18 @@ namespace Lexer public override bool Parse() { - throw new NotImplementedException(); + NextCh(); + + StringBuilder res = new StringBuilder(""); + StringBuilder ident = new StringBuilder(""); + + if (currentCharValue == -1) + Error(); + + + IdentLexer l = new IdentLexer("abc22"); + + return true; } } @@ -445,16 +685,8 @@ namespace Lexer { public static void Main() { - string input = "154216"; - Lexer L = new IntLexer(input); - try - { - L.Parse(); - } - catch (LexerException e) - { - System.Console.WriteLine(e.Message); - } + CommentLexer l = new CommentLexer("/**/"); + l.Parse(); } } diff --git a/TestLexer/Tests.cs b/TestLexer/Tests.cs index 1c4d882919629971d183406cdc2fc8c55350b84e..7c9897ac66c87bbe0880098385555373bcbf0ad5 100644 --- a/TestLexer/Tests.cs +++ b/TestLexer/Tests.cs @@ -281,7 +281,7 @@ namespace TestLexer } [TestFixture] - [Ignore("This test is disabled")] + //[Ignore("This test is disabled")] public class TestDigitListLexer { [Test] @@ -330,7 +330,7 @@ namespace TestLexer } [TestFixture] - [Ignore("This test is disabled")] + //[Ignore("This test is disabled")] public class TestLetterDigitGroupLexer { [Test] @@ -381,7 +381,7 @@ namespace TestLexer } [TestFixture] - [Ignore("This test is disabled")] + //[Ignore("This test is disabled")] public class TestDoubleLexer { public TestDoubleLexer() @@ -424,7 +424,7 @@ namespace TestLexer } [TestFixture] - [Ignore("This test is disabled")] + //[Ignore("This test is disabled")] public class TestQuotedStringLexer { @@ -460,7 +460,7 @@ namespace TestLexer } [TestFixture] - [Ignore("This test is disabled")] + //[Ignore("This test is disabled")] public class TestCommentLexer {