diff --git a/Module3/Gplex.exe b/Module3/Gplex.exe new file mode 100644 index 0000000000000000000000000000000000000000..8999c93225e4fccd4075d3c30c657b298c4c6e2c Binary files /dev/null and b/Module3/Gplex.exe differ diff --git a/Module3/LexerAddon.cs b/Module3/LexerAddon.cs index c2467796d99e34b2906c362b66cf925504fe57e5..01afbf5509836d7e7858baf6bb6a098d28f2ceef 100644 --- a/Module3/LexerAddon.cs +++ b/Module3/LexerAddon.cs @@ -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); } } diff --git a/Module3/SimpleLex.cs b/Module3/SimpleLex.cs index d8f9df81a5460e11bf2e732ea49905ce52e6f7fa..83c9574ec1148b4f2cf9a6dcac09b4a86fa27902 100644 --- a/Module3/SimpleLex.cs +++ b/Module3/SimpleLex.cs @@ -1,14 +1,10 @@ // // This CSharp output file generated by Gardens Point LEX -// Gardens Point LEX (GPLEX) is Copyright (c) John Gough, QUT 2006-2014. -// Output produced by GPLEX is the property of the user. -// See accompanying file GPLEXcopyright.rtf. -// -// GPLEX Version: 1.2.2 -// Machine: MAINHOMEPC2 -// DateTime: 30.09.2018 17:57:38 -// UserName: someone -// GPLEX input file <SimpleLex.lex - 30.09.2018 17:56:56> +// Version: 1.2.0 +// Machine: LAPTOP-8RKO19AH +// DateTime: 03.10.2022 21:30:51 +// UserName: luspa +// GPLEX input file <SimpleLex.lex - 03.10.2022 21:26:04> // GPLEX frame file <embedded resource> // // Option settings: noParser, minimize @@ -16,8 +12,8 @@ // // -// Revised backup code -// Version 1.2.1 of 24-June-2013 +// Experimental embedded frame +// Version 1.1.4 of 10-May-2010 // // #define BACKUP @@ -126,15 +122,17 @@ namespace SimpleScanner enum Result {accept, noMatch, contextFound}; - const int maxAccept = 20; - const int initial = 21; + const int maxAccept = 40; + const int initial = 41; const int eofNum = 0; const int goStart = -1; const int INITIAL = 0; + const int COMMENT = 1; #region user code public int LexValueInt; public double LexValueDouble; + public List<string> idsInComment = new List<string>(); #endregion user code int state; @@ -166,112 +164,208 @@ public int LexValueInt; } }; - static int[] startState = new int[] {21, 0}; + static int[] startState = new int[] {41, 44, 0}; - static Table[] NxS = new Table[23] { + static Table[] NxS = new Table[45] { /* NxS[ 0] */ new Table(0, 0, 0, null), /* NxS[ 1] */ new Table(0, 0, -1, null), -/* NxS[ 2] */ new Table(46, 12, -1, new sbyte[] {22, -1, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2}), -/* NxS[ 3] */ new Table(61, 1, -1, new sbyte[] {19}), -/* NxS[ 4] */ new Table(0, 0, -1, null), -/* NxS[ 5] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 6] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 15, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 7] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 11, 5}), -/* NxS[ 8] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 9, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 9] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 10, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 10] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 11] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 12, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 12] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 13, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 13] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 14, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 14] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 15] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 16, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 16] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 17, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 17] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 18, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 18] */ new Table(48, 75, -1, new sbyte[] {5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, -1, -1, -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, -1, -1, -1, -1, 5, -1, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5}), -/* NxS[ 19] */ new Table(0, 0, -1, null), -/* NxS[ 20] */ new Table(48, 10, -1, new sbyte[] {20, 20, 20, 20, 20, 20, - 20, 20, 20, 20}), -/* NxS[ 21] */ new Table(10, 113, 1, new sbyte[] {-1, 1, 1, -1, 1, 1, +/* NxS[ 2] */ new Table(39, 1, 43, new sbyte[] {25}), +/* NxS[ 3] */ new Table(47, 1, -1, new sbyte[] {24}), +/* NxS[ 4] */ new Table(46, 12, -1, new sbyte[] {42, -1, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4}), +/* NxS[ 5] */ new Table(61, 1, -1, new sbyte[] {22}), +/* NxS[ 6] */ new Table(0, 0, -1, null), +/* NxS[ 7] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 8] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 18, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 9] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 14, 7}), +/* NxS[ 10] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 12, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 11] */ new Table(0, 0, -1, null), +/* NxS[ 12] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 13, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 13] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 14] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 15, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 15] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 16, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 16] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 17, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 17] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 18] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 19, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 19] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 20, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 20] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 21, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 21] */ new Table(48, 75, -1, new sbyte[] {7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, -1, -1, -1, -1, -1, -1, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, -1, -1, -1, -1, 7, -1, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7}), +/* NxS[ 22] */ new Table(0, 0, -1, null), +/* NxS[ 23] */ new Table(48, 10, -1, new sbyte[] {23, 23, 23, 23, 23, 23, + 23, 23, 23, 23}), +/* NxS[ 24] */ new Table(10, 4, 24, new sbyte[] {-1, 24, 24, -1}), +/* NxS[ 25] */ new Table(0, 0, -1, null), +/* NxS[ 26] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 27] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 37, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 28] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 33, 26}), +/* NxS[ 29] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 31, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 30] */ new Table(0, 0, -1, null), +/* NxS[ 31] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 32, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 32] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 33] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 34, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 34] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 35, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 35] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 36, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 36] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 37] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 38, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 38] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 39, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 39] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 40, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 40] */ new Table(48, 75, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, -1, -1, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26}), +/* NxS[ 41] */ new Table(10, 114, 1, new sbyte[] {-1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 1, 1, 1, 1, - 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 5, - 1, 5, 6, 7, 5, 8, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}), -/* NxS[ 22] */ new Table(48, 10, -1, new sbyte[] {20, 20, 20, 20, 20, 20, - 20, 20, 20, 20}), + -1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 6, 1, 1, 1, 1, + 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 1, 1, 1, 7, + 1, 7, 8, 9, 7, 10, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 11}), +/* NxS[ 42] */ new Table(48, 10, -1, new sbyte[] {23, 23, 23, 23, 23, 23, + 23, 23, 23, 23}), +/* NxS[ 43] */ new Table(39, 1, 43, new sbyte[] {25}), +/* NxS[ 44] */ new Table(65, 61, -1, new sbyte[] {26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, -1, -1, 26, -1, 26, 27, 28, 26, 29, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, -1, -1, 30}), }; int NextState() { @@ -644,52 +738,61 @@ int NextState() { // ============== The main tokenizer code ================= - int Scan() { - for (; ; ) { - int next; // next state to enter + int Scan() + { + for (; ; ) + { + int next; // next state to enter +#if BACKUP + Result rslt = Result.noMatch; +#endif // BACKUP #if LEFTANCHORS - for (;;) { + for (;;) + { // Discard characters that do not start any pattern. // Must check the left anchor condition after *every* GetCode! state = ((cCol == 0) ? anchorState[currentScOrd] : currentStart); - if ((next = NextState()) != goStart) break; // LOOP EXIT HERE... + if ((next = NextState()) != goStart) + break; // LOOP EXIT HERE... GetCode(); } #else // !LEFTANCHORS state = currentStart; - while ((next = NextState()) == goStart) { + while ((next = NextState()) == goStart) // At this point, the current character has no // transition from the current state. We discard // the "no-match" char. In traditional LEX such // characters are echoed to the console. GetCode(); - } #endif // LEFTANCHORS // At last, a valid transition ... MarkToken(); state = next; - GetCode(); + GetCode(); + + while ((next = NextState()) > eofNum) // Exit for goStart AND for eofNum #if BACKUP - bool contextSaved = false; - while ((next = NextState()) > eofNum) { // Exit for goStart AND for eofNum - if (state <= maxAccept && next > maxAccept) { // need to prepare backup data - // Store data for the *latest* accept state that was found. - SaveStateAndPos( ref ctx ); - contextSaved = true; + if (state <= maxAccept && next > maxAccept) // need to prepare backup data + { + // ctx is an object. The fields may be + // mutated by the call to Recurse2. + // On return the data in ctx is the + // *latest* accept state that was found. + + rslt = Recurse2(ref ctx, next); + if (rslt == Result.noMatch) + RestoreStateAndPos(ref ctx); + break; } - state = next; - GetCode(); - } - if (state > maxAccept && contextSaved) - RestoreStateAndPos( ref ctx ); -#else // BACKUP - while ((next = NextState()) > eofNum) { // Exit for goStart AND for eofNum - state = next; - GetCode(); - } + else #endif // BACKUP - if (state <= maxAccept) { + { + state = next; + GetCode(); + } + if (state <= maxAccept) + { MarkEnd(); #region ActionSwitch #pragma warning disable 162, 1522 @@ -700,48 +803,92 @@ int NextState() { return (int)Tokens.EOF; break; case 1: + case 2: + case 3: LexError(); return 0; break; - case 2: + case 4: LexValueInt = int.Parse(yytext); return (int)Tok.INUM; break; - case 3: + case 5: return (int)Tok.COLON; break; - case 4: + case 6: return (int)Tok.SEMICOLON; break; - case 5: - case 6: case 7: case 8: case 9: - case 11: + case 10: case 12: - case 13: + case 14: case 15: case 16: - case 17: + case 18: + case 19: + case 20: return (int)Tok.ID; break; - case 10: + case 11: +BEGIN(COMMENT); + return (int)Tok.LONGCOMMENT; + break; + case 13: return (int)Tok.END; break; - case 14: + case 17: return (int)Tok.CYCLE; break; - case 18: + case 21: return (int)Tok.BEGIN; break; - case 19: + case 22: return (int)Tok.ASSIGN; break; - case 20: + case 23: LexValueDouble = double.Parse(yytext); return (int)Tok.RNUM; break; + case 24: +return (int)Tok.COMMENT; + break; + case 25: +return (int)Tok.STRINGAP; + break; + case 26: + case 27: + case 28: + case 29: + case 31: + case 33: + case 34: + case 35: + case 37: + case 38: + case 39: +idsInComment.Add(yytext); + break; + case 30: +BEGIN(INITIAL); + return (int)Tok.LONGCOMMENT; + break; + case 32: +{ + +} + break; + case 36: +{ + +} + break; + case 40: +{ + +} + break; default: break; } @@ -752,7 +899,29 @@ LexValueDouble = double.Parse(yytext); } #if BACKUP - void SaveStateAndPos(ref Context ctx) { + Result Recurse2(ref Context ctx, int next) + { + // Assert: at entry "state" is an accept state AND + // NextState(state, code) != goStart AND + // NextState(state, code) is not an accept state. + // + SaveStateAndPos(ref ctx); + state = next; + GetCode(); + + while ((next = NextState()) > eofNum) + { + if (state <= maxAccept && next > maxAccept) // need to update backup data + SaveStateAndPos(ref ctx); + state = next; + if (state == eofNum) return Result.accept; + GetCode(); + } + return (state <= maxAccept ? Result.accept : Result.noMatch); + } + + void SaveStateAndPos(ref Context ctx) + { ctx.bPos = buffer.Pos; ctx.rPos = readPos; ctx.cCol = cCol; @@ -761,7 +930,8 @@ LexValueDouble = double.Parse(yytext); ctx.cChr = code; } - void RestoreStateAndPos(ref Context ctx) { + void RestoreStateAndPos(ref Context ctx) + { buffer.Pos = ctx.bPos; readPos = ctx.rPos; cCol = ctx.cCol; @@ -769,7 +939,8 @@ LexValueDouble = double.Parse(yytext); state = ctx.state; code = ctx.cChr; } -#endif // BACKUP + +#endif // BACKUP // ============= End of the tokenizer code ================ @@ -803,7 +974,7 @@ LexValueDouble = double.Parse(yytext); public void LexError() { - Console.WriteLine("({0},{1}): ÍåèçâåñòГûé ñèìâîë {2}", yyline, yycol, yytext); + Console.WriteLine("({0},{1}): {2}", yyline, yycol, yytext); } public string TokToString(Tok tok) diff --git a/Module3/SimpleLex.lex b/Module3/SimpleLex.lex index c0434f09b6e8ca1adf55cd70f9ae3e4b18e41e45..779b54f40d7a22a102108293cbdba9314f161992 100644 --- a/Module3/SimpleLex.lex +++ b/Module3/SimpleLex.lex @@ -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) diff --git a/Module3/packages.config b/Module3/packages.config new file mode 100644 index 0000000000000000000000000000000000000000..14b53d1ecb2e718f6d9c15e6fcb20c081a72bdd1 --- /dev/null +++ b/Module3/packages.config @@ -0,0 +1,6 @@ +п»ї<?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 diff --git a/TestGeneratedLexer/Tests.cs b/TestGeneratedLexer/Tests.cs index 57d7d4cfefec38b435448d0de4ad694d624d177e..1a3da97bd3925dd8010663afcb65591f6c1bbebb 100644 --- a/TestGeneratedLexer/Tests.cs +++ b/TestGeneratedLexer/Tests.cs @@ -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