Skip to content

Commit

Permalink
move rules to section
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimShagov committed Mar 26, 2024
1 parent 2626cb6 commit d9df89f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions benchmarks/flex/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +36,7 @@ QUOTE2 "\""[^"\\]*"\""
#endif
}

{DIGIT}+"."{DIGIT}* {
{FLOAT} {
#ifdef PRINT
printf( "A float: %s (%g)\n", yytext, atof( yytext ) );
#endif
Expand Down Expand Up @@ -73,7 +80,7 @@ QUOTE2 "\""[^"\\]*"\""
#endif
}

{QUOTE1}|{QUOTE2} {
{STRINGS} {
#ifdef PRINT
printf( "An string: %s\n", yytext );
#endif
Expand All @@ -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 */


Expand All @@ -104,6 +111,8 @@ QUOTE2 "\""[^"\\]*"\""

%%

/* User code*/

main(int argc, char **argv)
{
++argv, --argc; /* skip over program name */
Expand Down

0 comments on commit d9df89f

Please sign in to comment.