diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2017-01-18 19:40:18 -0600 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2017-01-18 19:40:18 -0600 |
commit | 6c6b91f9a6bc5ae203e99ac7abb3a70215488a6f (patch) | |
tree | a60ee21b204363128001cf323e5914745a630afd /parser.y | |
parent | 1e0d0202e614f398f491624c84ae9a8309fa2f96 (diff) |
nqasm: support unary operators in immediate expressions
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -16,6 +16,7 @@ void yyerror(const char *msg) #define MKARGVALUE(v) (struct argument) { .type = ARG_INTEGER, .value = (v) } #define MKARGLABEL(l) (struct argument) { .type = ARG_LABEL, .label = (l) } #define MKARGTYPE(t) (struct argument) { .type = (t) } +#define MKARGEXPR(op,c) (struct argument) { .type = (op), .children = c } %} @@ -84,6 +85,11 @@ void yyerror(const char *msg) %token T_DOT "." %token T_DEREF "@" +%token T_OPERATOR_ADD "+" +%token T_OPERATOR_SUB "-" +%token T_OPERATOR_NOT "!" +%token T_OPERATOR_INV "~" + %type <inst> inst %type <arg> reg %type <arg> regp @@ -181,6 +187,10 @@ expr: intlit { $$ = MKARGVALUE($1); } | T_LABEL { $$ = MKARGLABEL($1); } | "." { $$ = MKARGTYPE(ARG_PC); } + | "+" expr { $$ = MKARGEXPR(ARG_UNARY_ADD, { argdup(&$2) }); } + | "-" expr { $$ = MKARGEXPR(ARG_UNARY_SUB, { argdup(&$2) }); } + | "!" expr { $$ = MKARGEXPR(ARG_UNARY_NOT, { argdup(&$2) }); } + | "~" expr { $$ = MKARGEXPR(ARG_UNARY_INV, { argdup(&$2) }); } ; intlit: T_INT |