diff options
| Commit | 8c775f973087d9982e3ba8c113b3f1628ee60fc6 (patch) | |
|---|---|---|
| Author | 2023-10-19 09:17:00 +0300 | |
| Committer | 2023-10-19 09:17:00 +0300 | |
| Files | ca6a24a73be805b9f15c9ce427cc381f33c3a2aa | |
| uni-projects-8c775f973087d9982e3ba8c113b3f1628ee60fc6.tar uni-projects-8c775f973087d9982e3ba8c113b3f1628ee60fc6.tar.gz uni-projects-8c775f973087d9982e3ba8c113b3f1628ee60fc6.zip | ||
| Parent | 0b26fa027ca143f086a64d412aa40a15be0e5cd7 (diff) | |
[CI/PA1] Fixed line number with strings and implemented unterminated string and eof in string errors
1 files changed, 8 insertions, 3 deletions
| -rw-r--r-- | Year 3/Compilers, Introduction/coolc-spim/my-code/coursework/pa1/cool.flex | 11 |
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 9f86243..39a15c3 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 @@ -47,6 +47,7 @@ char* escapeString(char* str) { unsigned escapes = 0, length = 0; for (char* i = str; *i != 0; i++) { if (*i == '\\') escapes++; + else if (*i == '\n') curr_lineno++; length++; } char* out = new char[length -= 2]; @@ -65,6 +66,8 @@ char* escapeString(char* str) { return out; } +bool strStarted = false; + %} /* @@ -95,9 +98,11 @@ yylval types: %% -\"(\\\"|[^"])*\" { cool_yylval.symbol = inttable.add_string(escapeString(yytext)); return (STR_CONST); } ---[^\n\r]* { } -\(\*.*\*\) { } +\"(\\(.|\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]* { } +\(\*.*\*\) { } (?i:class) { return (CLASS); } (?i:else) { return (ELSE); } |
