diff --git a/src/NQP/Actions.pm b/src/NQP/Actions.pm index e142d5c..29eb5a8 100644 --- a/src/NQP/Actions.pm +++ b/src/NQP/Actions.pm @@ -227,3 +227,15 @@ NQP::Grammar.O(':prec, :assoc', '%list_infix'); method nulltermish($/) { make $ ?? $.ast !! 0; } + +method postfix:sym<++>($/) { + make PAST::Op.new( :name('postfix:<++>'), + :inline(' clone %r, %0', ' inc %0'), + :pasttype('inline') ); +} + +method postfix:sym<-->($/) { + make PAST::Op.new( :name('postfix:<-->'), + :inline(' clone %r, %0', ' dec %0'), + :pasttype('inline') ); +} diff --git a/src/NQP/Grammar.pm b/src/NQP/Grammar.pm index a37bfc3..f771287 100644 --- a/src/NQP/Grammar.pm +++ b/src/NQP/Grammar.pm @@ -160,8 +160,10 @@ token postcircumfix:sym<[ ]> { } -token prefix:sym<--> { } -token postfix:sym<++> { } +token prefix:sym<++> { ')> } +token prefix:sym<--> { ')> } +token postfix:sym<++> { } # see Actions.pm +token postfix:sym<--> { } # see Actions.pm token infix:sym<**> { ')> } diff --git a/t/nqp/13-op.t b/t/nqp/13-op.t new file mode 100644 index 0000000..6dfacb6 --- /dev/null +++ b/t/nqp/13-op.t @@ -0,0 +1,48 @@ +#!./parrot nqp.pbc + +# checking basic operands and circumfix:( ) + +plan(29); + +##Additive operators +ok( 1+2 == 3, 'Checking addition 1+2'); +ok( 10-9 == 1, 'Checking subtraction 10-9'); +ok( 10-3+2 == 9, 'Checking compound statements 10-3+2'); +ok( 10-(3+2) == 5, 'Checking parenthesized statement 10-(3+2)'); + +##Multiplicative operators +ok( 6*7 == 42, 'Checking multiplication 6*7'); +ok( 36/6 == 6, 'Checking division 36/6'); +ok( 4*3+5 == 17, 'Checking compound statements 4*3+5'); +ok( 4*(3+5) == 32, 'Checking parenthesized statements 4*(3+5)'); +ok( 12/4*3 == 9, 'Checking compound statements 12/4*3'); +ok( 12/(4*3) == 1, 'Checking compound statements 12/(4*3)'); +ok( 5-3*2 == -1, 'Checking compound statements 5-3*2'); + +##Modulo operator +ok( 8%3 == 2, 'Checking modulo 8%3'); +ok( 8%3+2 == 4, 'Checking compound statement 8%3+2'); +ok( 8%(3+2) == 3, 'Checking compound statement 8%(3+2)'); + +##Concatenation operator +ok( 'a' ~ 'b' eq 'ab', 'Checking concatenation "a" ~ "b"'); +ok( 1 ~ 'b' eq '1b', 'Checking concatenation 1 ~ "b"'); +ok( 'a' ~ 2 eq 'a2', 'Checking concatenation "a" ~ 2 '); + +##Postfix operators +my $x := 0; +ok( $x++ == 0 ); +ok( $x == 1 ); +ok( $x-- == 1 ); +ok( $x == 0 ); + +##Relational operators +ok( ?(1 < 2) ); +ok( !(2 < 1) ); +ok( ?(2 <= 2) ); +ok( !(3 <= 2) ); +ok( ?(2 > 1) ); +ok( !(2 > 3) ); +ok( ?(2 >= 1) ); +ok( !(2 >= 3) ); +