summaryrefslogtreecommitdiff
path: root/parse/gram.y
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-03-06 11:47:45 -0800
committerOri Bernstein <ori@markovcorp.com>2018-03-06 11:47:45 -0800
commit7b024df82962f4bfe24db5b74fe2a92aac26cf8e (patch)
tree71c499cbc5964b8a9823fef21d1e8b09ee98c0b3 /parse/gram.y
parent27b4f894b3b7456b64908ad8c2d50ba66ebb513a (diff)
downloadmc-7b024df82962f4bfe24db5b74fe2a92aac26cf8e.tar.gz
Add ternary operator.
Diffstat (limited to 'parse/gram.y')
-rw-r--r--parse/gram.y13
1 files changed, 10 insertions, 3 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 5c73295..8fb448b 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -83,6 +83,7 @@ static void setupinit(Node *n);
%token<tok> Tcsqbrac /* ] */
%token<tok> Ttick /* ` */
%token<tok> Tderef /* # */
+%token<tok> Tqmark /* ? */
%token<tok> Ttype /* type */
%token<tok> Tfor /* for */
@@ -145,7 +146,7 @@ static void setupinit(Node *n);
%type<node> exprln retexpr goto continue break expr atomicexpr
%type<node> littok literal lorexpr landexpr borexpr strlit bandexpr
-%type<node> cmpexpr addexpr mulexpr shiftexpr prefixexpr
+%type<node> cmpexpr addexpr mulexpr shiftexpr prefixexpr ternexpr
%type<node> postfixexpr funclit seqlit tuplit name block stmt label
%type<node> use fnparam declbody declcore typedeclcore autodecl structent
%type<node> arrayelt structelt tuphead ifstmt forstmt whilestmt
@@ -692,9 +693,9 @@ optexprln
exprln : expr Tendln
;
-expr : lorexpr asnop expr
+expr : ternexpr asnop expr
{$$ = mkexpr($1->loc, binop($2->type), $1, $3, NULL);}
- | lorexpr
+ | ternexpr
;
asnop : Tasn
@@ -710,6 +711,12 @@ asnop : Tasn
| Tbsreq /* >>= */
;
+ternexpr
+ : lorexpr
+ | lorexpr Tqmark lorexpr Tcolon lorexpr
+ {$$ = mkexpr($1->loc, Otern, $1, $3, $5, NULL);}
+ ;
+
lorexpr : lorexpr Tlor landexpr
{$$ = mkexpr($1->loc, binop($2->type), $1, $3, NULL);}
| landexpr