Index: ast_expr2.fl =================================================================== RCS file: /usr/cvsroot/asterisk/ast_expr2.fl,v retrieving revision 1.2 diff -u -r1.2 ast_expr2.fl --- ast_expr2.fl 20 May 2005 03:18:35 -0000 1.2 +++ ast_expr2.fl 4 Jun 2005 16:14:40 -0000 @@ -66,7 +66,9 @@ \* { SET_COLUMNS; SET_STRING; return TOK_MULT;} \/ { SET_COLUMNS; SET_STRING; return TOK_DIV;} \% { SET_COLUMNS; SET_STRING; return TOK_MOD;} +\? { SET_COLUMNS; SET_STRING; return TOK_COND;} \: { SET_COLUMNS; SET_STRING; return TOK_COLON;} +\:\: { SET_COLUMNS; SET_STRING; return TOK_COLONCOLON;} \( { SET_COLUMNS; SET_STRING; return TOK_LP;} \) { SET_COLUMNS; SET_STRING; return TOK_RP;} @@ -79,7 +81,7 @@ yylval_param->val->type = AST_EXPR_integer; yylval_param->val->u.i = atoi(yytext); return TOKEN;} -[a-zA-Z0-9,.?';{}\\_^%$#@!]+ {SET_COLUMNS; SET_STRING; return TOKEN;} +[a-zA-Z0-9,.';{}\\_^%$#@!]+ {SET_COLUMNS; SET_STRING; return TOKEN;} %% Index: ast_expr2.y =================================================================== RCS file: /usr/cvsroot/asterisk/ast_expr2.y,v retrieving revision 1.2 diff -u -r1.2 ast_expr2.y --- ast_expr2.y 20 May 2005 03:18:35 -0000 1.2 +++ ast_expr2.y 4 Jun 2005 16:14:40 -0000 @@ -89,6 +89,7 @@ static struct val *op_gt __P((struct val *, struct val *)); static struct val *op_le __P((struct val *, struct val *)); static struct val *op_lt __P((struct val *, struct val *)); +static struct val *op_cond __P((struct val *, struct val *, struct val *)); static struct val *op_minus __P((struct val *, struct val *)); static struct val *op_negate __P((struct val *)); static struct val *op_compl __P((struct val *)); @@ -141,17 +142,17 @@ static int ast_yylex __P((YYSTYPE *, YYLTYPE *, yyscan_t)); %} */ - +%left TOK_COND TOK_COLONCOLON %left TOK_OR %left TOK_AND %left TOK_EQ TOK_GT TOK_LT TOK_GE TOK_LE TOK_NE %left TOK_PLUS TOK_MINUS %left TOK_MULT TOK_DIV TOK_MOD -%left TOK_COMPL TOK_EQTILDE -%left UMINUS -%left TOK_COLON +%right TOK_COMPL +%left TOK_COLON TOK_EQTILDE %left TOK_RP TOK_LP + %token TOKEN %type start expr @@ -196,10 +197,10 @@ | expr TOK_MINUS expr { $$ = op_minus ($1, $3); @$.first_column = @1.first_column; @$.last_column = @3.last_column; @$.first_line=0; @$.last_line=0;} - | TOK_MINUS expr %prec UMINUS { $$ = op_negate ($2); + | TOK_MINUS expr %prec TOK_COMPL { $$ = op_negate ($2); @$.first_column = @1.first_column; @$.last_column = @2.last_column; @$.first_line=0; @$.last_line=0;} - | TOK_COMPL expr %prec UMINUS { $$ = op_compl ($2); + | TOK_COMPL expr { $$ = op_compl ($2); @$.first_column = @1.first_column; @$.last_column = @2.last_column; @$.first_line=0; @$.last_line=0;} | expr TOK_MULT expr { $$ = op_times ($1, $3); @@ -217,6 +218,9 @@ | expr TOK_EQTILDE expr { $$ = op_eqtilde ($1, $3); @$.first_column = @1.first_column; @$.last_column = @3.last_column; @$.first_line=0; @$.last_line=0;} + | expr TOK_COND expr TOK_COLONCOLON expr { $$ = op_cond ($1, $3, $5); + @$.first_column = @1.first_column; @$.last_column = @3.last_column; + @$.first_line=0; @$.last_line=0;} ; %% @@ -520,6 +524,45 @@ free_value (a); free_value (b); + return r; +} + +static struct val * +op_cond (struct val *a, struct val *b, struct val *c) +{ + struct val *r; + + if( isstring(a) ) + { + if( strlen(a->u.s) && strcmp(a->u.s, "\"\"") != 0 && strcmp(a->u.s,"0") != 0 ) + { + free_value(a); + free_value(c); + r = b; + } + else + { + free_value(a); + free_value(b); + r = c; + } + } + else + { + (void)to_integer(a); + if( a->u.i ) + { + free_value(a); + free_value(c); + r = b; + } + else + { + free_value(a); + free_value(b); + r = c; + } + } return r; } Index: doc/README.variables =================================================================== RCS file: /usr/cvsroot/asterisk/doc/README.variables,v retrieving revision 1.46 diff -u -r1.46 README.variables --- doc/README.variables 16 May 2005 00:43:16 -0000 1.46 +++ doc/README.variables 4 Jun 2005 16:14:40 -0000 @@ -229,11 +229,15 @@ ** - expr1 ** Return the result of subtracting expr1 from 0. +** This, the unary minus operator, is right associative, and +** has the same precedence as the ! operator. ** ** ! expr1 ** Return the result of a logical complement of expr1. ** In other words, if expr1 is null, 0, an empty string, ** or the string "0", return a 1. Otherwise, return a "0". (only with flex >= 2.5.31) +** It has the same precedence as the unary minus operator, and +** is also right associative. expr1 : expr2 The `:' operator matches expr1 against expr2, which must be a @@ -253,12 +257,22 @@ characters are stripped from both the pattern and the string. ** expr1 =~ expr2 -** Exactly the same as the ':' operator, except that the match is -** not anchored to the beginning of the string. Pardon any similarity -** to seemingly similar operators in other programming languages! -** (only if flex >= 2.5.31) - - +** Exactly the same as the ':' operator, except that the match is +** not anchored to the beginning of the string. Pardon any similarity +** to seemingly similar operators in other programming languages! +** (only if flex >= 2.5.31). The ":" and "=~" operators share the +** same precedence. + +** expr1 ? expr2 :: expr3 +** Traditional Conditional operator. If expr1 is a number that evaluates +** to 0 (false), expr3 is result of the this expression evaluation. +** Otherwise, expr2 is the result. +** If expr1 is a string, and evaluates to an empty string, or the two +** characters (""), then expr3 is the result. Otherwise, expr2 is the result. +** In Asterisk, all 3 exprs will be "evaluated"; if expr1 is "true", +** expr2 will be the result of the "evaluation" of this expression. +** expr3 will be the result otherwise. This operator has the lowest +** precedence. Parentheses are used for grouping in the usual manner. @@ -315,7 +329,7 @@ CONDITIONALS --------------------------- -There is one conditional operator - the conditional goto : +There is one conditional application - the conditional goto : exten => 1,2,gotoif(condition?label1:label2) @@ -498,6 +512,12 @@ ** match anywhere in the string. The only diff with the ':' is that ** match doesn't have to be anchored to the beginning of the string. +**9. Added the conditional operator 'expr1 ? true_expr :: false_expr' +** First, all 3 exprs are evaluated, and if expr1 is false, the 'false_expr' +** is returned as the result. See above for details. + +**10. Unary operators '-' and '!' were made right associative. + --------------------------------------------------------- Asterisk standard channel variables