diff --git a/builtin.c b/builtin.c index f184ff7f..3d726854 100644 --- a/builtin.c +++ b/builtin.c @@ -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}, diff --git a/lexer.l b/lexer.l index cac08ec7..5c6b62f4 100644 --- a/lexer.l +++ b/lexer.l @@ -33,6 +33,7 @@ "#"[^\r\n]* { /* comments */ } +"!=" { return NEQ; } "==" { return EQ; } "as" { return AS; } "def" { return DEF; } diff --git a/parser.y b/parser.y index 38e72ee3..b0e4e521 100644 --- a/parser.y +++ b/parser.y @@ -46,6 +46,7 @@ typedef void* yyscan_t; %token IDENT %token 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, '<'); } |