summaryrefslogtreecommitdiff
path: root/parser.y
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2017-01-18 19:40:18 -0600
committerBobby Bingham <koorogi@koorogi.info>2017-01-18 19:40:18 -0600
commit6c6b91f9a6bc5ae203e99ac7abb3a70215488a6f (patch)
treea60ee21b204363128001cf323e5914745a630afd /parser.y
parent1e0d0202e614f398f491624c84ae9a8309fa2f96 (diff)
nqasm: support unary operators in immediate expressions
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y10
1 files changed, 10 insertions, 0 deletions
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> 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