From 1975a6e8f80d06571c7990e2a3af387889160c36 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 19 Oct 2023 11:51:41 +0300 Subject: [CI/PA1] Reworked certain regexes into definitions --- .../coolc-spim/my-code/coursework/pa1/cool.flex | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex b/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex index 9854f17..367c149 100644 --- a/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex +++ b/Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex @@ -76,6 +76,10 @@ unsigned openedComments = 0; * char *error_msg; */ +ALL (.|\n) +ENDL \n|\r\n +BLANK [ \f\t\v\r] +IDENT [A-Za-z0-9_] %x MULTILINE @@ -84,7 +88,7 @@ unsigned openedComments = 0; --[^\n\r]* { } \(\* { openedComments++; BEGIN(MULTILINE); } \*\) { if (--openedComments == 0) BEGIN(INITIAL); } -[\n\r] { curr_lineno++; } +{ENDL} { curr_lineno++; } . { } <> { cool_yylval.error_msg = "EOF in comment"; BEGIN(INITIAL); return (ERROR); } @@ -126,14 +130,14 @@ unsigned openedComments = 0; "<-" { return (ASSIGN); } (t(?i:rue)|f(?i:alse)) { cool_yylval.boolean = *yytext == 't'; return (BOOL_CONST); } -[a-z][A-Za-z0-9_]* { cool_yylval.symbol = inttable.add_string(yytext); return (OBJECTID); } -[0-9]+ { cool_yylval.symbol = inttable.add_string(yytext); return (INT_CONST); } -[A-Z][A-Za-z0-9_]* { cool_yylval.symbol = inttable.add_string(yytext); return (TYPEID); } +[a-z]{IDENT}* { cool_yylval.symbol = inttable.add_string(yytext); return (OBJECTID); } +[0-9]+ { cool_yylval.symbol = inttable.add_string(yytext); return (INT_CONST); } +[A-Z]{IDENT}* { cool_yylval.symbol = inttable.add_string(yytext); return (TYPEID); } \{|\}|\(|\)|:|;|,|@|\.|\+|-|\*|\/|~|<|<=|= { return *yytext; } -[\n\r] { curr_lineno++; } -[ \f\t\v] { } . { cool_yylval.error_msg = yytext; return (ERROR); } +{ENDL} { curr_lineno++; } +{BLANK} { } %% -- cgit v1.3.1-26-gb76a