From: Matthias Kruk Date: Sun, 5 Jul 2020 07:28:46 +0000 (+0900) Subject: parser: Implement parsing of assignment expressions X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=bf82b37e1799f7fee0e2002edb447ecc7afb8191;p=ccc parser: Implement parsing of assignment expressions --- diff --git a/src/parser.c b/src/parser.c index 8211cbc..28e82af 100644 --- a/src/parser.c +++ b/src/parser.c @@ -591,6 +591,10 @@ struct primary_expression *parse_primary_expression(void) * position and free the struct, since we can't match a primary expression. */ + if(pe->data.expr.expr) { + free(pe->data.expr.expr); + } + lex_setpos(pos); free(pe); pe = NULL; @@ -599,3 +603,64 @@ struct primary_expression *parse_primary_expression(void) return(pe); } + +struct assignment_expression *parse_assignment_expression(void) +{ + struct assignment_expression *ae; + + ae = assignment_expression_new(); + + if(!ae) { + return(NULL); + } + + if((ae->data.cexpr = parse_conditional_expression())) { + ae->type = ASSIGNMENT_EXPR_CONDITIONAL; + } else { + int pos; + + pos = lex_getpos(); + + ae->data.aexpr.uexpr = parse_unary_expression(); + ae->data.aexpr.op = lex_gettoken(); + ae->data.aexpr.aexpr = parse_assignment_expression(); + + if(ae->data.aexpr.uexpr && ae->data.aexpr.op && ae->data.aexpr.aexpr && + (ae->data.aexpr.op->type == TOKEN_ASSIGN || + ae->data.aexpr.op->type == TOKEN_ASSIGN_ADD || + ae->data.aexpr.op->type == TOKEN_ASSIGN_AND || + ae->data.aexpr.op->type == TOKEN_ASSIGN_MOD || + ae->data.aexpr.op->type == TOKEN_ASSIGN_MUL || + ae->data.aexpr.op->type == TOKEN_ASSIGN_OR || + ae->data.aexpr.op->type == TOKEN_ASSIGN_SHL || + ae->data.aexpr.op->type == TOKEN_ASSIGN_SHR || + ae->data.aexpr.op->type == TOKEN_ASSIGN_SUB || + ae->data.aexpr.op->type == TOKEN_ASSIGN_XOR)) { + ae->type = ASSIGNMENT_EXPR_ASSIGNMENT; + } else { + if(ae->data.aexpr.uexpr) { + free(ae->data.aexpr.uexpr); + } + + if(ae->data.aexpr.aexpr) { + free(ae->data.aexpr.aexpr); + } + + lex_setpos(pos); + free(ae); + ae = NULL; + } + } + + return(ae); +} + +struct unary_expression *parse_unary_expression(void) +{ + return(NULL); +} + +struct conditional_expression *parse_conditional_expression(void) +{ + return(NULL); +}