Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
1 files changed, 12 insertions, 5 deletions
-rw-r--r--Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex17
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 b64e368..acc81ba 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
@@ -108,11 +108,18 @@ 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); }
+\"([^"\0\n\\]|\\[^\0])*\" { char* str = escapeString(yytext);
+ if (strlen(str) >= MAX_STR_CONST) {
+ cool_yylval.error_msg = "String constant too long"; return (ERROR);
+ }
+ else {
+ cool_yylval.symbol = inttable.add_string(str); return (STR_CONST);
+ }
+ }
+\"([^"\0\n\\]|\\[^\0])*{ENDL} { cool_yylval.error_msg = "Unterminated string constant"; curr_lineno++; return (ERROR); }
+\"([^"\0\n\\]|\\{ALL})*(\"|{ENDL}) { cool_yylval.error_msg = "String contains escaped null character."; return (ERROR); }
+\"([^"\n\\]|\\[^\0])*(\"|{ENDL}) { cool_yylval.error_msg = "String contains null character."; return (ERROR); }
+\"([^"\0\n\\]|\\[^\0])* { cool_yylval.error_msg = "EOF in string constant"; return (ERROR); }
\*\) { cool_yylval.error_msg = "Unmatched *)"; return (ERROR); }