Changeset 0a2168f


Ignore:
Timestamp:
Mar 4, 2018, 10:32:08 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ea46db7
Parents:
82c367d
Message:

add gcc binary constants

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r82c367d r0a2168f  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Sep 27 22:51:55 2017
    13 // Update Count     : 781
     12// Last Modified On : Sat Mar  3 18:22:33 2018
     13// Update Count     : 796
    1414//
    1515
     
    5858static inline bool checkD( char c ) { return c == 'd' || c == 'D'; }
    5959static inline bool checkI( char c ) { return c == 'i' || c == 'I'; }
     60static inline bool checkB( char c ) { return c == 'b' || c == 'B'; }
    6061static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    6162
     
    116117
    117118        unsigned long long int v;                                                       // converted integral value
    118         size_t last = str.length() - 1;                                         // last character of constant
     119        size_t last = str.length() - 1;                                         // last subscript of constant
    119120        Expression * ret;
    120121
     
    129130        } // if
    130131
    131         if ( str[0] == '0' ) {                                                          // octal/hex constant ?
     132        // Cannot be "0"
     133
     134        if ( str[0] == '0' ) {                                                          // radix character ?
    132135                dec = false;
    133                 if ( last != 0 && checkX( str[1] ) ) {                  // hex constant ?
     136                if ( checkX( str[1] ) ) {                                               // hex constant ?
    134137                        sscanf( (char *)str.c_str(), "%llx", &v );
     138                        //printf( "%llx %llu\n", v, v );
     139                } else if ( checkB( str[1] ) ) {                                // binary constant ?
     140                        v = 0;
     141                        for ( unsigned int i = 2;; i += 1 ) {           // compute value
     142                                if ( str[i] == '1' ) v |= 1;
     143                          if ( i == last ) break;
     144                                v <<= 1;
     145                        } // for
    135146                        //printf( "%llx %llu\n", v, v );
    136147                } else {                                                                                // octal constant
  • src/Parser/lex.ll

    r82c367d r0a2168f  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu Feb 22 18:11:27 2018
    13  * Update Count     : 637
     12 * Last Modified On : Sat Mar  3 18:38:16 2018
     13 * Update Count     : 640
    1414 */
    1515
     
    7777%}
    7878
     79binary [0-1]
    7980octal [0-7]
    8081nonzero [1-9]
     
    103104nonzero_digits ({nonzero})|({nonzero}({decimal}|"_")*{decimal})
    104105decimal_constant {nonzero_digits}{integer_suffix_opt}
     106
     107binary_digits ({binary})|({binary}({binary}|"_")*{binary})
     108binary_prefix "0"[bB]"_"?
     109binary_constant {binary_prefix}{binary_digits}{integer_suffix_opt}
    105110
    106111hex_digits ({hex})|({hex}({hex}|"_")*{hex})
     
    315320
    316321                                /* numeric constants */
     322{binary_constant} { NUMERIC_RETURN(INTEGERconstant); }
     323{octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    317324{decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    318 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    319325{hex_constant}  { NUMERIC_RETURN(INTEGERconstant); }
    320326{floating_decimal}      { NUMERIC_RETURN(FLOATING_DECIMALconstant); } // must appear before floating_constant
Note: See TracChangeset for help on using the changeset viewer.