diff --git a/Module2/SimpleLangLexer/SimpleLexer.cs b/Module2/SimpleLangLexer/SimpleLexer.cs index 7bd0af4e65a57a95a208e01d8242bf4f0d50d410..ff75d8156f39e1563a02ec98466eda2d2de5a924 100644 --- a/Module2/SimpleLangLexer/SimpleLexer.cs +++ b/Module2/SimpleLangLexer/SimpleLexer.cs @@ -100,6 +100,14 @@ namespace SimpleLexer keywordsMap["begin"] = Tok.BEGIN; keywordsMap["end"] = Tok.END; keywordsMap["cycle"] = Tok.CYCLE; + + //1 + keywordsMap["div"] = Tok.DIV; + keywordsMap["mod"] = Tok.MOD; + keywordsMap["and"] = Tok.AND; + keywordsMap["or"] = Tok.OR; + keywordsMap["not"] = Tok.NOT; + } public string FinishCurrentLine() @@ -166,12 +174,122 @@ namespace SimpleLexer 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 == '=') + { + NextCh(); + LexKind = Tok.PLUSASSIGN; + } + else + { + LexKind = Tok.PLUS; + } + } + else if (currentCh == '-') + { + NextCh(); + if (currentCh == '=') + { + NextCh(); + LexKind = Tok.MINUSASSIGN; + } + else { - LexError("= was expected"); + LexKind = Tok.MINUS; } + } + else if (currentCh == '*') + { NextCh(); - LexKind = Tok.ASSIGN; + if (currentCh == '=') + { + NextCh(); + LexKind = Tok.MULTASSIGN; + } + else + { + LexKind = Tok.MULT; + } + } + else if (currentCh == '/') + { + NextCh(); + if (currentCh == '=') + { + NextCh(); + LexKind = Tok.DIVASSIGN; + } + else if (currentCh == '/') + { + while (currentCh != '\0' && currentCh != '\n') + NextCh(); + if (currentCh == '\0') + LexKind = Tok.EOF; + else + NextLexem(); + } + else + { + LexKind = Tok.DIVISION; + } + } + else if (currentCh == '>') + { + NextCh(); + LexKind = Tok.GT; + if (currentCh == '=') + { + NextCh(); + LexKind = Tok.GEQ; + } + } + else if (currentCh == '<') + { + NextCh(); + LexKind = Tok.LT; + if (currentCh == '=') + { + NextCh(); + LexKind = Tok.LEQ; + } + if (currentCh == '>') + { + NextCh(); + LexKind = Tok.NEQ; + } + } + else if (currentCh == '=') + { + NextCh(); + LexKind = Tok.EQ; + } + else if (currentCh == '{') + { + while (currentCh != '}') + { + if (currentCh == '\0') + LexError("End-of-lexem found, '}' Expected"); + 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]