diff options
author | hobbs <hobbs> | 2000-05-09 00:00:34 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2000-05-09 00:00:34 (GMT) |
commit | 427c904742d9d5aec8068fce38a28be9ae65af08 (patch) | |
tree | 1e3bab60e826e937b67fa7d70d97f4f352fe315a /generic/tclParseExpr.c | |
parent | 9f7b9b72befea46deb71233146973eea88223af0 (diff) | |
download | tcl-427c904742d9d5aec8068fce38a28be9ae65af08.zip tcl-427c904742d9d5aec8068fce38a28be9ae65af08.tar.gz tcl-427c904742d9d5aec8068fce38a28be9ae65af08.tar.bz2 |
* doc/expr.n:
* tests/expr.test:
* tests/expr-old.test: added tests for 'eq' and 'ne'
* generic/tclExecute.c:
* generic/tclCompile.h: added INST_STREQ and INST_STRNEQ opcodes
that do strict string comparisons.
* generic/tclCompExpr.c: added 'eq' and 'ne' string comparison
operators.
* generic/tclParseExpr.c (GetLexeme): added 'eq' and 'ne' expr
parse terms (string (in)equality check).
Diffstat (limited to 'generic/tclParseExpr.c')
-rw-r--r-- | generic/tclParseExpr.c | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/generic/tclParseExpr.c b/generic/tclParseExpr.c index b9c9d71..fbdd9ea 100644 --- a/generic/tclParseExpr.c +++ b/generic/tclParseExpr.c @@ -7,11 +7,12 @@ * code analysis, etc. * * Copyright (c) 1997 Sun Microsystems, Inc. + * Copyright (c) 1998-2000 by Scriptics Corporation. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclParseExpr.c,v 1.6 1999/12/04 06:15:42 hobbs Exp $ + * RCS: @(#) $Id: tclParseExpr.c,v 1.7 2000/05/09 00:00:35 hobbs Exp $ */ #include "tclInt.h" @@ -118,6 +119,9 @@ typedef struct ParseInfo { #define NOT 31 #define BIT_NOT 32 +#define STREQ 33 +#define STRNEQ 34 + /* * Mapping from lexemes to strings; used for debugging messages. These * entries must match the order and number of the lexeme definitions above. @@ -130,7 +134,7 @@ static char *lexemeStrings[] = { "*", "/", "%", "+", "-", "<<", ">>", "<", ">", "<=", ">=", "==", "!=", "&", "^", "|", "&&", "||", "?", ":", - "!", "~" + "!", "~", "eq", "ne", }; #endif /* TCL_COMPILE_DEBUG */ @@ -720,7 +724,8 @@ ParseBitAndExpr(infoPtr) * ParseEqualityExpr -- * * This procedure parses a Tcl equality (inequality) expression: - * equalityExpr ::= relationalExpr {('==' | '!=') relationalExpr} + * equalityExpr ::= relationalExpr + * {('==' | '!=' | 'ne' | 'eq') relationalExpr} * * Results: * The return value is TCL_OK on a successful parse and TCL_ERROR @@ -754,9 +759,10 @@ ParseEqualityExpr(infoPtr) } lexeme = infoPtr->lexeme; - while ((lexeme == EQUAL) || (lexeme == NEQ)) { + while ((lexeme == EQUAL) || (lexeme == NEQ) + || (lexeme == STREQ) || (lexeme == STRNEQ)) { operator = infoPtr->start; - code = GetLexeme(infoPtr); /* skip over == or != */ + code = GetLexeme(infoPtr); /* skip over ==, !=, 'eq' or 'ne' */ if (code != TCL_OK) { return code; } @@ -766,7 +772,8 @@ ParseEqualityExpr(infoPtr) } /* - * Generate tokens for the subexpression and '==' or '!=' operator. + * Generate tokens for the subexpression and '==', '!=', 'eq' or 'ne' + * operator. */ PrependSubExprTokens(operator, 2, srcStart, @@ -1735,7 +1742,30 @@ GetLexeme(infoPtr) infoPtr->lexeme = BIT_NOT; return TCL_OK; + case 'e': + if (src[1] == 'q') { + infoPtr->lexeme = STREQ; + infoPtr->size = 2; + infoPtr->next = src+2; + parsePtr->term = infoPtr->next; + return TCL_OK; + } else { + goto checkFuncName; + } + + case 'n': + if (src[1] == 'e') { + infoPtr->lexeme = STRNEQ; + infoPtr->size = 2; + infoPtr->next = src+2; + parsePtr->term = infoPtr->next; + return TCL_OK; + } else { + goto checkFuncName; + } + default: + checkFuncName: offset = Tcl_UtfToUniChar(src, &ch); c = UCHAR(ch); if (isalpha(UCHAR(c))) { /* INTL: ISO only. */ |