Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / Compilers, Introduction
diff options
context:
space:
mode:
Commit8c775f973087d9982e3ba8c113b3f1628ee60fc6 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-10-19 09:17:00 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-10-19 09:17:00 +0300
Filesca6a24a73be805b9f15c9ce427cc381f33c3a2aa /Year 3/Compilers, Introduction
uni-projects-8c775f973087d9982e3ba8c113b3f1628ee60fc6.tar
uni-projects-8c775f973087d9982e3ba8c113b3f1628ee60fc6.tar.gz
uni-projects-8c775f973087d9982e3ba8c113b3f1628ee60fc6.zip
Parent0b26fa027ca143f086a64d412aa40a15be0e5cd7 (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.flex11
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); }