hyc

Hydrogen Compiler written in C
git clone git://git.kocotian.pl/hyc.git
Log | Files | Refs | README | LICENSE

commit cfe9fa01ce7c08569ab5d53c0610d3a093334b80
parent f4040ead76593e34cc8d9923d624498e314fef1b
Author: kocotian <kocotian@kocotian.pl>
Date:   Fri, 30 Jul 2021 22:35:02 +0000

Binary expressions: assignment

Diffstat:
Mast.c | 12++++++++++++
Minclude/ast.h | 9+++++++++
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/ast.c b/ast.c @@ -195,6 +195,18 @@ tokenstoASTExpression(Tokenizer *t) new(expr.FunctionCall.callexpr) = callexpr; new(expr.FunctionCall.argv) = tokenstoASTExpressionFunctionArgumentList(t); + } else if (tok->type == TokenAssignment) { /* assignment */ + ASTExpression right = tokenstoASTExpression(t); + ASTExpression left = { + .Unary = { + .type = ASTExpressionUnaryAddressof_T, + .expr = malloc(sizeof left.Unary.expr) + } + }; + *(left.Unary.expr) = expr; + expr.type = ASTExpressionBinaryAssignment_T; + new(expr.BinaryAssignment.right) = right; + new(expr.BinaryAssignment.left) = left; } else { prevToken(t); } diff --git a/include/ast.h b/include/ast.h @@ -55,6 +55,7 @@ typedef enum ASTExpressionType { ASTExpressionUnaryPredecrement_T, ASTExpressionFunctionArgumentList_T, ASTExpressionFunctionCall_T, + ASTExpressionBinaryAssignment_T, ASTExpression_Count, } ASTExpressionType; @@ -72,6 +73,12 @@ typedef struct ASTExpressionUnary { union ASTExpression *expr; } ASTExpressionUnary; +typedef struct ASTExpressionBinary { + enum ASTExpressionType type; + union ASTExpression *left; + union ASTExpression *right; +} ASTExpressionBinary; + typedef struct ASTExpressionFunctionArgumentList { enum ASTExpressionType type; union ASTExpression *data; @@ -97,6 +104,8 @@ typedef union ASTExpression { struct ASTExpressionUnary UnaryPredecrement; struct ASTExpressionFunctionArgumentList FunctionArgumentList; struct ASTExpressionFunctionCall FunctionCall; + struct ASTExpressionBinary Binary; + struct ASTExpressionBinary BinaryAssignment; } ASTExpression; /**/