Browse code

core: new script operators: eq, ne, ieq, ine

Added operators for: - string == and string != : eq, ne
- integer == and integer!= : ieq, ine
They are almost equivalent to == or !=, but they force the
conversion of their operands (eq to string and ieq to int),
allowing among other things better type checking on startup
and more optimizations.
Non equiv. examples: 0 == "" (true) is not equivalent to 0 eq ""
(false: it evaluates to "0" eq ""). "a" ieq "b" (true: (int)"a" is
0 and (int)"b" is 0) is not equivalent to "a" == "b" (false).

Note: the names are not final, they are mostly for testing.
Future releases might replace ==/!= with ieq/ine and use eq/ne for
strings.

Andrei Pelinescu-Onciul authored on 28/04/2009 17:48:11
Showing 2 changed files
... ...
@@ -248,6 +248,10 @@ MINUS	"-"
248 248
 STRLEN	"strlen"
249 249
 STREMPTY	"strempty"
250 250
 DEFINED		"defined"
251
+STREQ	eq
252
+INTEQ	ieq
253
+STRDIFF	ne
254
+INTDIFF	ine
251 255
 
252 256
 /* Attribute specification */
253 257
 ATTR_MARK   "%"
... ...
@@ -772,6 +776,10 @@ EAT_ABLE	[\ \t\b\r]
772 772
 <INITIAL>{STRLEN}	{ count(); return STRLEN; }
773 773
 <INITIAL>{STREMPTY}	{ count(); return STREMPTY; }
774 774
 <INITIAL>{DEFINED}	{ count(); return DEFINED; }
775
+<INITIAL>{STREQ}	{ count(); return STREQ; }
776
+<INITIAL>{INTEQ}	{ count(); return INTEQ; }
777
+<INITIAL>{STRDIFF}	{ count(); return STRDIFF; }
778
+<INITIAL>{INTDIFF}	{ count(); return INTDIFF; }
775 779
 
776 780
 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
777 781
 <SELECT>{ID}		{ count(); addstr(&s_buf, yytext, yyleng);
... ...
@@ -484,7 +484,7 @@ static int case_check_default(struct case_stms* stms);
484 484
 %left LOG_AND
485 485
 %left BIN_OR
486 486
 %left BIN_AND
487
-%left EQUAL_T DIFF MATCH
487
+%left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF
488 488
 %left GT LT GTE LTE
489 489
 %left PLUS MINUS
490 490
 %left STAR SLASH
... ...
@@ -1580,6 +1580,8 @@ exp:	rval_expr
1580 1580
 equalop:
1581 1581
 	EQUAL_T {$$=EQUAL_OP; }
1582 1582
 	| DIFF	{$$=DIFF_OP; }
1583
+	| STREQ	{$$=EQUAL_OP; }  /* for expr. elems equiv. to EQUAL_T*/
1584
+	| STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
1583 1585
 	;
1584 1586
 cmpop:
1585 1587
 	  GT	{$$=GT_OP; }
... ...
@@ -1597,6 +1599,10 @@ strop:
1597 1597
 rve_equalop:
1598 1598
 	EQUAL_T {$$=RVE_EQ_OP; }
1599 1599
 	| DIFF	{$$=RVE_DIFF_OP; }
1600
+	| INTEQ	{$$=RVE_IEQ_OP; }
1601
+	| INTDIFF {$$=RVE_IDIFF_OP; }
1602
+	| STREQ	{$$=RVE_STREQ_OP; }
1603
+	| STRDIFF {$$=RVE_STRDIFF_OP; }
1600 1604
 	;
1601 1605
 rve_cmpop:
1602 1606
 	  GT	{$$=RVE_GT_OP; }