]> git.corax.cc Git - ccc/commitdiff
parser: Implement parsing of assignment expressions
authorMatthias Kruk <m@m10k.eu>
Sun, 5 Jul 2020 07:28:46 +0000 (16:28 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 5 Jul 2020 07:28:46 +0000 (16:28 +0900)
src/parser.c

index 8211cbcd03badbbddb129c135cd12e3a66543fb9..28e82afaed7bb2a50598b90ebb7ca2d897815664 100644 (file)
@@ -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);
+}