comparison lwasm/lwasm.c @ 576:40edb7de3857

Add 0b and 0B as a prefix for binary constants
author William Astle <lost@l-w.ca>
date Fri, 12 Jul 2024 23:02:57 -0600
parents 87f904e2b304
children 10f8fc64481d
comparison
equal deleted inserted replaced
575:d562ecd3ffd8 576:40edb7de3857
638 { 638 {
639 val = val * 2 + (**p - '0'); 639 val = val * 2 + (**p - '0');
640 (*p)++; 640 (*p)++;
641 } 641 }
642 return lw_expr_build(lw_expr_type_int, val * neg); 642 return lw_expr_build(lw_expr_type_int, val * neg);
643 }
644 if (**p == '0' && (*((*p)+1) == 'b' || *((*p)+1) == 'B'))
645 {
646 val = 0;
647 // binary constant
648 (*p) += 2;
649
650 if (**p != '0' && **p != '1')
651 {
652 (*p)-2;
653 return NULL;
654 }
655
656 while (**p && (**p == '0' || **p == '1'))
657 {
658 val = val * 2 + (**p - '0');
659 (*p)++;
660 }
661 return lw_expr_build(lw_expr_type_int, val);
643 } 662 }
644 663
645 if (**p == '$') 664 if (**p == '$')
646 { 665 {
647 // hexadecimal constant 666 // hexadecimal constant