* as/hc08/lkaomf51.c (OutputName): made name unsigned char,
[fw/sdcc] / src / SDCC.lex
index 1701dbe1b2e48d3315c5357faa0a4798c5df1b6c..4f9b51887143ffac7c794b995ac355ef74005628 100644 (file)
@@ -40,6 +40,11 @@ IS      (u|U|l|L)*
 #define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
                                 check_type())
 
+#define TKEYWORDSDCC(token) return (options.std_sdcc && isTargetKeyword(yytext)\
+                                    ? token : check_type())
+
+#define TKEYWORD99(token) return (options.std_c99 ? token : check_type())
+
 extern int lineno, column;
 extern char *filename;
 
@@ -61,18 +66,27 @@ static int checkCurrFile(char *s);
 
 %x asm
 %%
-"_asm"         {
+_?"_asm"         {
   count();
+  if (!options.std_sdcc && yytext[1] != '_')
+    return check_type();
   assert(asmbuff.alloc == 0 && asmbuff.len == 0 && asmbuff.buf == NULL);
   dbuf_init(&asmbuff, INITIAL_INLINEASM);
   BEGIN(asm);
 }
-<asm>"_endasm" {
+<asm>_?"_endasm" {
   count();
-  yylval.yyinline = dbuf_c_str(&asmbuff);
-  dbuf_detach(&asmbuff);
-  BEGIN(INITIAL);
-  return (INLINEASM);
+  if (!options.std_sdcc && yytext[1] != '_')
+    {
+      dbuf_append(&asmbuff, yytext, strlen(yytext));
+    }
+  else
+    {
+      yylval.yyinline = dbuf_c_str(&asmbuff);
+      dbuf_detach(&asmbuff);
+      BEGIN(INITIAL);
+      return (INLINEASM);
+    }
 }
 <asm>\n        {
   count();
@@ -81,49 +95,75 @@ static int checkCurrFile(char *s);
 <asm>.         {
   dbuf_append(&asmbuff, yytext, 1);
 }
-"at"           { count(); TKEYWORD(AT); }
+"at"           { count(); TKEYWORDSDCC(AT); }
+"__at"         { count(); TKEYWORD(AT); }
 "auto"         { count(); return(AUTO); }
-"bit"          { count(); TKEYWORD(BIT); }
+"bit"          { count(); TKEYWORDSDCC(BIT); }
+"__bit"        { count(); TKEYWORD(BIT); }
 "break"        { count(); return(BREAK); }
 "case"         { count(); return(CASE); }
 "char"         { count(); return(CHAR); }
-"code"         { count(); TKEYWORD(CODE); }
+"code"         { count(); TKEYWORDSDCC(CODE); }
+"__code"       { count(); TKEYWORD(CODE); }
 "const"        { count(); return(CONST); }
 "continue"     { count(); return(CONTINUE); }
-"critical"     { count(); TKEYWORD(CRITICAL); }
-"data"         { count(); TKEYWORD(DATA); }
+"critical"     { count(); TKEYWORDSDCC(CRITICAL); }
+"__critical"   { count(); TKEYWORD(CRITICAL); }
+"data"         { count(); TKEYWORDSDCC(DATA); }
+"__data"       { count(); TKEYWORD(DATA); }
 "default"      { count(); return(DEFAULT); }
 "do"           { count(); return(DO); }
 "double"       { count(); werror(W_DOUBLE_UNSUPPORTED);return(FLOAT); }
 "else"         { count(); return(ELSE); }
 "enum"         { count(); return(ENUM); }
 "extern"       { count(); return(EXTERN); }
-"far"          { count(); TKEYWORD(XDATA); }
-"eeprom"       { count(); TKEYWORD(EEPROM); }
+"far"          { count(); TKEYWORDSDCC(XDATA); }
+"__far"        { count(); TKEYWORD(XDATA); }
+"eeprom"       { count(); TKEYWORDSDCC(EEPROM); }
+"__eeprom"     { count(); TKEYWORD(EEPROM); }
 "float"        { count(); return(FLOAT); }
-"flash"        { count(); TKEYWORD(CODE); }
+"fixed16x16"   { count(); TKEYWORDSDCC(FIXED16X16); }
+"__fixed16x16"   { count(); TKEYWORD(FIXED16X16); }
+"flash"        { count(); TKEYWORDSDCC(CODE); }
+"__flash"      { count(); TKEYWORD(CODE); }
 "for"          { count(); return(FOR); }
 "goto"         { count(); return(GOTO); }
-"idata"        { count(); TKEYWORD(IDATA); }
+"idata"        { count(); TKEYWORDSDCC(IDATA); }
+"__idata"      { count(); TKEYWORD(IDATA); }
 "if"           { count(); return(IF); }
 "int"          { count(); return(INT); }
-"interrupt"    { count(); return(INTERRUPT); }
-"nonbanked"    { count(); TKEYWORD(NONBANKED); }
-"banked"       { count(); TKEYWORD(BANKED); }
+"interrupt"    { count(); TKEYWORDSDCC(INTERRUPT); }
+"__interrupt"  { count(); TKEYWORD(INTERRUPT); }
+"nonbanked"    { count(); TKEYWORDSDCC(NONBANKED); }
+"__nonbanked"  { count(); TKEYWORD(NONBANKED); }
+"banked"       { count(); TKEYWORDSDCC(BANKED); }
+"__banked"     { count(); TKEYWORD(BANKED); }
 "long"         { count(); return(LONG); }
-"near"         { count(); TKEYWORD(DATA); }
-"pdata"        { count(); TKEYWORD(PDATA); }
-"reentrant"    { count(); TKEYWORD(REENTRANT); }
-"shadowregs"   { count(); TKEYWORD(SHADOWREGS); }
-"wparam"       { count(); TKEYWORD(WPARAM); }
+"near"         { count(); TKEYWORDSDCC(DATA); }
+"__near"       { count(); TKEYWORD(DATA); }
+"pdata"        { count(); TKEYWORDSDCC(PDATA); }
+"__pdata"      { count(); TKEYWORD(PDATA); }
+"reentrant"    { count(); TKEYWORDSDCC(REENTRANT); }
+"__reentrant"  { count(); TKEYWORD(REENTRANT); }
+"shadowregs"   { count(); TKEYWORDSDCC(SHADOWREGS); }
+"__shadowregs" { count(); TKEYWORD(SHADOWREGS); }
+"wparam"       { count(); TKEYWORDSDCC(WPARAM); }
+"__wparam"     { count(); TKEYWORD(WPARAM); }
 "register"     { count(); return(REGISTER); }
 "return"       { count(); return(RETURN); }
-"sfr"          { count(); TKEYWORD(SFR); }
-"sbit"         { count(); TKEYWORD(SBIT); }
+"sfr"          { count(); TKEYWORDSDCC(SFR); }
+"__sfr"        { count(); TKEYWORD(SFR); }
+"sfr16"        { count(); TKEYWORDSDCC(SFR16); }
+"__sfr16"      { count(); TKEYWORD(SFR16); }
+"sfr32"        { count(); TKEYWORDSDCC(SFR32); }
+"__sfr32"      { count(); TKEYWORD(SFR32); }
+"sbit"         { count(); TKEYWORDSDCC(SBIT); }
+"__sbit"       { count(); TKEYWORD(SBIT); }
 "short"        { count(); return(SHORT); }
 "signed"       { count(); return(SIGNED); }
 "sizeof"       { count(); return(SIZEOF); }
-"sram"         { count(); TKEYWORD(XDATA); }
+"sram"         { count(); TKEYWORDSDCC(XDATA); }
+"__sram"       { count(); TKEYWORD(XDATA); }
 "static"       { count(); return(STATIC); }
 "struct"       { count(); return(STRUCT); }
 "switch"       { count(); return(SWITCH); }
@@ -132,14 +172,20 @@ static int checkCurrFile(char *s);
 "unsigned"     { count(); return(UNSIGNED); }
 "void"         { count(); return(VOID); }
 "volatile"     { count(); return(VOLATILE); }
-"using"        { count(); TKEYWORD(USING); }
-"_naked"       { count(); TKEYWORD(NAKED); }
+"using"        { count(); TKEYWORDSDCC(USING); }
+"__using"      { count(); TKEYWORD(USING); }
+"_naked"       { count(); TKEYWORDSDCC(NAKED); }
+"__naked"      { count(); TKEYWORD(NAKED); }
 "while"        { count(); return(WHILE); }
-"xdata"        { count(); TKEYWORD(XDATA); }
+"xdata"        { count(); TKEYWORDSDCC(XDATA); }
+"__xdata"      { count(); TKEYWORD(XDATA); }
 "..."          { count(); return(VAR_ARGS); }
 "__typeof"     { count(); return TYPEOF; }
 "_JavaNative"  { count(); TKEYWORD(JAVANATIVE); }
-"_overlay"     { count(); TKEYWORD(OVERLAY); }
+"_overlay"     { count(); TKEYWORDSDCC(OVERLAY); }
+"__overlay"    { count(); TKEYWORD(OVERLAY); }
+"inline"       { count(); TKEYWORD99(INLINE); }
+"restrict"     { count(); TKEYWORD99(RESTRICT); }
 {L}({L}|{D})*  { count(); return(check_type()); }
 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
 0[0-7]*{IS}?     { count(); yylval.val = constVal(yytext); return(CONSTANT); }
@@ -238,7 +284,7 @@ static int checkCurrFile (char *s)
 
     /* get the line number */
     lNum = strtol(s, &tptr, 10);
-    if (tptr == s || !isspace(*tptr))
+    if (tptr == s || !isspace((unsigned char)*tptr))
       return 0;
     s = tptr;
 
@@ -421,7 +467,13 @@ enum pragma_id {
      P_DISABLEWARN,
      P_OPTCODESPEED,
      P_OPTCODESIZE,
-     P_OPTCODEBALANCED
+     P_OPTCODEBALANCED,
+     P_STD_C89,
+     P_STD_C99,
+     P_STD_SDCC89,
+     P_STD_SDCC99,
+     P_CODESEG,
+     P_CONSTSEG
 };
 
 
@@ -617,7 +669,48 @@ static void doPragma(int op, char *cp)
     optimize.codeSpeed = 0;
     optimize.codeSize = 0;
     break;
+  
+  case P_STD_C89:
+    options.std_c99 = 0;
+    options.std_sdcc = 0;
+    break;
+  
+  case P_STD_C99:
+    options.std_c99 = 1;
+    options.std_sdcc = 0;
+    break;
+  
+  case P_STD_SDCC89:
+    options.std_c99 = 0;
+    options.std_sdcc = 1;
+    break;
+  
+  case P_STD_SDCC99:
+    options.std_c99 = 1;
+    options.std_sdcc = 1;
+    break;
+
+  case P_CODESEG:
+    {
+      char str[9];
+      char *segname = Safe_malloc(15);
+      sscanf(cp, " %8s", str);
+      str[8] = '\0';
+      sprintf(segname, "%-8.8s(CODE)", str);
+      options.code_seg = segname;
+    }
+    break;
 
+  case P_CONSTSEG:
+    {
+      char str[9];
+      char *segname = Safe_malloc(15);
+      sscanf(cp, " %8s", str);
+      str[8] = '\0';
+      sprintf(segname, "%-8.8s(CODE)", str);
+      options.const_seg = segname;
+    }
+    break;
   }
 }
 
@@ -652,6 +745,12 @@ static int process_pragma(char *s)
     { "opt_code_speed", P_OPTCODESPEED, 0 },
     { "opt_code_size",  P_OPTCODESIZE,  0 },
     { "opt_code_balanced",  P_OPTCODEBALANCED,  0 },
+    { "std_c89",        P_STD_C89,      0 },
+    { "std_c99",        P_STD_C99,      0 },
+    { "std_sdcc89",     P_STD_SDCC89,   0 },
+    { "std_sdcc99",     P_STD_SDCC99,   0 },
+    { "codeseg",        P_CODESEG,      0 },
+    { "constseg",       P_CONSTSEG,     0 },
 
     /*
      * The following lines are deprecated pragmas,
@@ -684,14 +783,18 @@ static int process_pragma(char *s)
   s += PRAGMA_LEN;
 
   /* look for the directive */
-  while(isspace(*s))
+  while(isspace((unsigned char)*s))
     s++;
 
   cp = s;
   /* look for the end of the directive */
-  while ((!isspace(*s)) && (*s != '\n'))
+  while ((!isspace((unsigned char)*s)) && (*s != '\n'))
     s++ ;
 
+  /* skip separating whitespace */
+  while (isspace((unsigned char)*s) && (*s != '\n'))
+    s++;
+
   /* First give the port a chance */
   if (port->process_pragma && !port->process_pragma(cp))
     return 0;
@@ -706,7 +809,7 @@ static int process_pragma(char *s)
           if (pragma_tbl[i].deprecated != 0)
             werror(W_DEPRECATED_PRAGMA, pragma_tbl[i].name);
 
-          doPragma(pragma_tbl[i].id, cp + len);
+          doPragma(pragma_tbl[i].id, s);
           return 0;
         }
     }
@@ -723,12 +826,30 @@ static int isTargetKeyword(char *s)
 
   if (port->keywords == NULL)
     return 0;
-  for (i = 0 ; port->keywords[i] ; i++ ) {
-    if (strcmp(port->keywords[i],s) == 0)
-      return 1;
-  }
+  
+  if (s[0] == '_' && s[1] == '_')
+    {
+      /* Keywords in the port's array have either 0 or 1 underscore, */
+      /* so skip over the appropriate number of chars when comparing */
+      for (i = 0 ; port->keywords[i] ; i++ )
+        {
+          if (port->keywords[i][0] == '_' &&
+              strcmp(port->keywords[i],s+1) == 0)
+            return 1;
+          else if (strcmp(port->keywords[i],s+2) == 0)
+            return 1;
+        }
+    }
+  else
+    {
+      for (i = 0 ; port->keywords[i] ; i++ )
+        {
+          if (strcmp(port->keywords[i],s) == 0)
+            return 1;
+        }
+    }
 
-    return 0;
+  return 0;
 }
 
 int yywrap(void)