diff --git a/Module2/SimpleLangLexer/SimpleLexer.cs b/Module2/SimpleLangLexer/SimpleLexer.cs index 7bd0af4e65a57a95a208e01d8242bf4f0d50d410..f4ed8a4b5cfe56765dc1a2738cf478b9ddcc3733 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 14165974a952d77ad4d72a746988f0904d4bc9e2..94075504fd76090977df6b63c25a3f81acdf45db 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]