diff options
[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.flex | 9 |
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); } |
