* Makefile.in, configure.in, configure,
[fw/sdcc] / src / SDCC.lex
index 7fbe4e7f456ff670b835ff1518fd85f10682ee9e..0fc43d00445ed1bd3f5881bb047b091f04423282 100644 (file)
@@ -1,6 +1,6 @@
 /*-----------------------------------------------------------------------
-  SDCC.lex - lexical analyser for use with sdcc ( a freeware compiler for
-  8/16 bit microcontrollers)
+  SDCC.lex - lexical analyser for use with sdcc (free open source
+  compiler for 8/16 bit microcontrollers)
   Written by : Sandeep Dutta . sandeep.dutta@usa.net (1997)
 
   This program is free software; you can redistribute it and/or modify it
@@ -22,9 +22,9 @@
   what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
+B       [0-1]
 D       [0-9]
-L       [a-zA-Z_]
-L_DOLL  [a-zA-Z_$]
+L       [a-zA-Z_$]
 H       [a-fA-F0-9]
 E       [Ee][+-]?{D}+
 FS      (f|F|l|L)
@@ -50,10 +50,15 @@ extern char *filename;
 extern int lineno;
 int column = 0;         /* current column */
 
+/* global definitions */
+char *lexFilename;
+int lexLineno = 1;
+
 /* local definitions */
 static struct dbuf_s asmbuff; /* reusable _asm buffer */
 
 /* forward declarations */
+int yyerror(char *s);
 static const char *stringLiteral(void);
 static void count(void);
 static void count_char(int);
@@ -187,15 +192,22 @@ _?"_asm"         {
 "__overlay"    { count(); TKEYWORD(OVERLAY); }
 "inline"       { count(); TKEYWORD99(INLINE); }
 "restrict"     { count(); TKEYWORD99(RESTRICT); }
-{L}({L}|{D})*  { count(); return(check_type()); }
-{L_DOLL}({L_DOLL}|{D})*  {
-  if (options.dollars_in_ident)
+{L}({L}|{D})*  {
+  if (!options.dollars_in_ident && strchr(yytext, '$'))
     {
-      count();
-      return(check_type());
+      yyerror("stray '$' in program");
     }
-  else
-    REJECT;
+  count();
+  return(check_type());
+}
+0[bB]{B}+{IS}? {
+  if (!options.std_sdcc)
+    {
+      yyerror("binary (0b) constants are not allowed in ISO C");
+    }
+  count();
+  yylval.val = constVal(yytext);
+  return(CONSTANT);
 }
 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
 0[0-7]*{IS}?     { count(); yylval.val = constVal(yytext); return(CONSTANT); }
@@ -303,7 +315,7 @@ static int checkCurrFile (const char *s)
   s = tptr;
 
   /* adjust the line number */
-  lineno = lNum;
+  lineno = lexLineno = lNum;
 
   /* now see if we have a file name */
   while (*s != '"' && *s)
@@ -323,20 +335,26 @@ static int checkCurrFile (const char *s)
   if (fullSrcFileName &&
     strncmp(s, fullSrcFileName, strlen(fullSrcFileName)) == 0 && fullSrcFileName[strlen(fullSrcFileName) - 1] == '"')
     {
-      filename = fullSrcFileName;
+      lexFilename = fullSrcFileName;
     }
   else
     {
       const char *sb = s;
+      char *tmpFname;
 
-      /* find the end of the filename */
+      /* find the end of the file name */
       while (*s && *s != '"')
         ++s;
 
-      filename = Safe_malloc(s - sb + 1);
-      memcpy(filename, sb, s - sb);
-      filename[s - sb] = '\0';
+      tmpFname = Safe_malloc(s - sb + 1);
+      memcpy(tmpFname, sb, s - sb);
+      tmpFname[s - sb] = '\0';
+
+      lexFilename = Safe_malloc(s - sb + 1);
+      copyStr(lexFilename, tmpFname);
     }
+  filename = lexFilename;
+
   return 0;
 }
 
@@ -346,7 +364,7 @@ static void count_char(int ch)
     {
     case '\n':
       column = 0;
-      ++lineno;
+      lineno = ++lexLineno;
       break;
 
     case '\t':
@@ -375,7 +393,7 @@ static int check_type(void)
 
   /* check if it is in the table as a typedef */
   if (!ignoreTypedefType && sym && IS_SPEC (sym->etype)
-      && SPEC_TYPEDEF (sym->etype))
+      && SPEC_TYPEDEF (sym->etype) && findSym(TypedefTab, NULL, yytext))
     return (TYPE_NAME);
   else
     return(IDENTIFIER);
@@ -493,8 +511,10 @@ static const char *stringLiteral(void)
                       dbuf_destroy(&linebuf);
                     }
                   else
-                    unput(ch);
-                  break;
+                    {
+                      unput(ch);
+                      goto out;
+                    }
 
                 default:
                   count_char(ch);
@@ -1121,10 +1141,10 @@ int yyerror(char *s)
 
   if(options.vc_err_style)
     fprintf(stderr, "\n%s(%d) : %s: token -> '%s' ; column %d\n",
-      filename, lineno, s, yytext, column);
+      lexFilename, lexLineno, s, yytext, column);
   else
     fprintf(stderr, "\n%s:%d: %s: token -> '%s' ; column %d\n",
-      filename, lineno, s ,yytext, column);
+      lexFilename, lexLineno, s ,yytext, column);
   fatalError++;
 
   return 0;