From: johanknol Date: Fri, 22 Jun 2001 16:41:57 +0000 (+0000) Subject: some progress on escape sequences X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=ec91ae40b0c4a39b3b7b546cb876846c60c92cfa;p=fw%2Fsdcc some progress on escape sequences git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@927 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCC.lex b/src/SDCC.lex index 23ee5a10..d80995fb 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -302,21 +302,17 @@ int checkCurrFile ( char *s) void comment() { - char c, c1; - -loop: - while ((c = input()) != '*' && c != 0) - if ( c == '\n') - yylineno++ ; - - if ((c1 = input()) != '/' && c != 0) { - if ( c1 == '\n' ) - yylineno++ ; - - unput(c1); - goto loop; - } - + char c, c1; + + loop: + while ((c = input()) != '*' && c) + if ( c == '\n') + yylineno++ ; + + if (c && (c1 = input()) != '/') { + unput(c1); + goto loop; + } } @@ -362,62 +358,62 @@ char strLitBuff[2048] ; * to support ANSI hex and octal escape sequences in string liteals */ -char *stringLiteral () - -{ -int ch; -char *str = strLitBuff ; - -*str++ = '\"' ; -/* put into the buffer till we hit the */ -/* first \" */ - -while (1) - { - ch = input() ; - - if (!ch) - break ; /* end of input */ - - /* if it is a \ then everything allowed */ - - if (ch == '\\') - { - *str++ = ch ; /* backslash in place */ - *str++ = input() ; /* following char in place */ - continue ; /* carry on */ +char *stringLiteral () { + int ch; + char *str = strLitBuff; + + *str++ = '\"'; + /* put into the buffer till we hit the first \" */ + + while (1) { + ch = input(); + + if (!ch) + break; /* end of input */ + + /* if it is a \ then escape char's are allowed */ + if (ch == '\\') { + *str++ = ch; /* backslash in place */ + *str++=input(); /* get the escape char, no check */ + continue; /* carry on */ } + + /* if new line we have a new line break */ + if (ch == '\n') { + yylineno++; + continue; + } + + /* if this is a quote then we have work to do */ + /* find the next non whitespace character */ + /* if that is a double quote then carry on */ + if (ch == '\"') { + *str++ = ch ; /* Pass end of this string or substring to evaluator */ + + while ((ch = input()) && (isspace(ch) || ch=='\\')) { + switch (ch) { + case '\\': + werror (W_STRAY_BACKSLASH, filename, yylineno); + break; + case '\n': + yylineno++; + break; + } + } - /* if new line we have a new line break */ - if (ch == '\n') - break ; - - /* if this is a quote then we have work to do */ - /* find the next non whitespace character */ - /* if that is a double quote then carry on */ - - if (ch == '\"') - { - *str++ = ch ; /* Pass end of this string or substring to evaluator */ - - while ((ch = input()) && isspace(ch)) ; - - if (!ch) - break ; - - if (ch != '\"') - { - unput(ch) ; - break ; + if (!ch) + break; + + if (ch != '\"') { + unput(ch) ; + break ; } } - - *str++ = ch; /* Put next substring introducer into output string */ + *str++ = ch; /* Put next substring introducer into output string */ } - -*str = '\0'; - -return strLitBuff ; + *str = '\0'; + + return strLitBuff; } void doPragma (int op, char *cp) diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index d4337253..db6d963d 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -350,7 +350,9 @@ struct { W_EXESS_ARRAY_INITIALIZERS, ERROR_LEVEL_WARNING, "excess elements in array initializer after `%s' at line %d" }, { E_ARGUMENT_MISSING, ERROR_LEVEL_ERROR, - "Option %s requires an argument." } + "Option %s requires an argument." }, +{ W_STRAY_BACKSLASH, ERROR_LEVEL_WARNING, + "stray '\\' in program" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index f5297034..a1e763d1 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -163,7 +163,8 @@ SDCCERR - SDCC Standard error handler #define E_SIGNED_AND_UNSIGNED_INVALID 145 /* signed and unsigned invalid for .. */ #define E_TWO_OR_MORE_STORAGE_CLASSES 146 #define W_EXESS_ARRAY_INITIALIZERS 147 /* too much initializers for array */ -#define E_ARGUMENT_MISSING 148 /* Option requires an argument. */ +#define E_ARGUMENT_MISSING 148 /* Option requires an argument. */ +#define W_STRAY_BACKSLASH 149 /** Describes the maximum error level that will be logged. Any level * includes all of the levels listed after it.