From 6c6b91f9a6bc5ae203e99ac7abb3a70215488a6f Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Wed, 18 Jan 2017 19:40:18 -0600 Subject: nqasm: support unary operators in immediate expressions --- parser.y | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'parser.y') diff --git a/parser.y b/parser.y index 2ec2264..cb1343f 100644 --- a/parser.y +++ b/parser.y @@ -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 %type reg %type 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 -- cgit v1.2.3