some progress on escape sequences
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 22 Jun 2001 16:41:57 +0000 (16:41 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 22 Jun 2001 16:41:57 +0000 (16:41 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@927 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCC.lex
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 23ee5a102f2bdba229f7acf7b93a1c03a0ba1100..d80995fbc2a8469723bd28e6e623d0ea0c544e91 100644 (file)
@@ -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)
index d4337253469ee1800bf247692d203155756a0549..db6d963d6f10b2e0f3573a24e4a430069290872d 100644 (file)
@@ -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" },
 };
 
 /*
index f529703413ad74bcd30c2ceb838cd594283ffbb0..a1e763d1757401bb86583a8680ff98797e65cd01 100644 (file)
@@ -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.