From e04ce1099f556913d4ebc5ccb217b4c08a7b5f59 Mon Sep 17 00:00:00 2001 From: Per Hedbor <ph@opera.com> Date: Wed, 11 Dec 2013 13:45:18 +0100 Subject: [PATCH] Merged the "ph/bits" branch. This allows one more syntax for int-ranges in types: (Xbit): This reprensents the range (0..(1<<X)-1). So, string(8bit) is identical to string(0..255) and string(16bit) is string(0..65535). The same is true for integers, int(3bit) is int(0..7). This does not conflict with any existing code because identifiers can not start with a number. --- src/language.yacc | 7 +++++++ src/lexer.h | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/language.yacc b/src/language.yacc index fe6ca29e81..946ae0ad77 100644 --- a/src/language.yacc +++ b/src/language.yacc @@ -98,6 +98,7 @@ %token TOK_OPTIONAL %token TOK_SAFE_INDEX %token TOK_SAFE_START_INDEX +%token TOK_BITS %right '=' @@ -290,6 +291,7 @@ int yylex(YYSTYPE *yylval); %type <n> string %type <n> TOK_STRING %type <n> TOK_NUMBER +%type <n> TOK_BITS %type <n> optional_attributes %type <n> optional_rename_inherit %type <n> optional_identifier @@ -1499,6 +1501,11 @@ opt_int_range: /* Empty */ { push_int_type(MIN_INT_TYPE, MAX_INT_TYPE); } + | '(' TOK_BITS ')' + { + push_int_type( 0, (1<<$2->u.sval.u.integer)-1 ); + free_node( $2 ); + } | '(' number_or_minint expected_dot_dot number_or_maxint ')' { INT_TYPE min = MIN_INT_TYPE; diff --git a/src/lexer.h b/src/lexer.h index 8b36bf6744..b52e42387d 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -885,7 +885,7 @@ unknown_directive: case '0': { int base = 0; - + if(GOBBLE('b') || GOBBLE('B')) { base = 2; @@ -909,7 +909,7 @@ unknown_directive: return TOK_NUMBER; } } - + case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { @@ -985,7 +985,16 @@ unknown_directive: free_svalue(&sval); debug_malloc_touch(yylval->n); lex->pos=p2; - if (lex_isidchar (LOOK())) { + if (lex_isidchar (LOOK())) + { + if( GOBBLE('b') ) + if( GOBBLE( 'i' ) ) + if( GOBBLE( 't' ) ) + { + GOBBLE('s'); + return TOK_BITS; + } + my_yyerror ("Invalid char '%c' in constant.", LOOK()); do SKIP(); while (lex_isidchar (LOOK())); } -- GitLab