From bfa5f22920c704da543e5c51d3b3435a84adc004 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 19 Oct 2023 11:17:44 +0300 Subject: [CI/PA1] Added string errors on null character, unterminated strings and EOF --- .../coolc-spim/my-code/coursework/pa1/cool.flex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 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]* { } \(\* { openedComments++; BEGIN(MULTILINE); } \*\) { if (--openedComments == 0) BEGIN(INITIAL); } @@ -111,6 +108,12 @@ yylval types: . { } <> { 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); } -- cgit v1.3.1-26-gb76a