Skip to content
Snippets Groups Projects
Commit 4d38e7d4 authored by lusparon332's avatar lusparon332
Browse files

lab3 done

parent 6532ce82
Branches
No related merge requests found
Pipeline #5556 passed with warnings with stages
in 6 minutes and 55 seconds
File added
......@@ -46,8 +46,32 @@ namespace GeneratedLexer
if (tok == (int)Tok.EOF)
{
idsInComment = myScanner.idsInComment;
break;
}
else if (tok == (int)Tok.ID)
{
++idCount;
if (myScanner.yytext.Length < minIdLength)
minIdLength = myScanner.yytext.Length;
if (myScanner.yytext.Length > maxIdLength)
maxIdLength = myScanner.yytext.Length;
avgIdLength = (avgIdLength * (idCount - 1) + myScanner.yytext.Length) / idCount;
}
else if (tok == (int)Tok.RNUM)
{
sumDouble += double.Parse(myScanner.yytext);
}
else if (tok == (int)Tok.INUM)
{
sumInt += int.Parse(myScanner.yytext);
}
} while (true);
}
}
......
This diff is collapsed.
......@@ -7,13 +7,19 @@ AlphaDigit {Alpha}|{Digit}
INTNUM {Digit}+
REALNUM {INTNUM}\.{INTNUM}
ID {Alpha}{AlphaDigit}*
DotChr [^\r\n]
OneLineCmnt \/\/{DotChr}*
StringUp \'[^']*\'
// , - Scanner
%{
public int LexValueInt;
public double LexValueDouble;
public List<string> idsInComment = new List<string>();
%}
%x COMMENT
%%
{INTNUM} {
LexValueInt = int.Parse(yytext);
......@@ -41,6 +47,44 @@ cycle {
return (int)Tok.ID;
}
{OneLineCmnt} {
return (int)Tok.COMMENT;
}
{StringUp} {
return (int)Tok.STRINGAP;
}
"{" {
// COMMENT
BEGIN(COMMENT);
return (int)Tok.LONGCOMMENT;
}
<COMMENT> "}" {
// INITIAL
BEGIN(INITIAL);
return (int)Tok.LONGCOMMENT;
}
<COMMENT>begin {
}
<COMMENT>end {
}
<COMMENT>cycle {
}
<COMMENT>{ID} {
// ID
idsInComment.Add(yytext);
}
":" {
return (int)Tok.COLON;
}
......@@ -55,7 +99,7 @@ cycle {
[^ \r\n] {
LexError();
return 0; //
return 0; //
}
%%
......@@ -64,7 +108,7 @@ cycle {
public void LexError()
{
Console.WriteLine("({0},{1}): {2}", yyline, yycol, yytext);
Console.WriteLine("({0},{1}): {2}", yyline, yycol, yytext);
}
public string TokToString(Tok tok)
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.13.3" targetFramework="net40" />
<package id="NUnit.ConsoleRunner" version="3.15.2" targetFramework="net40" />
<package id="NUnit3TestAdapter" version="4.2.1" targetFramework="net40" />
</packages>
\ No newline at end of file
......@@ -40,17 +40,20 @@ namespace TestGeneratedLexer
}
[Test]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public void TestString()
{
LexerAddon lexer = new LexerAddon(@"3 389 3 'ssfsf ' ");
lexer.Lex();
Assert.AreEqual(395, lexer.sumInt);
Assert.AreEqual(0.0, lexer.sumDouble, 0.001);
Assert.AreEqual(0, lexer.idCount);
// TODO: checks in this test
}
[Test]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public void TestSingleLineCmt()
{
LexerAddon lexer = new LexerAddon(@"i22d1 5.6 // i 32 id3
......@@ -63,7 +66,7 @@ namespace TestGeneratedLexer
}
[Test]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public void TestMultiLineCmt()
{
LexerAddon lexer = new LexerAddon(@"i22d1 5.6 { i 32 id3
......@@ -76,7 +79,7 @@ namespace TestGeneratedLexer
}
[Test]
[Ignore("This test is disabled")]
//[Ignore("This test is disabled")]
public void TestMultiLineCmtIds()
{
LexerAddon lexer = new LexerAddon(@"i22d1 5.6 { i 32 id3
......
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