From a1575200afc3cc0557a08a1fe721d7190962acf6 Mon Sep 17 00:00:00 2001
From: NikitaBogoslovskiy <nbog@sfedu.ru>
Date: Thu, 15 Sep 2022 22:13:01 +0300
Subject: [PATCH] do module 2

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

diff --git a/Module2/SimpleLangLexer/SimpleLexer.cs b/Module2/SimpleLangLexer/SimpleLexer.cs
index 7bd0af4..985fa98 100644
--- a/Module2/SimpleLangLexer/SimpleLexer.cs
+++ b/Module2/SimpleLangLexer/SimpleLexer.cs
@@ -100,6 +100,11 @@ namespace SimpleLexer
             keywordsMap["begin"] = Tok.BEGIN;
             keywordsMap["end"] = Tok.END;
             keywordsMap["cycle"] = Tok.CYCLE;
+            keywordsMap["div"] = Tok.DIV;
+            keywordsMap["mod"] = Tok.MOD;
+            keywordsMap["or"] = Tok.OR;
+            keywordsMap["and"] = Tok.AND;
+            keywordsMap["not"] = Tok.NOT;
         }
 
         public string FinishCurrentLine()
@@ -160,18 +165,137 @@ namespace SimpleLexer
             // Для каждой лексемы строится синтаксическая диаграмма
             if (currentCh == ';')
             {
-                NextCh();
                 LexKind = Tok.SEMICOLON;
+                NextCh();
             }
             else if (currentCh == ':')
             {
                 NextCh();
-                if (currentCh != '=')
+                if (currentCh == '=')
+                {
+                    LexKind = Tok.ASSIGN;
+                    NextCh();
+                }
+                else
+                {
+                    LexKind = Tok.COLON;
+                }
+            }
+            else if (currentCh == ',')
+            {
+                NextCh();
+                LexKind = Tok.COMMA;
+            }
+            else if (currentCh == '+')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    LexKind = Tok.PLUSASSIGN;
+                    NextCh();
+                }
+                else
                 {
-                    LexError("= was expected");
+                    LexKind = Tok.PLUS;
                 }
+            }
+            else if (currentCh == '-')
+            {
                 NextCh();
-                LexKind = Tok.ASSIGN;
+                if (currentCh == '=')
+                {
+                    LexKind = Tok.MINUSASSIGN;
+                    NextCh();
+                }
+                else
+                {
+                    LexKind = Tok.MINUS;
+                }
+            }
+            else if (currentCh == '*')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    LexKind = Tok.MULTASSIGN;
+                    NextCh();
+                }
+                else
+                {
+                    LexKind = Tok.MULT;
+                }
+            }
+            else if (currentCh == '/')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    LexKind = Tok.DIVASSIGN;
+                    NextCh();
+                }
+                else if (currentCh == '/')
+                {
+                    while (currentCh != '\n' && (int)currentCh != 0)
+                        NextCh();
+                    if (currentCh == '\n')
+                    {
+                        NextCh();
+                        NextLexem();
+                    }
+                    else
+                        LexKind = Tok.EOF;
+                }
+                else
+                {
+                    LexKind = Tok.DIVISION;
+                }
+            }
+            else if (currentCh == '=')
+            {
+                LexKind = Tok.EQ;
+                NextCh();
+            }
+            else if (currentCh == '<')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    LexKind = Tok.LEQ;
+                    NextCh();
+                }
+                else if (currentCh == '>')
+                {
+                    LexKind = Tok.NEQ;
+                    NextCh();
+                }
+                else
+                {
+                    LexKind = Tok.LT;
+                }
+            }
+            else if (currentCh == '>')
+            {
+                NextCh();
+                if (currentCh == '=')
+                {
+                    LexKind = Tok.GEQ;
+                    NextCh();
+                }
+                else
+                {
+                    LexKind = Tok.GT;
+                }
+            }
+            else if (currentCh == '{')
+            {
+                while (currentCh != '}')
+                {
+                    if ((int)currentCh == 0)
+                        LexError("Comment section was not finished");
+                    NextCh();
+                }
+                NextCh();
+                NextLexem();
             }
             else if (char.IsLetter(currentCh))
             {
diff --git a/TestSimpleLexer/Tests.cs b/TestSimpleLexer/Tests.cs
index 1416597..ea8d836 100644
--- a/TestSimpleLexer/Tests.cs
+++ b/TestSimpleLexer/Tests.cs
@@ -19,7 +19,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+    //[Ignore("This test is disabled")]
     public class TestSimpleLexer
     {
         public static List< KeyValuePair<Tok, string> > getLexerOutput(Lexer l)
@@ -56,7 +56,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+    //[Ignore("This test is disabled")]
     public class TestSimpleLexerOps
     {
         [Test]
@@ -126,7 +126,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+    //[Ignore("This test is disabled")]
     public class TestSimpleLexerAssigns
     {
         [Test]
@@ -218,7 +218,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+    //[Ignore("This test is disabled")]
     public class TestSimpleLexerLineCmt
     {
         [Test]
@@ -280,7 +280,7 @@ namespace TestSimpleLexer
     }
     
     [TestFixture]
-    [Ignore("This test is disabled")]
+    //[Ignore("This test is disabled")]
     public class TestSimpleLexerMultLineCmt
     {
         [Test]
-- 
GitLab