about summary refs log blame commit diff stats
path: root/awk/forth/test.forth
blob: a1f4f507dd9d1dd2c2aa58e0b10b70b928df5bc6 (plain) (tree)











































                                          
( Basic arithmetic operations )
2 3 + . ( expect: 5 )
10 3 - . ( expect: 7 )
4 5 * . ( expect: 20 )
20 4 / . ( expect: 5 )
7 3 mod . ( expect: 1 )

( Stack manipulation operations )
5 dup . . ( expect: 5 5 )
1 2 swap . . ( expect: 2 1 )
1 2 over . . . ( expect: 1 2 1 )
1 2 3 rot . . . ( expect: 2 3 1 )
1 2 3 4 2 roll . . . . ( expect: 1 3 4 2 )
5 drop
1 2 nip . ( expect: 2 )
1 2 tuck . . . ( expect: 2 1 2 )

( Comparison operations )
5 3 > . ( expect: 1 )
3 5 < . ( expect: 1 )
4 4 = . ( expect: 1 )
5 3 < . ( expect: 0 )
3 5 > . ( expect: 0 )
4 5 = . ( expect: 0 )

( Math operations )
5 negate . ( expect: -5 )
-7 abs . ( expect: 7 )
5 2 max . ( expect: 5 )
5 2 min . ( expect: 2 )

( Complex stack manipulations )
1 2 3 4 5 \ Put 5 numbers on stack
3 pick . ( expect: 2 )
2 roll . ( expect: 4 )
. . . . ( expect: 5 3 1 )

( Error handling tests )
drop drop drop drop drop \ Clear stack
drop ( expect: Error: Stack underflow )
. ( expect: Error: Stack underflow )
5 0 / ( expect: Error: Division by zero )

bye