From 6e85377d7a5733dccd811429b58866090393b8a6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 12 Nov 2021 00:19:58 +0900 Subject: [PATCH] [cexpr] Support variable assignment I might have to add code to block it when necessary, but it's needed for axis recipe parsing. --- libs/util/cexpr-lex.l | 9 +++++++++ libs/util/cexpr-parse.y | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/libs/util/cexpr-lex.l b/libs/util/cexpr-lex.l index 3fafef8e6..026f7eea2 100644 --- a/libs/util/cexpr-lex.l +++ b/libs/util/cexpr-lex.l @@ -166,15 +166,23 @@ STRING \"(\\.|[^"\\])*\" } [+\-*/&|^%]= { + yylval->op = yytext[0]; + return ASX; } "%%=" { + yylval->op = MOD; + return ASX; } "<<=" { + yylval->op = SHL; + return ASX; } ">>=" { + yylval->op = SHR; + return ASX; } [!(){}.*/&|^~+\-=\[\];,#%?:] { @@ -182,6 +190,7 @@ STRING \"(\\.|[^"\\])*\" } "%%" { + return MOD; } "<<" return SHL; diff --git a/libs/util/cexpr-parse.y b/libs/util/cexpr-parse.y index fca9171af..46eaae7fe 100644 --- a/libs/util/cexpr-parse.y +++ b/libs/util/cexpr-parse.y @@ -51,8 +51,8 @@ #include "QF/cexpr.h" -static void assign_expr (exprval_t *dst, const exprval_t *src, - exprctx_t *context); +static exprval_t *assign_expr (exprval_t *dst, const exprval_t *src, + exprctx_t *context); static exprval_t *binary_expr (int op, const exprval_t *a, const exprval_t *b, exprctx_t *context); static exprval_t *field_expr (const exprval_t *a, const exprval_t *b, @@ -138,6 +138,7 @@ uexpr expr : uexpr + | expr '=' expr { $$ = assign_expr ($1, $3, context); } | expr SHL expr { $$ = binary_expr (SHL, $1, $3, context); } | expr SHR expr { $$ = binary_expr (SHR, $1, $3, context); } | expr '+' expr { $$ = binary_expr ('+', $1, $3, context); } @@ -184,16 +185,16 @@ arg_expr %% -static void +static exprval_t * assign_expr (exprval_t *dst, const exprval_t *src, exprctx_t *context) { binop_t *binop; - if (!src) { - return; + if (!dst || !src) { + return 0; } if (dst->type == &cexpr_exprval) { *(exprval_t **) dst->value = (exprval_t *) src; - return; + return dst; } binop = cexpr_find_cast (dst->type, src->type); if (binop && binop->op) { @@ -203,10 +204,11 @@ assign_expr (exprval_t *dst, const exprval_t *src, exprctx_t *context) cexpr_error (context, "type mismatch in expression result: %s = %s", dst->type->name, src->type->name); - return; + return dst; } memcpy (dst->value, src->value, dst->type->size); } + return dst; } static exprval_t *