Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit1975a6e8f80d06571c7990e2a3af387889160c36 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-10-19 11:51:41 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-10-19 11:51:41 +0300
Files426b3524e0e9b8cc94609ad5f9c8f69957dfa028
uni-projects-1975a6e8f80d06571c7990e2a3af387889160c36.tar
uni-projects-1975a6e8f80d06571c7990e2a3af387889160c36.tar.gz
uni-projects-1975a6e8f80d06571c7990e2a3af387889160c36.zip
Parentaee3bfe71cba2c1cb7c5e768288281bf42b6baea (diff)
[CI/PA1] Reworked certain regexes into definitions
1 files changed, 10 insertions, 6 deletions
-rw-r--r--Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex16
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]* { }
<MULTILINE,INITIAL>\(\* { openedComments++; BEGIN(MULTILINE); }
<MULTILINE>\*\) { if (--openedComments == 0) BEGIN(INITIAL); }
-<MULTILINE>[\n\r] { curr_lineno++; }
+<MULTILINE>{ENDL} { curr_lineno++; }
<MULTILINE>. { }
<MULTILINE><<EOF>> { 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} { }
%%