added assignment operator
This commit is contained in:
@@ -18,6 +18,7 @@ typedef enum {
|
||||
EXPR_SUB,
|
||||
EXPR_MUL,
|
||||
EXPR_DIV,
|
||||
EXPR_ASS,
|
||||
EXPR_INT,
|
||||
EXPR_NONE,
|
||||
EXPR_TRUE,
|
||||
|
||||
@@ -50,6 +50,29 @@ static _Bool emit_instr_for_node(ExeBuilder *exeb, Node *node, Error *error)
|
||||
NULL, 0, node->offset, node->length);
|
||||
}
|
||||
|
||||
case EXPR_ASS:
|
||||
{
|
||||
OperExprNode *oper = (OperExprNode*) expr;
|
||||
|
||||
Node *lop, *rop;
|
||||
lop = oper->head;
|
||||
rop = lop->next;
|
||||
|
||||
if(((ExprNode*) lop)->kind != EXPR_IDENT)
|
||||
{
|
||||
Error_Report(error, 0, "Assignment left operand must be an identifier");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!emit_instr_for_node(exeb, rop, error))
|
||||
return 0;
|
||||
|
||||
const char *name = ((IdentExprNode*) lop)->val;
|
||||
|
||||
Operand op = { .type = OPTP_STRING, .as_string = name };
|
||||
return ExeBuilder_Append(exeb, error, OPCODE_ASS, &op, 1, node->offset, node->length);
|
||||
}
|
||||
|
||||
case EXPR_INT:
|
||||
{
|
||||
IntExprNode *p = (IntExprNode*) expr;
|
||||
|
||||
@@ -852,15 +852,15 @@ static inline _Bool isbinop(Token *tok)
|
||||
return tok->kind == '+' ||
|
||||
tok->kind == '-' ||
|
||||
tok->kind == '*' ||
|
||||
tok->kind == '/';
|
||||
tok->kind == '/' ||
|
||||
tok->kind == '=';
|
||||
}
|
||||
|
||||
static inline _Bool isrightassoc(Token *tok)
|
||||
{
|
||||
assert(tok != NULL);
|
||||
|
||||
(void) tok;
|
||||
return 0;
|
||||
return tok->kind == '=';
|
||||
}
|
||||
|
||||
static inline int precedenceof(Token *tok)
|
||||
@@ -869,6 +869,9 @@ static inline int precedenceof(Token *tok)
|
||||
|
||||
switch(tok->kind)
|
||||
{
|
||||
case '=':
|
||||
return 0;
|
||||
|
||||
case '+':
|
||||
case '-':
|
||||
return 1;
|
||||
@@ -928,6 +931,7 @@ static Node *parse_expression_2(Context *ctx, Node *left_expr, int min_prec)
|
||||
case '-': temp->base.kind = EXPR_SUB; break;
|
||||
case '*': temp->base.kind = EXPR_MUL; break;
|
||||
case '/': temp->base.kind = EXPR_DIV; break;
|
||||
case '=': temp->base.kind = EXPR_ASS; break;
|
||||
|
||||
default:
|
||||
UNREACHABLE;
|
||||
|
||||
Reference in New Issue
Block a user