Skip to content
Snippets Groups Projects
Commit c8257804 authored by Илья's avatar Илья
Browse files

test3

parent 772d33b6
Branches
No related merge requests found
Pipeline #5592 passed with warnings with stages
in 7 minutes and 46 seconds
......@@ -7,24 +7,63 @@ AlphaDigit {Alpha}|{Digit}
INTNUM {Digit}+
REALNUM {INTNUM}\.{INTNUM}
ID {Alpha}{AlphaDigit}*
DotChr [^\r\n]
OneLineCmnt \/\/{DotChr}*
Chars [^']
STRING \'{Chars}*\'
// , - Scanner
%{
public int LexValueInt;
public double LexValueDouble;
public int idCount = 0;
public int maxIdLength = int.MinValue;
public int minIdLength = int.MaxValue;
public double avgIdLength;
public int sumInt = 0;
public double sumDouble = 0.0;
public List<string> idsInComment = new List<string>();
%}
%x COMMENT
%%
{INTNUM} {
LexValueInt = int.Parse(yytext);
sumInt += LexValueInt;
return (int)Tok.INUM;
}
{REALNUM} {
LexValueDouble = double.Parse(yytext);
sumDouble += LexValueDouble;
return (int)Tok.RNUM;
}
{STRING} {
return (int)Tok.STRINGAP;
}
{OneLineCmnt} {
}
"{" {
// COMMENT
BEGIN(COMMENT);
}
<COMMENT> "}" {
// INITIAL
BEGIN(INITIAL);
}
begin {
return (int)Tok.BEGIN;
}
......@@ -37,7 +76,30 @@ cycle {
return (int)Tok.CYCLE;
}
<COMMENT> {ID} {
if(yytext != "begin" && yytext != "end" && yytext != "cycle"){
idsInComment.Add(yytext);
}
}
{ID} {
if(yytext == "begin"){
return (int)Tok.BEGIN;
}
idCount += 1;
if(yytext.Length > maxIdLength){
maxIdLength = yytext.Length;
}
if(yytext.Length < minIdLength){
minIdLength = yytext.Length;
}
avgIdLength += yytext.Length;
return (int)Tok.ID;
}
......@@ -53,11 +115,17 @@ cycle {
return (int)Tok.SEMICOLON;
}
[\0] {
avgIdLength /= idCount;
return 0;
}
[^ \r\n] {
LexError();
return 0; //
}
%%
// - Scanner
......
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