From bd8ffaf3114a157d8135d0cb0c77257690e4a87f Mon Sep 17 00:00:00 2001
From: selfmadekirich <tosha.kirichenko.2001@mail.ru>
Date: Tue, 20 Sep 2022 02:03:19 +0300
Subject: [PATCH] module 2 done

---
 Module2/SimpleLangLexer/SimpleLexer.cs | 152 ++++++++++++++++++++++++-
 TestSimpleLexer/Tests.cs               |  10 +-
 2 files changed, 153 insertions(+), 9 deletions(-)

diff --git a/Module2/SimpleLangLexer/SimpleLexer.cs b/Module2/SimpleLangLexer/SimpleLexer.cs
index 7bd0af4..f4ed8a4 100644
--- a/Module2/SimpleLangLexer/SimpleLexer.cs
+++ b/Module2/SimpleLangLexer/SimpleLexer.cs
@@ -100,6 +100,12 @@ namespace SimpleLexer
             keywordsMap["begin"] = Tok.BEGIN;
             keywordsMap["end"] = Tok.END;
             keywordsMap["cycle"] = Tok.CYCLE;
+            keywordsMap["div"] = Tok.DIV;
+            keywordsMap["mod"] = Tok.MOD;
+            keywordsMap["and"] = Tok.AND;
+            keywordsMap["or"] = Tok.OR;
+            keywordsMap["not"] = Tok.NOT;  
+               
         }
 
         public string FinishCurrentLine()
@@ -158,6 +164,57 @@ namespace SimpleLexer
             LexCol = col;
             // Тип лексемы определяется по ее первому символу
             // Для каждой лексемы строится синтаксическая диаграмма
+            if (currentCh == '/')
+            {
+                NextCh();
+
+                if (currentCh == '=')
+                {
+                    NextCh();
+                    LexKind = Tok.DIVASSIGN;
+                    return;
+                }
+                else if (currentCh == '/')
+                {
+                    NextCh();
+                    while (currentCh != '\n' && (int)currentCh != 0)
+                        NextCh();
+                    if ((int)currentCh == 0)
+                        LexKind = Tok.EOF;
+                    else
+                    {
+                        PassSpaces();
+                        LexText = "";
+                    }
+
+                }
+                else
+                {
+                    LexKind = Tok.DIVISION;
+                    return;
+                }
+               
+            }
+            else if(currentCh == '{')
+            {
+             
+                while (currentCh != '}' && (int)currentCh != 0)
+                       NextCh();
+
+                 if (currentCh == '}')
+                 {
+                    NextCh();
+                    PassSpaces();
+                    LexText = "";
+              
+                 }
+                 else  if((int)currentCh == 0)
+                {
+                    LexError("Incorrect symbol " + currentCh);
+                }
+
+            }
+
             if (currentCh == ';')
             {
                 NextCh();
@@ -168,10 +225,20 @@ namespace SimpleLexer
                 NextCh();
                 if (currentCh != '=')
                 {
-                    LexError("= was expected");
+                    LexKind = Tok.COLON;
+                    //LexError("= was expected");
+                }
+                else
+                {
+                    LexKind = Tok.ASSIGN;
+                    NextCh();
                 }
+                
+            }
+            else if (currentCh == '=')
+            {
                 NextCh();
-                LexKind = Tok.ASSIGN;
+                LexKind = Tok.EQ;
             }
             else if (char.IsLetter(currentCh))
             {
@@ -197,8 +264,87 @@ namespace SimpleLexer
                 LexValue = Int32.Parse(LexText);
                 LexKind = Tok.INUM;
             }
-            else if ((int)currentCh == 0)
+            else if(currentCh == ',')
+            {
+                NextCh();
+                LexKind = Tok.COMMA;
+            }
+            else if (currentCh == '+')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    NextCh();
+                    LexKind = Tok.PLUSASSIGN;
+                }
+                else
+                {
+                    LexKind = Tok.PLUS;
+                }
+                
+            }
+            else if (currentCh == '-')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    NextCh();
+                    LexKind = Tok.MINUSASSIGN;
+                }
+                else
+                {
+                    LexKind = Tok.MINUS;
+                }
+               
+            }
+            else if (currentCh == '*')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    NextCh();
+                    LexKind = Tok.MULTASSIGN;
+                }
+                else
+                {
+                    
+                    LexKind = Tok.MULT;
+                }
+                
+            }
+            else if (currentCh == '>')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    NextCh();
+                    LexKind = Tok.GEQ;
+                }
+                else
+                {
+                    LexKind = Tok.GT;
+                }
+
+            }
+            else if (currentCh == '<')
             {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    NextCh();
+                    LexKind = Tok.LEQ;
+                }
+                else if (currentCh == '>')
+                {
+                    NextCh();
+                    LexKind = Tok.NEQ;
+                }
+                else
+                    LexKind = Tok.LT;
+
+            }
+            else if ((int)currentCh == 0)
+            {  
                 LexKind = Tok.EOF;
             }
             else
diff --git a/TestSimpleLexer/Tests.cs b/TestSimpleLexer/Tests.cs
index 1416597..9407550 100644
--- a/TestSimpleLexer/Tests.cs
+++ b/TestSimpleLexer/Tests.cs
@@ -19,7 +19,6 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
     public class TestSimpleLexer
     {
         public static List< KeyValuePair<Tok, string> > getLexerOutput(Lexer l)
@@ -56,7 +55,6 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
     public class TestSimpleLexerOps
     {
         [Test]
@@ -126,7 +124,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+   
     public class TestSimpleLexerAssigns
     {
         [Test]
@@ -164,7 +162,7 @@ namespace TestSimpleLexer
     public class TestSimpleLexerComparisons
     {
         [Test]
-        [Ignore("This test is disabled")]
+     
         public void TestComparisons()
         {
             string text = @"><>>=<=+<> > <=";
@@ -218,7 +216,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+
     public class TestSimpleLexerLineCmt
     {
         [Test]
@@ -280,7 +278,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+    
     public class TestSimpleLexerMultLineCmt
     {
         [Test]
-- 
GitLab