Skip to content
Snippets Groups Projects
Commit 914e2b43 authored by lusparon332's avatar lusparon332
Browse files

lab1 finish

parent 347f7cff
Branches
No related merge requests found
Pipeline #5354 passed with warnings with stages
in 6 minutes and 36 seconds
......@@ -126,9 +126,7 @@ namespace Lexer
NextCh();
if (currentCharValue == -1)
{
Error();
}
var builder1 = new StringBuilder();
......@@ -320,7 +318,45 @@ namespace Lexer
public override bool Parse()
{
throw new NotImplementedException();
NextCh();
List<int> res = new List<int>();
if (currentCharValue == -1)
{
Error();
}
if (!char.IsDigit(currentCh))
Error();
else
{
res.Add(currentCh - '0');
NextCh();
}
while (currentCh == ' ')
{
NextCh();
if (char.IsDigit(currentCh))
{
res.Add(currentCh - '0');
NextCh();
}
else if (currentCh == ' ')
continue;
else
Error();
}
if (currentCharValue != -1)
{
Error();
}
parseResult = res;
return true;
}
}
......@@ -342,7 +378,55 @@ namespace Lexer
public override bool Parse()
{
throw new NotImplementedException();
NextCh();
StringBuilder res = new StringBuilder("");
if (currentCharValue == -1)
{
Error();
}
while (char.IsLetterOrDigit(currentCh))
{
if (char.IsLetter(currentCh))
{
res.Append(currentCh);
NextCh();
}
else
Error();
if (char.IsLetter(currentCh))
{
res.Append(currentCh);
NextCh();
if (currentCharValue == -1)
break;
}
if (char.IsDigit(currentCh))
{
res.Append(currentCh);
NextCh();
if (currentCharValue == -1)
break;
}
if (char.IsDigit(currentCh))
{
res.Append(currentCh);
NextCh();
if (currentCharValue == -1)
break;
}
}
if (currentCharValue != -1)
{
Error();
}
parseResult = res.ToString();
return true;
}
}
......@@ -366,7 +450,80 @@ namespace Lexer
public override bool Parse()
{
throw new NotImplementedException();
NextCh();
StringBuilder res = new StringBuilder("");
if (currentCharValue == -1)
{
Error();
}
if (char.IsDigit(currentCh))
{
if (currentCh == '0')
{
res.Append(currentCh);
NextCh();
if (currentCharValue == -1)
{
parseResult = double.Parse(res.ToString());
return true;
}
else if (currentCh != '.' && currentCharValue != -1)
Error();
else if (currentCh == '.')
{
res.Append(currentCh);
NextCh();
if (!char.IsDigit(currentCh))
Error();
}
else
Error();
}
else
{
while (char.IsDigit(currentCh))
{
res.Append(currentCh);
NextCh();
}
if (currentCharValue == -1)
{
parseResult = double.Parse(res.ToString());
return true;
}
else if (currentCh != '.' && currentCharValue != -1)
Error();
else if (currentCh == '.')
{
res.Append(currentCh);
NextCh();
if (!char.IsDigit(currentCh))
Error();
}
else
Error();
}
}
else
Error();
while (char.IsDigit(currentCh))
{
res.Append(currentCh);
NextCh();
}
if (currentCharValue != -1)
{
Error();
}
parseResult = double.Parse(res.ToString());
return true;
}
}
......@@ -390,7 +547,41 @@ namespace Lexer
public override bool Parse()
{
throw new NotImplementedException();
NextCh();
StringBuilder res = new StringBuilder("");
if (currentCharValue == -1)
{
Error();
}
if (currentCh != '\'')
Error();
res.Append(currentCh);
NextCh();
while (currentCh != '\'')
{
if (currentCharValue == -1)
Error();
res.Append(currentCh);
NextCh();
}
if (currentCh != '\'')
Error();
res.Append(currentCh);
NextCh();
if (currentCharValue != -1)
{
Error();
}
parseResult = res.ToString();
return true;
}
}
......@@ -413,7 +604,45 @@ namespace Lexer
public override bool Parse()
{
throw new NotImplementedException();
NextCh();
StringBuilder res = new StringBuilder("");
if (currentCharValue == -1)
Error();
if (currentCh != '/')
Error();
res.Append(currentCh);
NextCh();
if (currentCh != '*')
Error();
res.Append(currentCh);
NextCh();
while (true)
{
if (currentCharValue == -1)
Error();
if (currentCh == '*')
{
res.Append(currentCh);
NextCh();
if (currentCh == '/')
{
res.Append(currentCh);
NextCh();
if (currentCharValue != -1)
Error();
break;
}
}
res.Append(currentCh);
NextCh();
}
parseResult = res.ToString();
return true;
}
}
......@@ -437,7 +666,18 @@ namespace Lexer
public override bool Parse()
{
throw new NotImplementedException();
NextCh();
StringBuilder res = new StringBuilder("");
StringBuilder ident = new StringBuilder("");
if (currentCharValue == -1)
Error();
IdentLexer l = new IdentLexer("abc22");
return true;
}
}
......@@ -445,16 +685,8 @@ namespace Lexer
{
public static void Main()
{
string input = "154216";
Lexer L = new IntLexer(input);
try
{
L.Parse();
}
catch (LexerException e)
{
System.Console.WriteLine(e.Message);
}
CommentLexer l = new CommentLexer("/**/");
l.Parse();
}
}
......
......@@ -281,7 +281,7 @@ namespace TestLexer
}
[TestFixture]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public class TestDigitListLexer
{
[Test]
......@@ -330,7 +330,7 @@ namespace TestLexer
}
[TestFixture]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public class TestLetterDigitGroupLexer
{
[Test]
......@@ -381,7 +381,7 @@ namespace TestLexer
}
[TestFixture]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public class TestDoubleLexer
{
public TestDoubleLexer()
......@@ -424,7 +424,7 @@ namespace TestLexer
}
[TestFixture]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public class TestQuotedStringLexer
{
......@@ -460,7 +460,7 @@ namespace TestLexer
}
[TestFixture]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public class TestCommentLexer
{
......
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