Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit60ef31d7b8ef34acf54cd82777e11828297dbdff (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-10-19 11:16:56 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-10-19 11:16:56 +0300
Files9126b7354e3672c34d96a37c93ececd9c5602718
uni-projects-60ef31d7b8ef34acf54cd82777e11828297dbdff.tar
uni-projects-60ef31d7b8ef34acf54cd82777e11828297dbdff.tar.gz
uni-projects-60ef31d7b8ef34acf54cd82777e11828297dbdff.zip
Parent8c775f973087d9982e3ba8c113b3f1628ee60fc6 (diff)
[CI/PA1] Added proper parsing of comments
1 files changed, 11 insertions, 2 deletions
-rw-r--r--Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex13
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 39a15c3..942b3a7 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
@@ -67,6 +67,7 @@ char* escapeString(char* str) {
}
bool strStarted = false;
+unsigned openedComments = 0;
%}
@@ -96,13 +97,21 @@ yylval types:
char *error_msg;
*/
+%x MULTILINE
+
%%
\"(\\(.|\n)|[^\\\n"])*\" { cool_yylval.symbol = inttable.add_string(escapeString(yytext)); return (STR_CONST); }
\"(\\(.|\n)|[^\\\n"])*\n { curr_lineno++; cool_yylval.error_msg = "Unterminated string constant"; return (ERROR); }
\"(\\(.|\n)|[^\\\n"])* { cool_yylval.error_msg = "EOF in string constant"; return (ERROR); }
---[^\n\r]* { }
-\(\*.*\*\) { }
+--[^\n\r]* { }
+<MULTILINE,INITIAL>\(\* { openedComments++; BEGIN(MULTILINE); }
+<MULTILINE>\*\) { if (--openedComments == 0) BEGIN(INITIAL); }
+<MULTILINE>[\n\r] { curr_lineno++; }
+<MULTILINE>. { }
+<MULTILINE><<EOF>> { cool_yylval.error_msg = "EOF in comment"; BEGIN(INITIAL); return (ERROR); }
+
+\*\) { cool_yylval.error_msg = "Unmatched *)"; return (ERROR); }
(?i:class) { return (CLASS); }
(?i:else) { return (ELSE); }