From d9df89f6ec524d74fc8c6aad0de749100f22ad1f Mon Sep 17 00:00:00 2001 From: MaksimShagov <43129418+MaksimShagov@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:21:32 +0300 Subject: [PATCH] move rules to section --- benchmarks/flex/lexer.l | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/benchmarks/flex/lexer.l b/benchmarks/flex/lexer.l index d4834402..dcddab43 100644 --- a/benchmarks/flex/lexer.l +++ b/benchmarks/flex/lexer.l @@ -9,16 +9,23 @@ FILE *fp; %} +/*Definition block*/ DIGIT [0-9] IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]* KEYWORD "bool"|"int"|"str"|"else"|"range"|"for"|"import"|"def"|"or"|"not"|"True"|"False"|"float"|"if"|"elif"|"while"|"break"|"continue"|"return"|"and"|"in"|"None" OPERATOR "%"|","|"-"|"=="|">"|"("|"."|"="|"*"|"!="|"<="|")"|"]"|"+"|"/"|"<"|">="|"[" -SPECIAL ":"|"->"|" "++|[\n] +SPECIAL ":"|"->"|" "|[\n] QUOTE1 "\'"[^'\\]*"\'" QUOTE2 "\""[^"\\]*"\"" -%% -{DIGIT}+ { +/*Rules blok*/ +INTEGER {DIGIT}+ +FLOAT {DIGIT}+"."{DIGIT}* +STRINGS {QUOTE1}|{QUOTE2} + +/*States rections*/ +%% +{INTEGER} { #ifdef PRINT printf( "An integer: %s (%d)\n", yytext, atoi( yytext ) ); #endif @@ -29,7 +36,7 @@ QUOTE2 "\""[^"\\]*"\"" #endif } -{DIGIT}+"."{DIGIT}* { +{FLOAT} { #ifdef PRINT printf( "A float: %s (%g)\n", yytext, atof( yytext ) ); #endif @@ -73,7 +80,7 @@ QUOTE2 "\""[^"\\]*"\"" #endif } -{QUOTE1}|{QUOTE2} { +{STRINGS} { #ifdef PRINT printf( "An string: %s\n", yytext ); #endif @@ -95,7 +102,7 @@ QUOTE2 "\""[^"\\]*"\"" #endif } -[ ] printf( "Space: %s\n", yytext ); +[ ] printf( "Space: %s\n", yytext ); "{"[^}\n]*"}" printf( "Unrecognized character: %s\n", yytext );/* eat up one-line comments */ @@ -104,6 +111,8 @@ QUOTE2 "\""[^"\\]*"\"" %% +/* User code*/ + main(int argc, char **argv) { ++argv, --argc; /* skip over program name */