Add logical-compound-assigment operators (^=, &=, |=)

This commit is contained in:
Nikita Lisitsa 2026-03-31 16:00:23 +03:00
parent 3ea319f7bf
commit e573081647
2 changed files with 9 additions and 0 deletions

View file

@ -68,6 +68,9 @@ f64 { return bp::make_f64(ctx.location); }
"*=" { return bp::make_asterisk_assignment(ctx.location); }
"/=" { return bp::make_slash_assignment(ctx.location); }
"%=" { return bp::make_percent_assignment(ctx.location); }
"^=" { return bp::make_circumflex_assignment(ctx.location); }
"&=" { return bp::make_ampersand_assignment(ctx.location); }
"|=" { return bp::make_vertical_bar_assignment(ctx.location); }
">>=" { return bp::make_right_shift_assignment(ctx.location); }
"<<=" { return bp::make_left_shift_assignment(ctx.location); }
"+" { return bp::make_plus(ctx.location); }

View file

@ -110,6 +110,9 @@ template <typename T>
%token asterisk_assignment "*="
%token slash_assignment "/="
%token percent_assignment "%="
%token circumflex_assignment "^="
%token ampersand_assignment "&="
%token vertical_bar_assignment "|="
%token left_shift_assignment "<<="
%token right_shift_assignment ">>="
@ -234,6 +237,9 @@ statement
| expression asterisk_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::multiplication, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| expression slash_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::division, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| expression percent_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::remainder, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| expression circumflex_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::logical_xor, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| expression ampersand_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::binary_and, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| expression vertical_bar_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::binary_or, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| expression left_shift_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::left_shift, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| expression right_shift_assignment expression { auto lhs = std::make_shared<ast::expression>($1); $$ = ast::assignment{ lhs, std::make_shared<ast::expression>(ast::binary_operation{ ast::binary_operation_type::right_shift, lhs, std::make_unique<ast::expression>($3), @$ }), @$ }; }
| variable_declaration { $$ = $1; }