Skip to content
Browse files

Ternary Operator

  • Loading branch information...
1 parent 940dfe7 commit c37ddf12c65dec154c6ef76dba422f2b7decad40 Brian Gernhardt committed
Showing with 10 additions and 1 deletion.
  1. +4 −1 cish/src/cish/Actions.pm
  2. +6 −0 cish/src/cish/Grammar.pm
View
5 cish/src/cish/Actions.pm
@@ -38,7 +38,10 @@ method builtin:sym<print>($/) {
make $past;
}
-method term:sym<integer>($/) { make $<integer>.ast; }
+method term:sym<integer>($/) {
+ make PAST::Val.new( :value($<integer>.ast) );
+}
+
method term:sym<quote>($/) { make $<quote>.ast; }
method quote:sym<'>($/) { make $<quote_EXPR>.ast; }
View
6 cish/src/cish/Grammar.pm
@@ -53,6 +53,7 @@ INIT {
cish::Grammar.O(':prec<s>, :assoc<left>', '%comparison');
cish::Grammar.O(':prec<r>, :assoc<left>', '%and');
cish::Grammar.O(':prec<q>, :assoc<left>', '%or');
+ cish::Grammar.O(':prec<p>, :assoc<right>', '%ternary');
}
token circumfix:sym<( )> { '(' <.ws> <EXPR> ')' }
@@ -76,3 +77,8 @@ token infix:sym('>' ) { <sym> <O('%comparison, :pirop<isgt IPP>')> }
token infix:sym<&&> { <sym> <O('%and, :pirop<and PPP>')> }
token infix:sym<||> { <sym> <O('%or, :pirop<or PPP>')> }
+
+token infix:sym<? :> {
+ '?' <EXPR('p')> ':'
+ <O('%ternary, :pasttype<if>, :reducecheck<ternary>')>
+}

0 comments on commit c37ddf1

Please sign in to comment.
Something went wrong with that request. Please try again.