Skip to content

Commit

Permalink
Refactoring binary operations (#50 from wesuRage/main)
Browse files Browse the repository at this point in the history
Refactoring binary operations
  • Loading branch information
wesuRage authored Dec 10, 2024
2 parents 6cb04e8 + 7497902 commit eb4acc4
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/a.glx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int oi := 3;
string oi := makonha == 3 ? "true" : "false";
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ AstNode *parse_additive_expr(Parser *parser) {
AstNode *left = parse_multiplicative_expr(parser);

while (at(parser).type == TOKEN_PLUS || at(parser).type == TOKEN_MINUS) {
char *operator = strdup(at(parser).lexeme);
eat(parser);
char *operator = strdup(eat(parser).lexeme);

AstNode *right = parse_multiplicative_expr(parser);

column_end = at(parser).column_end - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ AstNode *parse_bitwise_expr(Parser *parser){
|| at(parser).type == TOKEN_SHIFT_LEFT
|| at(parser).type == TOKEN_SHIFT_RIGHT
) {
char *operator= strdup(at(parser).lexeme);
eat(parser);
char *operator = strdup(eat(parser).lexeme);

AstNode *right = parse_additive_expr(parser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ AstNode *parse_equality_expr(Parser *parser) {
AstNode *left = parse_relational_expr(parser);

while(at(parser).type == TOKEN_EQUAL || at(parser).type == TOKEN_NEQUAL) {
char *operator = strdup(at(parser).lexeme);
eat(parser);
char *operator = strdup(eat(parser).lexeme);

AstNode *right = parse_relational_expr(parser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ AstNode *parse_exponential_expr(Parser *parser) {
AstNode *left = parse_call_member_expr(parser, NULL);

while(at(parser).type == TOKEN_POWER) {
char *operator = strdup(at(parser).lexeme);

eat(parser);
char *operator = strdup(eat(parser).lexeme);

AstNode *right = parse_call_member_expr(parser, NULL);

column_end = at(parser).column_end - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ AstNode *parse_logical_expr(Parser *parser) {
AstNode *left = parse_equality_expr(parser);

while(at(parser).type == TOKEN_AND || at(parser).type == TOKEN_OR) {
char *operator = strdup(at(parser).lexeme);
eat(parser);
char *operator = strdup(eat(parser).lexeme);

AstNode *right = parse_equality_expr(parser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ AstNode *parse_multiplicative_expr(Parser *parser) {
AstNode *left = parse_exponential_expr(parser);

while (at(parser).type == TOKEN_MUL || at(parser).type == TOKEN_DIV || at(parser).type == TOKEN_MODULUS) {
char *operator = strdup(at(parser).lexeme);
eat(parser);
char *operator = strdup(eat(parser).lexeme);

AstNode *right = parse_exponential_expr(parser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ AstNode *parse_relational_expr(Parser *parser) {
|| at(parser).type == TOKEN_LT
|| at(parser).type == TOKEN_LEQUAL
) {
char *operator = strdup(at(parser).lexeme);
eat(parser);
char *operator = strdup(eat(parser).lexeme);

AstNode *right = parse_logical_not_expr(parser);

Expand Down

0 comments on commit eb4acc4

Please sign in to comment.