diff options
author | Damian Gryski <damian@gryski.com> | 2012-10-23 17:01:39 +0200 |
---|---|---|
committer | Damian Gryski <damian@gryski.com> | 2012-10-23 17:01:39 +0200 |
commit | 553de39b2a9c45110ed25a714fb249bd6037f874 (patch) | |
tree | 6a54a2da8d510b182bcf17b59481b1ef4b2c2913 | |
parent | b193bca563f377f97b9a6efcf5b054bd70fb1f46 (diff) |
Implement 'not equal' (!=) as a binop
-rw-r--r-- | builtin.c | 6 | ||||
-rw-r--r-- | lexer.l | 1 | ||||
-rw-r--r-- | parser.y | 8 |
3 files changed, 14 insertions, 1 deletions
@@ -120,6 +120,11 @@ static void f_equal(jv input[], jv output[]) { output[0] = jv_bool(jv_equal(input[2], input[1])); } +static void f_notequal(jv input[], jv output[]) { + jv_free(input[0]); + output[0] = jv_bool(jv_equal(input[2], input[1]) == 0); +} + static void order_cmp(jv input[], jv output[], int op) { jv_free(input[0]); jv a = input[2]; @@ -284,6 +289,7 @@ static struct cfunction function_list[] = { {f_tostring, "tostring", CALL_BUILTIN_1_1}, {f_keys, "keys", CALL_BUILTIN_1_1}, {f_equal, "_equal", CALL_BUILTIN_3_1}, + {f_notequal, "_notequal", CALL_BUILTIN_3_1}, {f_less, "_less", CALL_BUILTIN_3_1}, {f_greater, "_greater", CALL_BUILTIN_3_1}, {f_lesseq, "_lesseq", CALL_BUILTIN_3_1}, @@ -33,6 +33,7 @@ "#"[^\r\n]* { /* comments */ } +"!=" { return NEQ; } "==" { return EQ; } "as" { return AS; } "def" { return DEF; } @@ -46,6 +46,7 @@ typedef void* yyscan_t; %token <literal> IDENT %token <literal> LITERAL %token EQ "==" +%token NEQ "!=" %token DEFINEDOR "//" %token AS "as" %token DEF "def" @@ -79,7 +80,7 @@ typedef void* yyscan_t; %nonassoc '=' SETPIPE SETPLUS SETMINUS SETMULT SETDIV SETDEFINEDOR %left OR %left AND -%nonassoc EQ '<' '>' LESSEQ GREATEREQ +%nonassoc NEQ EQ '<' '>' LESSEQ GREATEREQ %left '+' '-' %left '*' '/' @@ -142,6 +143,7 @@ static block gen_binop(block a, block b, int op) { case '*': funcname = "_multiply"; break; case '/': funcname = "_divide"; break; case EQ: funcname = "_equal"; break; + case NEQ: funcname = "_notequal"; break; case '<': funcname = "_less"; break; case '>': funcname = "_greater"; break; case LESSEQ: funcname = "_lesseq"; break; @@ -282,6 +284,10 @@ Exp "==" Exp { $$ = gen_binop($1, $3, EQ); } | +Exp "!=" Exp { + $$ = gen_binop($1, $3, NEQ); +} | + Exp '<' Exp { $$ = gen_binop($1, $3, '<'); } | |