Skip to content
Snippets Groups Projects
Commit bd8ffaf3 authored by selfmadekirich's avatar selfmadekirich
Browse files

module 2 done

parent c3e0f420
Branches
No related merge requests found
Pipeline #5373 passed with warnings with stages
in 6 minutes and 50 seconds
...@@ -100,6 +100,12 @@ namespace SimpleLexer ...@@ -100,6 +100,12 @@ namespace SimpleLexer
keywordsMap["begin"] = Tok.BEGIN; keywordsMap["begin"] = Tok.BEGIN;
keywordsMap["end"] = Tok.END; keywordsMap["end"] = Tok.END;
keywordsMap["cycle"] = Tok.CYCLE; 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() public string FinishCurrentLine()
...@@ -158,6 +164,57 @@ namespace SimpleLexer ...@@ -158,6 +164,57 @@ namespace SimpleLexer
LexCol = col; 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 == ';') if (currentCh == ';')
{ {
NextCh(); NextCh();
...@@ -168,10 +225,20 @@ namespace SimpleLexer ...@@ -168,10 +225,20 @@ namespace SimpleLexer
NextCh(); NextCh();
if (currentCh != '=') if (currentCh != '=')
{ {
LexError("= was expected"); LexKind = Tok.COLON;
//LexError("= was expected");
}
else
{
LexKind = Tok.ASSIGN;
NextCh();
} }
}
else if (currentCh == '=')
{
NextCh(); NextCh();
LexKind = Tok.ASSIGN; LexKind = Tok.EQ;
} }
else if (char.IsLetter(currentCh)) else if (char.IsLetter(currentCh))
{ {
...@@ -197,8 +264,87 @@ namespace SimpleLexer ...@@ -197,8 +264,87 @@ namespace SimpleLexer
LexValue = Int32.Parse(LexText); LexValue = Int32.Parse(LexText);
LexKind = Tok.INUM; 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; LexKind = Tok.EOF;
} }
else else
......
...@@ -19,7 +19,6 @@ namespace TestSimpleLexer ...@@ -19,7 +19,6 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")]
public class TestSimpleLexer public class TestSimpleLexer
{ {
public static List< KeyValuePair<Tok, string> > getLexerOutput(Lexer l) public static List< KeyValuePair<Tok, string> > getLexerOutput(Lexer l)
...@@ -56,7 +55,6 @@ namespace TestSimpleLexer ...@@ -56,7 +55,6 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")]
public class TestSimpleLexerOps public class TestSimpleLexerOps
{ {
[Test] [Test]
...@@ -126,7 +124,7 @@ namespace TestSimpleLexer ...@@ -126,7 +124,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")]
public class TestSimpleLexerAssigns public class TestSimpleLexerAssigns
{ {
[Test] [Test]
...@@ -164,7 +162,7 @@ namespace TestSimpleLexer ...@@ -164,7 +162,7 @@ namespace TestSimpleLexer
public class TestSimpleLexerComparisons public class TestSimpleLexerComparisons
{ {
[Test] [Test]
[Ignore("This test is disabled")]
public void TestComparisons() public void TestComparisons()
{ {
string text = @"><>>=<=+<> > <="; string text = @"><>>=<=+<> > <=";
...@@ -218,7 +216,7 @@ namespace TestSimpleLexer ...@@ -218,7 +216,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")]
public class TestSimpleLexerLineCmt public class TestSimpleLexerLineCmt
{ {
[Test] [Test]
...@@ -280,7 +278,7 @@ namespace TestSimpleLexer ...@@ -280,7 +278,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")]
public class TestSimpleLexerMultLineCmt public class TestSimpleLexerMultLineCmt
{ {
[Test] [Test]
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment