]> git.sur5r.net Git - cc65/commitdiff
Added a new feature "underline_in_numbers" requested by thefox. Using
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 12 Jan 2013 19:07:31 +0000 (19:07 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 12 Jan 2013 19:07:31 +0000 (19:07 +0000)
underlines it is possible to group the digits for easier reading.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5963 b7a2c559-68d2-44c3-8de9-860c34a00d81

doc/ca65.sgml
src/ca65/feature.c
src/ca65/feature.h
src/ca65/global.c
src/ca65/global.h
src/ca65/scanner.c

index a5cf80a6919a12224f8d79a1c72ffc95f5ae9f77..08469347461ee6ace310441afb5d6a71ac9506a1 100644 (file)
@@ -2719,6 +2719,17 @@ Here's a list of all control commands and a description, what they do:
     same name. This does also make it possible to introduce hard to find errors
     in your code, so be careful!
 
+  <tag><tt>underline_in_numbers</tt><label id="underline_in_numbers"></tag>
+
+    Allow underlines within numeric constants. These may be used for grouping
+    the digits of numbers for easier reading.
+    Example:
+    <tscreen><verb>
+        .feature        underline_in_numbers
+        .word           %1100001110100101
+        .word           %1100_0011_1010_0101    ; Identical but easier to read
+    </verb></tscreen>
+
   </descrip>
 
   It is also possible to specify features on the command line using the
index f0ba4c57853eebfd4f62ef4e07f790f00880985d..0a45ded86aefb52ed48d28dfd4978be1e90e5756 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2012, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -62,6 +62,7 @@ static const char* FeatureKeys[FEAT_COUNT] = {
     "ubiquitous_idents",
     "c_comments",
     "force_range",
+    "underline_in_numbers",
 };
 
 
@@ -117,6 +118,7 @@ feature_t SetFeature (const StrBuf* Key)
         case FEAT_UBIQUITOUS_IDENTS:          UbiquitousIdents  = 1;    break;
         case FEAT_C_COMMENTS:                 CComments         = 1;    break;
         case FEAT_FORCE_RANGE:                ForceRange        = 1;    break;
+        case FEAT_UNDERLINE_IN_NUMBERS:       UnderlineInNumbers= 1;    break;
        default:                         /* Keep gcc silent */          break;
     }
 
index cf2f3ade8ed3dd1105bba425525c268f764fb1e1..a56fc57f06e290bdf0c20dfc5e0ad98a52d14235 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2012, Ullrich von Bassewitz                                      */
+/* (C) 2000-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -64,6 +64,7 @@ typedef enum {
     FEAT_UBIQUITOUS_IDENTS,
     FEAT_C_COMMENTS,
     FEAT_FORCE_RANGE,
+    FEAT_UNDERLINE_IN_NUMBERS,
 
     /* Special value: Number of features available */
     FEAT_COUNT
index 90f6c43c76c522bed2dc2b01e99898b991bb5322..cc683556239d2f53d90c38df7197bf47c9ba6430 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/* (C) 1998-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -81,7 +81,8 @@ unsigned char UbiquitousIdents   = 0;   /* Allow ubiquitous identifiers */
 unsigned char OrgPerSeg          = 0;   /* Make .org local to current seg */
 unsigned char CComments          = 0;   /* Allow C like comments */
 unsigned char ForceRange         = 0;   /* Force values into expected range */
-
+unsigned char UnderlineInNumbers = 0;   /* Allow underlines in numbers */
+                
 /* Misc stuff */
 const char Copyright[]           = "(C) Copyright 1998-2011 Ullrich von Bassewitz";
 
index 8d03c01a7cf48c9a06762db6a00b83ec9de64d28..5e660055a6e737da64cbbb72fabb24ee5f4df8eb 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/* (C) 1998-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -83,6 +83,7 @@ extern unsigned char    UbiquitousIdents;   /* Allow ubiquitous identifiers */
 extern unsigned char    OrgPerSeg;          /* Make .org local to current seg */
 extern unsigned char    CComments;          /* Allow C like comments */
 extern unsigned char    ForceRange;         /* Force values into expected range */
