Skip to content
Snippets Groups Projects
Commit 6532ce82 authored by unknown's avatar unknown
Browse files

lab2 done

parent 914e2b43
Branches
No related merge requests found
Pipeline #5450 passed with warnings with stages
in 6 minutes and 30 seconds
...@@ -83,7 +83,8 @@ namespace SimpleLexer ...@@ -83,7 +83,8 @@ namespace SimpleLexer
NextLexem(); // Считать первую лексему, заполнив LexText, LexKind и, возможно, LexValue NextLexem(); // Считать первую лексему, заполнив LexText, LexKind и, возможно, LexValue
} }
public void Init() { public void Init()
{
} }
...@@ -100,9 +101,14 @@ namespace SimpleLexer ...@@ -100,9 +101,14 @@ 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()
{ {
return CurrentLineText + inputReader.ReadLine(); return CurrentLineText + inputReader.ReadLine();
} }
...@@ -156,24 +162,135 @@ namespace SimpleLexer ...@@ -156,24 +162,135 @@ namespace SimpleLexer
LexText = ""; LexText = "";
LexRow = row; LexRow = row;
LexCol = col; LexCol = col;
// Тип лексемы определяется по ее первому символу // Тип лексемы определяется по ее первому символу
// Для каждой лексемы строится синтаксическая диаграмма // Для каждой лексемы строится синтаксическая диаграмма
if (currentCh == ';') if (currentCh == ';')
{ {
NextCh(); NextCh();
LexKind = Tok.SEMICOLON; LexKind = Tok.SEMICOLON;
} }
else if (currentCh == ':') else if (currentCh == ':')
{ {
NextCh(); NextCh();
if (currentCh != '=') if (currentCh == '=')
{ {
LexError("= was expected"); NextCh();
} LexKind = Tok.ASSIGN;
NextCh(); }
LexKind = Tok.ASSIGN; else
} {
else if (char.IsLetter(currentCh)) 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
{
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.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("Неверное использование комментариев {}.");
NextCh();
}
NextCh();
NextLexem();
}
else if (char.IsLetter(currentCh))
{ {
while (char.IsLetterOrDigit(currentCh)) while (char.IsLetterOrDigit(currentCh))
{ {
......
...@@ -19,7 +19,7 @@ namespace TestSimpleLexer ...@@ -19,7 +19,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")] //[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 +56,7 @@ namespace TestSimpleLexer ...@@ -56,7 +56,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")] //[Ignore("This test is disabled")]
public class TestSimpleLexerOps public class TestSimpleLexerOps
{ {
[Test] [Test]
...@@ -126,7 +126,7 @@ namespace TestSimpleLexer ...@@ -126,7 +126,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")] //[Ignore("This test is disabled")]
public class TestSimpleLexerAssigns public class TestSimpleLexerAssigns
{ {
[Test] [Test]
...@@ -164,7 +164,7 @@ namespace TestSimpleLexer ...@@ -164,7 +164,7 @@ namespace TestSimpleLexer
public class TestSimpleLexerComparisons public class TestSimpleLexerComparisons
{ {
[Test] [Test]
[Ignore("This test is disabled")] //[Ignore("This test is disabled")]
public void TestComparisons() public void TestComparisons()
{ {
string text = @"><>>=<=+<> > <="; string text = @"><>>=<=+<> > <=";
...@@ -218,7 +218,7 @@ namespace TestSimpleLexer ...@@ -218,7 +218,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")] //[Ignore("This test is disabled")]
public class TestSimpleLexerLineCmt public class TestSimpleLexerLineCmt
{ {
[Test] [Test]
...@@ -280,7 +280,7 @@ namespace TestSimpleLexer ...@@ -280,7 +280,7 @@ namespace TestSimpleLexer
} }
[TestFixture] [TestFixture]
[Ignore("This test is disabled")] //[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