diff options
| Commit | 5d36bfc9517c9655c34b3690f3d125839acb375f (patch) | |
|---|---|---|
| Author | 2023-10-19 11:49:19 +0300 | |
| Committer | 2023-10-19 11:49:19 +0300 | |
| Files | cd167802e6d0890bacf1be49ea513ed831c0bea7 | |
| uni-projects-5d36bfc9517c9655c34b3690f3d125839acb375f.tar uni-projects-5d36bfc9517c9655c34b3690f3d125839acb375f.tar.gz uni-projects-5d36bfc9517c9655c34b3690f3d125839acb375f.zip | ||
| Parent | bfa5f22920c704da543e5c51d3b3435a84adc004 (diff) | |
(CI/PA1) Fully implemented strings
1 files changed, 12 insertions, 5 deletions
| -rw-r--r-- | Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex | 17 |
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); } |
