diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-03-22 22:07:29 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-03-22 22:07:29 -0400 |
commit | 7fc84f364bcb2e37363d3e22300180ba92288811 (patch) | |
tree | 66d12cb09c22d4df311feffd4d418bfae6ba5568 /dimension/common.rules | |
parent | 80b15832f59b5a5b4e7476c6eb4099b6edccbb1b (diff) | |
download | dimension-7fc84f364bcb2e37363d3e22300180ba92288811.tar.xz |
Support the ternary operator.
Diffstat (limited to 'dimension/common.rules')
-rw-r--r-- | dimension/common.rules | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/dimension/common.rules b/dimension/common.rules index 02f2010..81719c5 100644 --- a/dimension/common.rules +++ b/dimension/common.rules @@ -395,7 +395,10 @@ ARITH_EXPR: FLOAT_LITERAL | ARITH_EXPR "." "transmit" { $$ = dmnsn_new_astnode1(DMNSN_AST_DOT_TRANSMIT, @$, $1); } - | "(" ARITH_EXPR ")" { $$ = $2; } + | "(" ARITH_EXPR ")" %dprec 2 { $$ = $2; } + | "(" CONDITIONAL "?" ARITH_EXPR ":" ARITH_EXPR ")" { + $$ = dmnsn_new_astnode3(DMNSN_AST_TERNARY, @$, $2, $4, $6); + } | "abs" "(" ARITH_EXPR ")" { $$ = dmnsn_new_astnode1(DMNSN_AST_ABS, @$, $3); } @@ -530,6 +533,43 @@ MIN_LIST: ARITH_EXPR "," ARITH_EXPR { } ; +CONDITIONAL: ARITH_EXPR { + /* Force the expression to be evaluated logically */ + dmnsn_astnode zero = dmnsn_new_ast_integer(0); + $$ = dmnsn_new_astnode2(DMNSN_AST_OR, @$, zero, $1); + } + | ARITH_EXPR "=" ARITH_EXPR { + $$ = dmnsn_new_astnode2(DMNSN_AST_EQUAL, @$, $1, $3); + } + | ARITH_EXPR "!=" ARITH_EXPR { + $$ = dmnsn_new_astnode2(DMNSN_AST_NOT_EQUAL, @$, $1, $3); + } + | ARITH_EXPR "<" ARITH_EXPR { + $$ = dmnsn_new_astnode2(DMNSN_AST_LESS, @$, $1, $3); + } + | ARITH_EXPR "<=" ARITH_EXPR { + $$ = dmnsn_new_astnode2(DMNSN_AST_LESS_EQUAL, @$, $1, $3); + } + | ARITH_EXPR ">" ARITH_EXPR { + $$ = dmnsn_new_astnode2(DMNSN_AST_GREATER, @$, $1, $3); + } + | ARITH_EXPR ">=" ARITH_EXPR { + $$ = dmnsn_new_astnode2(DMNSN_AST_GREATER_EQUAL, @$, $1, $3); + } + | CONDITIONAL "&" CONDITIONAL { + $$ = dmnsn_new_astnode2(DMNSN_AST_AND, @$, $1, $3); + } + | CONDITIONAL "|" CONDITIONAL { + $$ = dmnsn_new_astnode2(DMNSN_AST_OR, @$, $1, $3); + } + | "(" CONDITIONAL ")" %dprec 1 { + $$ = $2; + } + | "!" CONDITIONAL { + $$ = dmnsn_new_astnode1(DMNSN_AST_NOT, @$, $2); + } +; + /* Colors */ COLOR: COLOR_BODY { |