Support ternary conditionals (a ? b : c) in constant expressions.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9330 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2006-09-23 09:35:31 +00:00
commit 4f803bf0c4
4 changed files with 22 additions and 3 deletions

View file

@ -1390,6 +1390,7 @@ static void default_arguments(Node *n) {
%token WARN
%token LESSTHAN GREATERTHAN MODULO DELETE_KW
%token LESSTHANOREQUALTO GREATERTHANOREQUALTO EQUALTO NOTEQUALTO
%token QUESTIONMARK
%token TYPES PARMS
%token NONID DSTAR DCNOT
%token <ivalue> TEMPLATE
@ -1398,6 +1399,7 @@ static void default_arguments(Node *n) {
%token PARSETYPE PARSEPARM PARSEPARMS
%left CAST
%left QUESTIONMARK
%left LOR
%left LAND
%left OR
@ -5445,6 +5447,12 @@ exprcompound : expr PLUS expr {
$$.val = NewStringf("%s<=%s",$1.val,$3.val);
$$.type = T_INT;
}
| expr QUESTIONMARK expr COLON expr {
$$.val = NewStringf("%s?%s:%s", $1.val, $3.val, $5.val);
/* This may not be exactly right, but is probably good enough
* for the purposes of parsing constant expressions. */
$$.type = promote($3.type, $5.type);
}
| MINUS expr %prec UMINUS {
$$.val = NewStringf("-%s",$2.val);
$$.type = $2.type;