Browse Source

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 16 years ago
parent
commit
298512a2b7
2 changed files with 15 additions and 1 deletions
  1. 8 0
      cfg.lex
  2. 7 1
      cfg.y

+ 8 - 0
cfg.lex

@@ -248,6 +248,10 @@ MINUS	"-"
 STRLEN	"strlen"
 STREMPTY	"strempty"
 DEFINED		"defined"
+STREQ	eq
+INTEQ	ieq
+STRDIFF	ne
+INTDIFF	ine
 
 /* Attribute specification */
 ATTR_MARK   "%"
@@ -772,6 +776,10 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{STRLEN}	{ count(); return STRLEN; }
 <INITIAL>{STREMPTY}	{ count(); return STREMPTY; }
 <INITIAL>{DEFINED}	{ count(); return DEFINED; }
+<INITIAL>{STREQ}	{ count(); return STREQ; }
+<INITIAL>{INTEQ}	{ count(); return INTEQ; }
+<INITIAL>{STRDIFF}	{ count(); return STRDIFF; }
+<INITIAL>{INTDIFF}	{ count(); return INTDIFF; }
 
 <INITIAL>{SELECT_MARK}  { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
 <SELECT>{ID}		{ count(); addstr(&s_buf, yytext, yyleng);

+ 7 - 1
cfg.y

@@ -484,7 +484,7 @@ static int case_check_default(struct case_stms* stms);
 %left LOG_AND
 %left BIN_OR
 %left BIN_AND
-%left EQUAL_T DIFF MATCH
+%left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF
 %left GT LT GTE LTE
 %left PLUS MINUS
 %left STAR SLASH
@@ -1580,6 +1580,8 @@ exp:	rval_expr
 equalop:
 	EQUAL_T {$$=EQUAL_OP; }
 	| DIFF	{$$=DIFF_OP; }
+	| STREQ	{$$=EQUAL_OP; }  /* for expr. elems equiv. to EQUAL_T*/
+	| STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
 	;
 cmpop:
 	  GT	{$$=GT_OP; }
@@ -1597,6 +1599,10 @@ strop:
 rve_equalop:
 	EQUAL_T {$$=RVE_EQ_OP; }
 	| DIFF	{$$=RVE_DIFF_OP; }
+	| INTEQ	{$$=RVE_IEQ_OP; }
+	| INTDIFF {$$=RVE_IDIFF_OP; }
+	| STREQ	{$$=RVE_STREQ_OP; }
+	| STRDIFF {$$=RVE_STRDIFF_OP; }
 	;
 rve_cmpop:
 	  GT	{$$=RVE_GT_OP; }