diff --git a/biner.y b/biner.y index daa95af..abc20c2 100644 --- a/biner.y +++ b/biner.y @@ -103,8 +103,8 @@ resolve_constant_( %type struct_member_type array_struct_member_type unqualified_struct_member_type %type expr or_expr and_expr bit_or_expr bit_xor_expr -%type bit_and_expr equality_expr relational_expr add_expr -%type mul_expr unary_expr operand +%type bit_and_expr equality_expr relational_expr shift_expr +%type add_expr mul_expr unary_expr operand %start decl_list @@ -314,7 +314,7 @@ equality_expr ; relational_expr - : add_expr + : shift_expr | relational_expr '>' add_expr { $$ = create_operator_($1, BINER_TREE_EXPR_TYPE_OPERATOR_GREATER, $3); } @@ -329,6 +329,16 @@ relational_expr } ; +shift_expr + : add_expr + | shift_expr BIT_LSHIFT add_expr { + $$ = create_operator_($1, BINER_TREE_EXPR_TYPE_OPERATOR_BIT_LSHIFT, $3); + } + | shift_expr BIT_RSHIFT add_expr { + $$ = create_operator_($1, BINER_TREE_EXPR_TYPE_OPERATOR_BIT_RSHIFT, $3); + } + ; + add_expr : mul_expr | add_expr '+' mul_expr { diff --git a/test/user.biner b/test/user.biner index dd8e9d8..7d59467 100644 --- a/test/user.biner +++ b/test/user.biner @@ -29,8 +29,8 @@ struct teacher_t { }; struct student_t { - lu8[10] scores; - lu8 absents; + lu8[(1 << 4) - 6] scores; + lu8 absents; }; struct user_t { diff --git a/transpile_c.c b/transpile_c.c index 95da95d..3a22d14 100644 --- a/transpile_c.c +++ b/transpile_c.c @@ -56,6 +56,8 @@ static const char* const expr_operator_string_map_ [BINER_TREE_EXPR_TYPE_OPERATOR_BIT_OR] = "|", [BINER_TREE_EXPR_TYPE_OPERATOR_BIT_NOT] = "~", [BINER_TREE_EXPR_TYPE_OPERATOR_BIT_XOR] = "^", + [BINER_TREE_EXPR_TYPE_OPERATOR_BIT_LSHIFT] = "<<", + [BINER_TREE_EXPR_TYPE_OPERATOR_BIT_RSHIFT] = ">>", }; typedef struct struct_member_info_t { diff --git a/tree.h b/tree.h index 17e9ac7..3543a4f 100644 --- a/tree.h +++ b/tree.h @@ -36,6 +36,8 @@ typedef enum biner_tree_expr_type_t { BINER_TREE_EXPR_TYPE_OPERATOR_BIT_OR, BINER_TREE_EXPR_TYPE_OPERATOR_BIT_NOT, BINER_TREE_EXPR_TYPE_OPERATOR_BIT_XOR, + BINER_TREE_EXPR_TYPE_OPERATOR_BIT_LSHIFT, + BINER_TREE_EXPR_TYPE_OPERATOR_BIT_RSHIFT, BINER_TREE_EXPR_TYPE_OPERATOR_MAX_, } biner_tree_expr_type_t;