Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitbfa5f22920c704da543e5c51d3b3435a84adc004 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-10-19 11:17:44 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-10-19 11:17:44 +0300
Filesbc1ef6b5c722fbcb4b891fd967bd42309eb97bcf
uni-projects-bfa5f22920c704da543e5c51d3b3435a84adc004.tar
uni-projects-bfa5f22920c704da543e5c51d3b3435a84adc004.tar.gz
uni-projects-bfa5f22920c704da543e5c51d3b3435a84adc004.zip
Parentbd174712cd01429682377f9baabe173049112c47 (diff)
[CI/PA1] Added string errors on null character, unterminated strings and EOF
1 files changed, 6 insertions, 3 deletions
-rw-r--r--Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex9
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 c6e99b9..b64e368 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
@@ -101,9 +101,6 @@ yylval types:
%%
-\"(\\(.|\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]* { }
<MULTILINE,INITIAL>\(\* { openedComments++; BEGIN(MULTILINE); }
<MULTILINE>\*\) { if (--openedComments == 0) BEGIN(INITIAL); }
@@ -111,6 +108,12 @@ yylval types:
<MULTILINE>. { }
<MULTILINE><<EOF>> { cool_yylval.error_msg = "EOF in comment"; BEGIN(INITIAL); return (ERROR); }
+\"(\\([^\0]|\n)|[^\0\\\n"])*\" { cool_yylval.symbol = inttable.add_string(escapeString(yytext)); return (STR_CONST); }
+\"(\\(.|\n)|[^\0\\\n"])*\" { cool_yylval.error_msg = "String contains escaped null character."; return (ERROR); }
+\"(\\([^\0]|\n)|[^\\\n"])*\" { cool_yylval.error_msg = "String contains null character."; return (ERROR); }
+\"(\\([^\0]|\n)|[^\0\\\n"])*\n { curr_lineno++; cool_yylval.error_msg = "Unterminated string constant"; return (ERROR); }
+\"(\\([^\0]|\n)|[^\0\\\n"])* { cool_yylval.error_msg = "EOF in string constant"; return (ERROR); }
+
\*\) { cool_yylval.error_msg = "Unmatched *)"; return (ERROR); }
(?i:class) { return (CLASS); }