diff --git a/Module2/SimpleLangLexer/SimpleLexer.cs b/Module2/SimpleLangLexer/SimpleLexer.cs index 7bd0af4e65a57a95a208e01d8242bf4f0d50d410..985fa987e98c39788c8a4aace6fcff004a004ed2 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 14165974a952d77ad4d72a746988f0904d4bc9e2..ea8d836f583459895bb9791e893d73e14544edd5 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]