+extern unsigned char    UnderlineInNumbers; /* Allow underlines in numbers */
 
 /* Misc stuff */
 extern const char       Copyright[];        /* Copyright string */
index 1ce48fa8ac134e8a41a9f9fbb621bd72887d5638..d36df2d067e16e6f1073b42a74de847f5c0b5f31 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/* (C) 1998-2013, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -862,7 +862,7 @@ Again:
        if (!IsXDigit (C)) {
            if (DollarIsPC) {
                CurTok.Tok = TOK_PC;
-               return;
+               return;
            } else {
                Error ("Hexadecimal digit expected");
            }
@@ -870,14 +870,26 @@ Again:
 
        /* Read the number */
        CurTok.IVal = 0;
-       while (IsXDigit (C)) {
-           if (CurTok.IVal & 0xF0000000) {
-               Error ("Overflow in hexadecimal number");
-               CurTok.IVal = 0;
-           }
-           CurTok.IVal = (CurTok.IVal << 4) + DigitVal (C);
-           NextChar ();
-       }
+        while (1) {
+            if (UnderlineInNumbers && C == '_') {
+                while (C == '_') {
+                    NextChar ();
+                }
+                if (!IsXDigit (C)) {
+                    Error ("Number may not end with underline");
+                }
+            }
+            if (IsXDigit (C)) {
+                if (CurTok.IVal & 0xF0000000) {
+                    Error ("Overflow in hexadecimal number");
+                    CurTok.IVal = 0;
+                }
+                CurTok.IVal = (CurTok.IVal << 4) + DigitVal (C);
+                NextChar ();
+            } else {
+                break;
+            }
+        }
 
        /* This is an integer constant */
        CurTok.Tok = TOK_INTCON;
@@ -895,14 +907,26 @@ Again:
 
        /* Read the number */
         CurTok.IVal = 0;
-       while (IsBDigit (C)) {
-           if (CurTok.IVal & 0x80000000) {
-               Error ("Overflow in binary number");
-               CurTok.IVal = 0;
-           }
-           CurTok.IVal = (CurTok.IVal << 1) + DigitVal (C);
-           NextChar ();
-       }
+        while (1) {
+            if (UnderlineInNumbers && C == '_') {
+                while (C == '_') {
+                    NextChar ();
+                }
+                if (!IsBDigit (C)) {
+                    Error ("Number may not end with underline");
+                }
+            }
+            if (IsBDigit (C)) {
+                if (CurTok.IVal & 0x80000000) {
+                    Error ("Overflow in binary number");
+                    CurTok.IVal = 0;
+                }
+                CurTok.IVal = (CurTok.IVal << 1) + DigitVal (C);
+                NextChar ();
+            } else {
+                break;
+            }
+        }
 
        /* This is an integer constant */
         CurTok.Tok = TOK_INTCON;
@@ -926,17 +950,27 @@ Again:
 
         /* Read the number into Buf counting the digits */
         Digits = 0;
-        while (IsXDigit (C)) {
-
-            /* Buf is big enough to allow any decimal and hex number to
-             * overflow, so ignore excess digits here, they will be detected
-             * when we convert the value.
-             */
-            if (Digits < sizeof (Buf)) {
-                Buf[Digits++] = C;
+        while (1) {
+            if (UnderlineInNumbers && C == '_') {
+                while (C == '_') {
+                    NextChar ();
+                }
+                if (!IsXDigit (C)) {
+                    Error ("Number may not end with underline");
+                }
+            }
+            if (IsXDigit (C)) {
+                /* Buf is big enough to allow any decimal and hex number to
+                 * overflow, so ignore excess digits here, they will be detected
+                 * when we convert the value.
+                 */
+                if (Digits < sizeof (Buf)) {
+                    Buf[Digits++] = C;
+                }
+                NextChar ();
+            } else {
+                break;
             }
-
-            NextChar ();
         }
 
         /* Allow zilog/intel style hex numbers with a 'h' suffix */