Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Conditional-structures/00-META.yaml
Normal file
3
Task/Conditional-structures/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Conditional_structures
|
||||
note: Control Structures
|
||||
14
Task/Conditional-structures/00-TASK.txt
Normal file
14
Task/Conditional-structures/00-TASK.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{{Control Structures}}
|
||||
[[Category:Simple]]
|
||||
|
||||
;Task:
|
||||
List the ''conditional structures'' offered by a programming language. See [[wp:Conditional_(computer_programming)|Wikipedia: conditionals]] for descriptions.
|
||||
|
||||
Common conditional structures include '''if-then-else''' and '''switch'''.
|
||||
|
||||
Less common are '''arithmetic if''', '''ternary operator''' and '''Hash-based conditionals'''.
|
||||
|
||||
'''''Arithmetic if''' allows tight control over computed gotos, which optimizers have a hard time to figure out.''
|
||||
|
||||
<br>
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
I x == 0
|
||||
foo()
|
||||
E I x == 1
|
||||
bar()
|
||||
E
|
||||
baz()
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
S x
|
||||
0
|
||||
foo()
|
||||
1
|
||||
bar()
|
||||
E
|
||||
baz()
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
* Unconditional Branch or No Branch:
|
||||
B label Unconditional
|
||||
BR Rx "
|
||||
NOP label No Operation
|
||||
NOPR Rx "
|
||||
* After Compare Instructions
|
||||
BH label Branch on High
|
||||
BHR Rx "
|
||||
BL label Branch on Low
|
||||
BLR Rx "
|
||||
BE label Branch on Equal
|
||||
BER Rx "
|
||||
BNH label Branch on Not High
|
||||
BNHR Rx "
|
||||
BNL label Branch on Not Low
|
||||
BNLR Rx "
|
||||
BNE label Branch on Not Equal
|
||||
BNER Rx "
|
||||
* After Arithmetic Instructions:
|
||||
BP label Branch on Plus
|
||||
BPR Rx "
|
||||
BM label Branch on Minus
|
||||
BMR Rx "
|
||||
BZ label Branch on Zero
|
||||
BZR Rx "
|
||||
BO label Branch on Overflow
|
||||
BOR Rx "
|
||||
BNP label Branch on Not Plus
|
||||
BNPR Rx "
|
||||
BNM label Branch on Not Minus
|
||||
BNMR Rx "
|
||||
BNZ label Branch on Not Zero
|
||||
BNZR Rx "
|
||||
BNO label Branch on No Overflow
|
||||
BNOR Rx "
|
||||
* After Test Under Mask Instructions:
|
||||
BO label Branch if Ones
|
||||
BOR Rx "
|
||||
BM label Branch if Mixed
|
||||
BMR Rx "
|
||||
BZ label Branch if Zero
|
||||
BZR Rx "
|
||||
BNO label Branch if Not Ones
|
||||
BNOR Rx "
|
||||
BNM label Branch if Not Mixed
|
||||
BNMR Rx "
|
||||
BNZ label Branch if Not Zero
|
||||
BNZR Rx "
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
expression:
|
||||
opcode,op1,rel,op2
|
||||
opcode,op1,rel,op2,OR,opcode,op1,rel,op2
|
||||
opcode,op1,rel,op2,AND,opcode,op1,rel,op2
|
||||
opcode::=C,CH,CR,CLC,CLI,CLCL, LTR, CP,CE,CD,...
|
||||
rel::=EQ,NE,LT,LE,GT,GE, (fortran style)
|
||||
E,L,H,NE,NL,NH (assembler style)
|
||||
P (plus), M (minus) ,Z (zero) ,O (overflow)
|
||||
opcode::=CLM,TM
|
||||
rel::=O (ones),M (mixed) ,Z (zeros)
|
||||
|
||||
* IF
|
||||
IF expression [THEN]
|
||||
...
|
||||
ELSEIF expression [THEN]
|
||||
...
|
||||
ELSE
|
||||
...
|
||||
ENDIF
|
||||
|
||||
IF C,R4,EQ,=F'10' THEN if r4=10 then
|
||||
MVI PG,C'A' pg='A'
|
||||
ELSEIF C,R4,EQ,=F'11' THEN elseif r4=11 then
|
||||
MVI PG,C'B' pg='B'
|
||||
ELSEIF C,R4,EQ,=F'12' THEN elseif r4=12 then
|
||||
MVI PG,C'C' pg='C'
|
||||
ELSE else
|
||||
MV PG,C'?' pg='?'
|
||||
ENDIF end if
|
||||
|
||||
* SELECT
|
||||
SELECT expressionpart1
|
||||
WHEN expressionpart2a
|
||||
...
|
||||
WHEN expressionpart2b
|
||||
...
|
||||
OTHRWISE
|
||||
...
|
||||
ENDSEL
|
||||
|
||||
* example SELECT type 1
|
||||
SELECT CLI,HEXAFLAG,EQ select hexaflag=
|
||||
WHEN X'20' when x'20'
|
||||
MVI PG,C'<' pg='<'
|
||||
WHEN X'21' when x'21'
|
||||
MVI PG,C'!' pg='!'
|
||||
WHEN X'22' when x'21'
|
||||
MVI PG,C'>' pg='>'
|
||||
OTHRWISE otherwise
|
||||
MVI PG,C'?' pg='?'
|
||||
ENDSEL end select
|
||||
|
||||
* example SELECT type 2
|
||||
SELECT select
|
||||
WHEN C,DELTA,LT,0 when delta<0
|
||||
MVC PG,=C'0 SOL' pg='0 SOL'
|
||||
WHEN C,DELTA,EQ,0 when delta=0
|
||||
MVC PG,=C'1 SOL'' pg='0 SOL'
|
||||
WHEN C,DELTA,GT,0 when delta>0
|
||||
MVC PG,=C'2 SOL'' pg='0 SOL'
|
||||
ENDSEL end select
|
||||
|
||||
* CASE
|
||||
CASENTRY R4 select case r4
|
||||
CASE 1 case 1
|
||||
LA R5,1 r5=1
|
||||
CASE 3 case 3
|
||||
LA R5,2 r5=2
|
||||
CASE 5 case 5
|
||||
LA R5,3 r5=1
|
||||
CASE 7 case 7
|
||||
LA R5,4 r5=4
|
||||
ENDCASE end select
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
LDA #10
|
||||
CMP #11
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
BNE ;Branch on Not Equal - branch when the zero flag is set
|
||||
BEQ ;Branch on EQual - branch when the zero flag is set.
|
||||
;The zero flag is set when the result of an operation is zero
|
||||
|
||||
BMI ;Branch on MInus
|
||||
BPL ;Branch on PLus - branch when the sign flag is cleared/set.
|
||||
;The sign flag is set when the result of an instruction is a negative number
|
||||
;and cleared when the result is a positive number
|
||||
|
||||
BVS ;Branch on oVerflow Set
|
||||
BVC ;Branch on oVerflow Cleared - branch when the overflow flag is cleared/set.
|
||||
;The overflow flag is set when the result of an addition/subtraction would
|
||||
;result in a number larger than 127 or smaller than -128
|
||||
|
||||
BCS ;Branch on Carry Set
|
||||
BCC ;Branch on Carry Clear - branch when the carry flag is cleared/set.
|
||||
;The carry flag is set when an addition produced a carry and when
|
||||
;a subtraction produced a borrow and cleared if an addition/subtraction
|
||||
;does not produce a carry/borrow. The carry flag also holds bits
|
||||
;after shifts and rotates.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
LDA #200
|
||||
CMP Variable
|
||||
BEQ #3 ;if equal, skip ahead 3 bytes...
|
||||
CLC ;if unequal, continue executing instructions
|
||||
ADC #1
|
||||
STA OtherVariable ; ...to here.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
LDX #100
|
||||
Loop: ...do something
|
||||
DEX
|
||||
BNE Loop
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
ReturnTable:
|
||||
dw foo-1 ;each is a label to a section of code that ends in an RTS
|
||||
dw bar-1
|
||||
dw baz-1
|
||||
|
||||
ReturnSpoof: ;assume execution arrived here via a JSR command.
|
||||
lda indexVariable ;contains the desired index into ReturnTable. 0 = foo, 1 = bar, 2 = baz.
|
||||
asl ;the data is word length so the index must be multiplied by 2.
|
||||
tax
|
||||
|
||||
lda ReturnTable+1,x ;get the high byte of the return address.
|
||||
pha
|
||||
lda ReturnTable,x ;get the low byte
|
||||
pha
|
||||
|
||||
; Now, the desired subroutine's address minus 1 is on top of the stack.
|
||||
; The RTS command will take this address and jump there. That routine's RTS command will act as the RTS from "ReturnSpoof",
|
||||
; bringing execution to the point just after ReturnSpoof was called.
|
||||
; If done properly, return spoofing will not corrupt the stack.
|
||||
|
||||
RTS ;this "RTS" acts as a JMP to the address we just put on the stack.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
MOVE.L #$FFFFFF00,D0
|
||||
CMP.B #0,D0 ;equals zero, so zero flag is set.
|
||||
CMP.W #0,D0 ;doesn't equals zero, so zero flag is clear.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
BTST #7,D0 ;test bit 7 of D0, i.e. the leftmost bit in the rightmost byte.
|
||||
BNE goHere ;if that bit is 1, branch to "goHere"
|
||||
BEQ goThere ;if that bit is 0, branch to "goThere"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
CMP.L #3,D0 ;this works with any size operands, not just L.
|
||||
BNE doNothing
|
||||
ADD.L #7,D0
|
||||
doNothing:
|
||||
;rest of program
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
SwitchCase:
|
||||
DC.L foo,bar,baz,default ;case 0, case 1, case 2, case 3. (Case 0,1,2 are the "valid" cases.)
|
||||
; D0 is the case selector variable (byte-sized)
|
||||
doSwitchCase: ;this is a subroutine that gets called elsewhere.
|
||||
LEA SwitchCase,A0
|
||||
|
||||
;this is our bounds check
|
||||
CMP.B #3,D0 ;is D0 > 3?
|
||||
BLS InBounds ;if not, keep going
|
||||
MOVE.B #3,D0 ;if it is, set it to 3.
|
||||
|
||||
|
||||
InBounds:
|
||||
LSL.W #2,D0 ;multiply by 4 to index into a table of longs
|
||||
MOVE.L (A0,D0),A0 ;deref the pointer and store the desired routine in A0
|
||||
MOVE.L A0,-(SP) ;push it onto the stack
|
||||
RTS ;"return" to the selected routine. If it ends in an RTS,
|
||||
; that RTS will return to just after "JSR doSwitchCase"
|
||||
|
||||
|
||||
foo:
|
||||
;your code for this case goes here.
|
||||
rts
|
||||
|
||||
bar:
|
||||
;your code for this case goes here.
|
||||
rts
|
||||
|
||||
baz:
|
||||
;your code for this case goes here.
|
||||
rts
|
||||
|
||||
default:
|
||||
rts
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program condstr64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
/*******************************************/
|
||||
/* Initialized data */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessTest1: .asciz "The test 1 is equal.\n"
|
||||
szMessTest1N: .asciz "The test 1 is not equal.\n"
|
||||
szMessTest1A: .asciz "The test 1A is equal.\n"
|
||||
szMessTest1AN: .asciz "The test 1A is not equal.\n"
|
||||
szMessTest2: .asciz "The test 2 is equal.\n"
|
||||
szMessTest2N: .asciz "The test 2 is not equal.\n"
|
||||
szMessTest3: .asciz "The test 3 is <.\n"
|
||||
szMessTest3N: .asciz "The test 3 is >.\n"
|
||||
szMessTest4: .asciz "The test 4 is <=.\n"
|
||||
szMessTest4N: .asciz "The test 4 is >.\n"
|
||||
szMessTest5: .asciz "The test 5 is negative.\n"
|
||||
szMessTest5N: .asciz "The test 5 is positive ou equal 0.\n"
|
||||
szMessTest6: .asciz "Test 6 : carry is off.\n"
|
||||
szMessTest6N: .asciz "Test 6 : carry is set.\n"
|
||||
szMessTest7: .asciz "Test 7 : no overflow.\n"
|
||||
szMessTest7N: .asciz "Test 7 : overflow.\n"
|
||||
szMessTest8: .asciz "Test 8 : then.\n"
|
||||
szMessTest8N: .asciz "Test 8 : else.\n"
|
||||
szMessResult: .asciz "Test result = @ \n"
|
||||
/*******************************************/
|
||||
/* UnInitialized data */
|
||||
/*******************************************/
|
||||
.bss
|
||||
sZoneConv: .skip 30
|
||||
/*******************************************/
|
||||
/* code section */
|
||||
/*******************************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
|
||||
// classic test equal zero, not equal zero
|
||||
//mov x1,0 // comments
|
||||
mov x1,1 // or uncomments
|
||||
cmp x1,0 // structure if else
|
||||
bne 1f
|
||||
ldr x0,qAdrszMessTest1 // if equal
|
||||
b 2f
|
||||
1:
|
||||
ldr x0,qAdrszMessTest1N // else
|
||||
2:
|
||||
bl affichageMess
|
||||
|
||||
mov x1,0 // comments
|
||||
//mov x1,1 // or uncomments
|
||||
cbnz x1,3f // other test and branch if not zero
|
||||
ldr x0,qAdrszMessTest1A
|
||||
b 4f
|
||||
3:
|
||||
ldr x0,qAdrszMessTest1AN
|
||||
4:
|
||||
bl affichageMess
|
||||
// test equal 5, not equal 5
|
||||
//mov x1,#5
|
||||
mov x1,10
|
||||
cmp x1,5
|
||||
bne 5f
|
||||
ldr x0,qAdrszMessTest2
|
||||
b 6f
|
||||
5:
|
||||
ldr x0,qAdrszMessTest2N
|
||||
6:
|
||||
bl affichageMess
|
||||
|
||||
// test < 5, > 5 SIGNED
|
||||
mov x1,#-10
|
||||
//mov x1,#10
|
||||
cmp x1,#5
|
||||
bgt 7f
|
||||
ldr x0,qAdrszMessTest3
|
||||
b 8f
|
||||
7:
|
||||
ldr x0,qAdrszMessTest3N
|
||||
8:
|
||||
bl affichageMess
|
||||
|
||||
// test < 5, > 5 UNSIGNED
|
||||
//mov x1,#-10
|
||||
mov x1,#2
|
||||
cmp x1,#5
|
||||
bhi 9f
|
||||
ldr x0,qAdrszMessTest4
|
||||
b 10f
|
||||
9:
|
||||
ldr x0,qAdrszMessTest4N
|
||||
10:
|
||||
bl affichageMess
|
||||
|
||||
// test < 0, > 0
|
||||
mov x1,2
|
||||
subs x1,x1,5 // s --> flags
|
||||
bpl 11f
|
||||
ldr x0,qAdrszMessTest5
|
||||
b 12f
|
||||
11:
|
||||
ldr x0,qAdrszMessTest5N
|
||||
12:
|
||||
bl affichageMess
|
||||
|
||||
// carry off carry on
|
||||
//mov x1,#-10 // for carry set
|
||||
//mov x1,#10 // for carry off
|
||||
mov x1,(2<<62) - 1 // for carry off
|
||||
adds x1,x1,20 // s --> flags
|
||||
bcs 13f
|
||||
ldr x0,qAdrszMessTest6 // carry clear
|
||||
b 14f
|
||||
13:
|
||||
ldr x0,qAdrszMessTest6N // carry set
|
||||
14:
|
||||
bl affichageMess
|
||||
|
||||
// overflow off overflow on
|
||||
//mov x1,#-10 // for not overflow
|
||||
//mov x1,#10 // for not overflow
|
||||
mov x1,(2<<62) - 1 // for overflow
|
||||
adds x1,x1,20 // s --> flags
|
||||
bvs 15f
|
||||
ldr x0,qAdrszMessTest7 // overflow off
|
||||
b 16f
|
||||
15:
|
||||
ldr x0,qAdrszMessTest7N // overflow on
|
||||
16:
|
||||
bl affichageMess
|
||||
|
||||
// other conditionnel test csel
|
||||
mov x2,-20
|
||||
mov x3,25
|
||||
mov x1,10 // for equal
|
||||
//mov x1,#20 // for else
|
||||
cmp x1,10
|
||||
csel x0,x2,x3,eq // if x1=10 x0 = x2 else x0 = x3
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10S
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess
|
||||
|
||||
// other conditionnel test cset
|
||||
//mov x1,10 // for equal
|
||||
mov x1,20 // for else
|
||||
cmp x1,10
|
||||
cset x0,eq // if x1=10 x0 = 1 else x0 = 0
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10S
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess
|
||||
|
||||
// other conditionnel test cinc
|
||||
mov x0,3
|
||||
mov x1,10 // for equal
|
||||
//mov x1,20 // for else
|
||||
cmp x1,10
|
||||
cinc x0,x0,eq // if x1=10 x0 = x0+1 else x0 = x0
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10S
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess
|
||||
|
||||
// other conditionnel test csinc
|
||||
mov x0,3
|
||||
mov x2,6
|
||||
mov x3,11
|
||||
mov x1,10 // for equal
|
||||
//mov x1,20 // for else
|
||||
cmp x1,10
|
||||
csinc x0,x2,x3,ne // if x1<>10 x0 = x2 else x0 = x3 + 1
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10S
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess
|
||||
100: // standard end of the program
|
||||
mov x0,0 // return code
|
||||
mov x8,EXIT // request to exit program
|
||||
svc 0 // perform the system call
|
||||
qAdrszMessTest1: .quad szMessTest1
|
||||
qAdrszMessTest1N: .quad szMessTest1N
|
||||
qAdrszMessTest1A: .quad szMessTest1A
|
||||
qAdrszMessTest1AN: .quad szMessTest1AN
|
||||
qAdrszMessTest2: .quad szMessTest2
|
||||
qAdrszMessTest2N: .quad szMessTest2N
|
||||
qAdrszMessTest3: .quad szMessTest3
|
||||
qAdrszMessTest3N: .quad szMessTest3N
|
||||
qAdrszMessTest4: .quad szMessTest4
|
||||
qAdrszMessTest4N: .quad szMessTest4N
|
||||
qAdrszMessTest5: .quad szMessTest5
|
||||
qAdrszMessTest5N: .quad szMessTest5N
|
||||
qAdrszMessTest6: .quad szMessTest6
|
||||
qAdrszMessTest6N: .quad szMessTest6N
|
||||
qAdrszMessTest7: .quad szMessTest7
|
||||
qAdrszMessTest7N: .quad szMessTest7N
|
||||
qAdrszMessTest8: .quad szMessTest8
|
||||
qAdrszMessTest8N: .quad szMessTest8N
|
||||
qAdrszMessResult: .quad szMessResult
|
||||
qAdrsZoneConv: .quad sZoneConv
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
'IF' I=1 'THEN' OUTINTEGER(1,I);
|
||||
|
||||
'IF' I<J 'THEN' OUTSTRING(1,'(' : I<J')')
|
||||
'ELSE' OUTSTRING(1,'(' : I>=J')');
|
||||
|
||||
'IF' I>=J 'THEN' 'BEGIN'
|
||||
OUTSTRING(1,'(' I=')');
|
||||
OUTINTEGER(1,I)
|
||||
'END'
|
||||
'ELSE' 'BEGIN'
|
||||
OUTSTRING(1,'(' J=')');
|
||||
OUTINTEGER(1,J)
|
||||
'END'
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
'SWITCH' TARGET:=L1,L2,L3;
|
||||
...
|
||||
'GOTO' TARGET(/J/);
|
||||
L1: OUTSTRING(1,'('AA')');
|
||||
L2: OUTSTRING(1,'('BB')');
|
||||
L3: OUTSTRING(1,'('CC')');
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
begin
|
||||
integer a, b, c;
|
||||
|
||||
a := 1; b := 2; c := 3;
|
||||
|
||||
% algol W has the traditional Algol if-the-else statement %
|
||||
% there is no "elseif" contraction %
|
||||
if a = b
|
||||
then write( "a = b" )
|
||||
else if a = c
|
||||
then write( "a = c" )
|
||||
else write( "a is ", a );
|
||||
|
||||
% if-then-else can also be used in an expression %
|
||||
write( if a < 4 then "lt 4" else "ge 4" );
|
||||
|
||||
% algol W also has a "case" statement, an integer expression is used to %
|
||||
% select the statement to execute. If the expression evaluates to 1, %
|
||||
% the first statement is executed, if 2, the second is executed etc. %
|
||||
% If the expression is less than 1 or greater than the number of %
|
||||
% statements, a run time error occurs %
|
||||
case a + b of
|
||||
begin write( "a + b is one" )
|
||||
; write( "a + b is two" )
|
||||
; write( "a + b is three" )
|
||||
; write( "a + b is four" )
|
||||
end;
|
||||
|
||||
% there is also an expression form of the case: %
|
||||
write( case c - a of ( "one", "two", "three", "four" ) )
|
||||
|
||||
end.
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program condstr.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
/* Initialized data */
|
||||
.data
|
||||
szMessTest1: .asciz "The test 1 is equal.\n"
|
||||
szMessTest1N: .asciz "The test 1 is not equal.\n"
|
||||
szMessTest2: .asciz "The test 2 is equal.\n"
|
||||
szMessTest2N: .asciz "The test 2 is not equal.\n"
|
||||
szMessTest3: .asciz "The test 3 is <.\n"
|
||||
szMessTest3N: .asciz "The test 3 is >.\n"
|
||||
szMessTest4: .asciz "The test 4 is <=.\n"
|
||||
szMessTest4N: .asciz "The test 4 is >.\n"
|
||||
szMessTest5: .asciz "The test 5 is negative.\n"
|
||||
szMessTest5N: .asciz "The test 5 is positive ou equal 0.\n"
|
||||
szMessTest6: .asciz "Test 6 : carry is off.\n"
|
||||
szMessTest6N: .asciz "Test 6 : carry is set.\n"
|
||||
szMessTest7: .asciz "Test 7 : no overflow.\n"
|
||||
szMessTest7N: .asciz "Test 7 : overflow.\n"
|
||||
szMessTest8: .asciz "Test 8 : then.\n"
|
||||
szMessTest8N: .asciz "Test 8 : else.\n"
|
||||
|
||||
/* UnInitialized data */
|
||||
.bss
|
||||
|
||||
/* code section */
|
||||
.text
|
||||
.global main
|
||||
main: /* entry of program */
|
||||
push {fp,lr} /* saves 2 registers */
|
||||
|
||||
@ test equal zero, not equal zero
|
||||
@movs r1,#0 @ comments
|
||||
movs r1,#1 @ @ s --> flags and uncomments
|
||||
ldreq r0,iAdrszMessTest1
|
||||
ldrne r0,iAdrszMessTest1N
|
||||
bl affichageMess
|
||||
|
||||
@ test equal 5, not equal 5
|
||||
@mov r1,#5
|
||||
mov r1,#10
|
||||
cmp r1,#5
|
||||
ldreq r0,iAdrszMessTest2
|
||||
ldrne r0,iAdrszMessTest2N
|
||||
bl affichageMess
|
||||
|
||||
@ test < 5, > 5 SIGNED
|
||||
mov r1,#-10
|
||||
@mov r1,#10
|
||||
cmp r1,#5
|
||||
ldrlt r0,iAdrszMessTest3
|
||||
ldrgt r0,iAdrszMessTest3N
|
||||
bl affichageMess
|
||||
|
||||
@ test < 5, > 5 UNSIGNED
|
||||
@mov r1,#-10
|
||||
mov r1,#2
|
||||
cmp r1,#5
|
||||
ldrls r0,iAdrszMessTest4
|
||||
ldrhi r0,iAdrszMessTest4N
|
||||
bl affichageMess
|
||||
|
||||
@ test < 0, > 0
|
||||
@movs r1,#-10
|
||||
movs r1,#2 @ s --> flags
|
||||
ldrmi r0,iAdrszMessTest5
|
||||
ldrpl r0,iAdrszMessTest5N
|
||||
bl affichageMess
|
||||
|
||||
@ carry off carry on
|
||||
@mov r1,#-10 @ for carry set
|
||||
@mov r1,#10 @ for carry off
|
||||
mov r1,#(2<<30) - 1 @ for carry off
|
||||
adds r1,#20 @ s --> flags
|
||||
ldrcc r0,iAdrszMessTest6 @ carry clear
|
||||
ldrcs r0,iAdrszMessTest6N @ carry set
|
||||
bl affichageMess
|
||||
|
||||
@ overflow off overflow on
|
||||
@mov r1,#-10 @ for not overflow
|
||||
@mov r1,#10 @ for not overflow
|
||||
mov r1,#(2<<30) - 1 @ for overflow
|
||||
adds r1,#20 @ s --> flags
|
||||
ldrvc r0,iAdrszMessTest7 @ overflow off
|
||||
ldrvs r0,iAdrszMessTest7N @ overflow on
|
||||
bl affichageMess
|
||||
|
||||
@ other if then else
|
||||
mov r1,#5 @ for then
|
||||
@mov r1,#20 @ for else
|
||||
cmp r1,#10
|
||||
ble 1f @ less or equal
|
||||
@bge 1f @ greather or equal
|
||||
@else
|
||||
ldr r0,iAdrszMessTest8N @ overflow off
|
||||
bl affichageMess
|
||||
b 2f
|
||||
1: @ then
|
||||
ldr r0,iAdrszMessTest8 @ overflow off
|
||||
bl affichageMess
|
||||
2:
|
||||
|
||||
100: /* standard end of the program */
|
||||
mov r0, #0 @ return code
|
||||
pop {fp,lr} @restaur 2 registers
|
||||
mov r7, #EXIT @ request to exit program
|
||||
swi 0 @ perform the system call
|
||||
iAdrszMessTest1: .int szMessTest1
|
||||
iAdrszMessTest1N: .int szMessTest1N
|
||||
iAdrszMessTest2: .int szMessTest2
|
||||
iAdrszMessTest2N: .int szMessTest2N
|
||||
iAdrszMessTest3: .int szMessTest3
|
||||
iAdrszMessTest3N: .int szMessTest3N
|
||||
iAdrszMessTest4: .int szMessTest4
|
||||
iAdrszMessTest4N: .int szMessTest4N
|
||||
iAdrszMessTest5: .int szMessTest5
|
||||
iAdrszMessTest5N: .int szMessTest5N
|
||||
iAdrszMessTest6: .int szMessTest6
|
||||
iAdrszMessTest6N: .int szMessTest6N
|
||||
iAdrszMessTest7: .int szMessTest7
|
||||
iAdrszMessTest7N: .int szMessTest7N
|
||||
iAdrszMessTest8: .int szMessTest8
|
||||
iAdrszMessTest8N: .int szMessTest8N
|
||||
/******************************************************************/
|
||||
/* display text with size calculation */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the message */
|
||||
affichageMess:
|
||||
push {fp,lr} /* save registres */
|
||||
push {r0,r1,r2,r7} /* save others registers */
|
||||
mov r2,#0 /* counter length */
|
||||
1: /* loop length calculation */
|
||||
ldrb r1,[r0,r2] /* read octet start position + index */
|
||||
cmp r1,#0 /* if 0 its over */
|
||||
addne r2,r2,#1 /* else add 1 in the length */
|
||||
bne 1b /* and loop */
|
||||
/* so here r2 contains the length of the message */
|
||||
mov r1,r0 /* address message in r1 */
|
||||
mov r0,#STDOUT /* code to write to the standard output Linux */
|
||||
mov r7, #WRITE /* code call system "write" */
|
||||
swi #0 /* call systeme */
|
||||
pop {r0,r1,r2,r7} /* restaur others registers */
|
||||
pop {fp,lr} /* restaur des 2 registres */
|
||||
bx lr /* return */
|
||||
|
|
@ -0,0 +1 @@
|
|||
if(i<0) i=0; else i=42
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if(i<0) {
|
||||
i=0; j=1
|
||||
} else {
|
||||
i=42; j=2
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
i=(i<0? 0: 42)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
PROC Main()
|
||||
INT i
|
||||
|
||||
FOR i=-1 TO 1
|
||||
DO
|
||||
IF i<0 THEN
|
||||
PrintF("%I is less than zero%E",i)
|
||||
ELSEIF i>0 THEN
|
||||
PrintF("%I is greater than zero%E",i)
|
||||
ELSE
|
||||
PrintF("%I is zero%E",i)
|
||||
FI
|
||||
OD
|
||||
RETURN
|
||||
10
Task/Conditional-structures/Ada/conditional-structures-1.ada
Normal file
10
Task/Conditional-structures/Ada/conditional-structures-1.ada
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
type Restricted is range 1..10;
|
||||
My_Var : Restricted;
|
||||
|
||||
if My_Var = 5 then
|
||||
-- do something
|
||||
elsif My_Var > 5 then
|
||||
-- do something
|
||||
else
|
||||
-- do something
|
||||
end if;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
case Today is
|
||||
when Saturday | Sunday =>
|
||||
null; -- don't do anything, if Today is Saturday or Sunday
|
||||
when Monday =>
|
||||
Compute_Starting_Balance;
|
||||
when Friday =>
|
||||
Compute_Ending_Balance;
|
||||
when Tuesday .. Thursday =>
|
||||
Accumulate_Sales;
|
||||
end case;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
select
|
||||
accept first_entry;
|
||||
-- do something
|
||||
or accept second_entry;
|
||||
-- do something
|
||||
or terminate;
|
||||
end select;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
select
|
||||
My_Task.Start;
|
||||
or
|
||||
delay Timeout_Period;
|
||||
end select;
|
||||
13
Task/Conditional-structures/Ada/conditional-structures-2.ada
Normal file
13
Task/Conditional-structures/Ada/conditional-structures-2.ada
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type Operation is (Add, Subtract, Multiply, Divide);
|
||||
Op : Operation;
|
||||
Result : Integer;
|
||||
-- we assume that A and B are inputs.
|
||||
Result := (if Op = Add then
|
||||
A + B
|
||||
elsif Op = Subtract then
|
||||
A - B
|
||||
elsif Op = Multiply then
|
||||
A * B
|
||||
elsif Op = Divide then
|
||||
A / B
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
Operation
|
||||
|
|
@ -0,0 +1 @@
|
|||
Op
|
||||
|
|
@ -0,0 +1 @@
|
|||
Result
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Result := (case Op is
|
||||
Add => A + B,
|
||||
Subtract => A - B,
|
||||
Multiply => A * B,
|
||||
Divide => A / B
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
case Op of...
|
||||
13
Task/Conditional-structures/Ada/conditional-structures-8.ada
Normal file
13
Task/Conditional-structures/Ada/conditional-structures-8.ada
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
|
||||
Today : Days;
|
||||
|
||||
case Today is
|
||||
when Saturday | Sunday =>
|
||||
null;
|
||||
when Monday =>
|
||||
Compute_Starting_Balance;
|
||||
when Friday =>
|
||||
Compute_Ending_Balance;
|
||||
when others =>
|
||||
Accumulate_Sales;
|
||||
end case;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
case Today is
|
||||
when Monday =>
|
||||
Compute_Starting_Balance;
|
||||
when Friday =>
|
||||
Compute_Ending_Balance;
|
||||
when Tuesday .. Thursday =>
|
||||
Accumulate_Sales;
|
||||
-- ignore Saturday and Sunday
|
||||
end case;
|
||||
|
|
@ -0,0 +1 @@
|
|||
var x = loggedin ? sessionid : -1
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if (value > 40) {
|
||||
println ("OK")
|
||||
} elif (value < 20) {
|
||||
println ("FAILED")
|
||||
} else {
|
||||
println ("RETRY")
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
switch (arg) {
|
||||
case "-d":
|
||||
case "--debug":
|
||||
debug = true
|
||||
break
|
||||
case "-f":
|
||||
force = true
|
||||
break
|
||||
default:
|
||||
throw "Unknown option " + arg
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case > 40:
|
||||
println ("OK")
|
||||
break
|
||||
case < 20:
|
||||
println ("FAILED")
|
||||
break
|
||||
case in 50..59:
|
||||
println ("WIERD")
|
||||
// fall through
|
||||
default:
|
||||
println ("RETRY")
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
if (c1) {
|
||||
// first condition is true...
|
||||
} elif (c2) {
|
||||
// second condition is true...
|
||||
} elif (c3) {
|
||||
// third condition is true...
|
||||
} else {
|
||||
// none was true...
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if: condition then: {
|
||||
// condition is true...
|
||||
} else: {
|
||||
// condition is false...
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
condition.ifTrue: { /* condition is true... */ } ifFalse: { /* condition is false... */ }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
IF condition
|
||||
-> if condition is true...
|
||||
ELSEIF condition2
|
||||
-> else if condition2 is true...
|
||||
ELSE
|
||||
-> if all other conditions are not true...
|
||||
ENDIF
|
||||
|
|
@ -0,0 +1 @@
|
|||
IF condition THEN statement
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
DEF c
|
||||
c := IF condition THEN 78 ELSE 19
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
SELECT var
|
||||
CASE n1
|
||||
-> code
|
||||
CASE n2
|
||||
-> code
|
||||
DEFAULT
|
||||
-> no one of the previous case...
|
||||
ENDSELECT
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
SELECT max_possible_value OF var
|
||||
CASE n1
|
||||
-> code
|
||||
CASE n2 TO n3, n4
|
||||
-> more
|
||||
CASE n5 TO n6, n7 TO n8
|
||||
-> more...
|
||||
DEFAULT
|
||||
-> none of previous ones
|
||||
ENDSELECT
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if (s == 'Hello World') {
|
||||
foo();
|
||||
} else if (s == 'Bye World') {
|
||||
bar();
|
||||
} else {
|
||||
deusEx();
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
if(obj != null && obj.foo()){
|
||||
aMethod();
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
if(obj != null & obj.foo()){
|
||||
aMethod();
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
s == 'Hello World' ? foo() : bar();
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
if myVar is "ok" then return true
|
||||
|
||||
set i to 0
|
||||
if i is 0 then
|
||||
return "zero"
|
||||
else if i mod 2 is 0 then
|
||||
return "even"
|
||||
else
|
||||
return "odd"
|
||||
end if
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
10 LET X = 1
|
||||
20 IF X THEN PRINT "X IS TRUE"
|
||||
30 IF NOT X THEN PRINT "X IS FALSE"
|
||||
40 ON X GOSUB 100,200,300
|
||||
50 ON X GOTO 300,200,100
|
||||
100 PRINT "APPLE": RETURN
|
||||
200 PRINT "BANANA": RETURN
|
||||
300 PRINT "CHERRY"
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
num: 2
|
||||
|
||||
if? num=2 [
|
||||
print "yep, num is 2"
|
||||
]
|
||||
else [
|
||||
print "something went wrong..."
|
||||
]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
loop 1..5 'num [
|
||||
case [num]
|
||||
when? [<2] -> print [num ": it's less than 2"]
|
||||
when? [=2] -> print [num ": it's 2!"]
|
||||
when? [=3] -> print [num ": it's 3!"]
|
||||
else -> print [num ": the number is too big"]
|
||||
]
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
if x == 0:
|
||||
foo()
|
||||
elif x == 1:
|
||||
bar()
|
||||
elif x == 2:
|
||||
baz()
|
||||
else:
|
||||
qux()
|
||||
|
||||
match x:
|
||||
0 => foo()
|
||||
1 => bar()
|
||||
2 => baz()
|
||||
_ => qux()
|
||||
|
||||
(a) ? b : c
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
x = 1
|
||||
If x
|
||||
MsgBox, x is %x%
|
||||
Else If x > 1
|
||||
MsgBox, x is %x%
|
||||
Else
|
||||
MsgBox, x is %x%
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
x = 2
|
||||
y = 1
|
||||
var := x > y ? 2 : 3
|
||||
MsgBox, % var
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
While (A_Index < 3) {
|
||||
MsgBox, %A_Index% is less than 3
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
If <expression> Then
|
||||
statements
|
||||
...
|
||||
[ElseIf expression-n Then
|
||||
[elseif statements ... ]]
|
||||
...
|
||||
[Else
|
||||
[else statements]
|
||||
...
|
||||
EndIf
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
Select
|
||||
Case <expression>
|
||||
statement1
|
||||
...
|
||||
[Case
|
||||
statement2
|
||||
...]
|
||||
[Case Else
|
||||
statementN
|
||||
...]
|
||||
EndSelect
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
Switch <expression>
|
||||
Case <value> [To <value>] [,<value> [To <value>] ...]
|
||||
statement1
|
||||
...
|
||||
[Case <value> [To <value>] [,<value> [To <value>] ...]
|
||||
statement2
|
||||
...]
|
||||
[Case Else
|
||||
statementN
|
||||
...]
|
||||
EndSwitch
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
If year = 1999 then [Print: "Party!";];
|
||||
|
||||
If someNumber > 5 then [Print: "Too high!";] else [Print: "Adequate amount.";];
|
||||
|
||||
If breed = "Abyssinian" then [score := 150;]
|
||||
else if breed = "Birman" then [score := 70;]
|
||||
else [score := 45;];
|
||||
|
||||
Unless char = ¢X then [Print: "character was not an x";];
|
||||
|
|
@ -0,0 +1 @@
|
|||
Print: if result = 13 then ["unlucky"] else ["safe"];
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
If 1
|
||||
YEP()
|
||||
End
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
!If 1
|
||||
NOPE()
|
||||
End
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
If 1
|
||||
YEP()
|
||||
Else
|
||||
NOPE()
|
||||
End
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
If 1=0
|
||||
NOPE()
|
||||
ElseIf 1=1
|
||||
YEP()
|
||||
Else
|
||||
NOPE()
|
||||
End
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
If 1=0
|
||||
NOPE()
|
||||
Else!If 1=2
|
||||
YEP()
|
||||
Else
|
||||
NOPE()
|
||||
End
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
10 LET A%=1: REM A HAS A VALUE OF TRUE
|
||||
20 IF A% THEN PRINT "A IS TRUE"
|
||||
30 WE CAN OF COURSE USE EXPRESSIONS
|
||||
40 IF A%<>0 THEN PRINT "A IS TRUE"
|
||||
50 IF NOT(A%) THEN PRINT "A IS FALSE"
|
||||
60 REM SOME VERSIONS OF BASIC PROVIDE AN ELSE KEYWORD
|
||||
70 IF A% THEN PRINT "A IS TRUE" ELSE PRINT "A IS FALSE"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
IF x = 0 THEN doSomething
|
||||
IF x < 0 THEN doSomething ELSE doOtherThing
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
IF x > 0 AND x < 10 THEN
|
||||
'do stuff
|
||||
ELSE IF x = 0 THEN
|
||||
'do other stuff
|
||||
ELSE
|
||||
'do more stuff
|
||||
END IF
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
IF aNumber THEN
|
||||
'the number is not 0
|
||||
ELSE
|
||||
'the number is 0
|
||||
END IF
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
SELECT CASE expression
|
||||
CASE 1
|
||||
'do stuff
|
||||
CASE 2, 3
|
||||
'do other stuff
|
||||
CASE 3.1 TO 9.9
|
||||
'do this
|
||||
CASE IS >= 10
|
||||
'do that
|
||||
CASE ELSE
|
||||
'default case
|
||||
END SELECT
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
10 INPUT "Enter 1,2 or 3: ";v
|
||||
20 GOTO v * 100
|
||||
99 STOP
|
||||
100 PRINT "Apple"
|
||||
110 STOP
|
||||
200 PRINT "Banana"
|
||||
210 STOP
|
||||
300 PRINT "Cherry"
|
||||
310 STOP
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
10 REM while loop
|
||||
20 L=0
|
||||
30 WHILE L<5
|
||||
40 PRINT L
|
||||
50 L=L+1
|
||||
60 WEND
|
||||
70 REM repeat loop
|
||||
80 L=1
|
||||
90 REPEAT
|
||||
100 PRINT L
|
||||
110 L=L+1
|
||||
120 UNTIL L>5
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
for i = 0 to 1
|
||||
for j = 0 to 1
|
||||
print i
|
||||
print j
|
||||
if (i) then
|
||||
if (j) then
|
||||
print "i is true j is true"
|
||||
else
|
||||
print "i is true j is false"
|
||||
end if
|
||||
else
|
||||
if (j) then
|
||||
print "i is false j is true"
|
||||
else
|
||||
print "i is false j is false"
|
||||
end if
|
||||
end if
|
||||
next j
|
||||
next i
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
REM Single-line IF ... THEN ... ELSE (ELSE clause is optional):
|
||||
IF condition% THEN statements ELSE statements
|
||||
|
||||
REM Multi-line IF ... ENDIF (ELSE clause is optional):
|
||||
IF condition% THEN
|
||||
statements
|
||||
ELSE
|
||||
statements
|
||||
ENDIF
|
||||
|
||||
REM CASE ... ENDCASE (OTHERWISE clause is optional):
|
||||
CASE expression OF
|
||||
WHEN value1: statements
|
||||
WHEN value2: statements
|
||||
...
|
||||
OTHERWISE: statements
|
||||
ENDCASE
|
||||
|
||||
REM ON ... GOTO (ELSE clause is optional):
|
||||
ON expression% GOTO dest1, dest2 ... ELSE statements
|
||||
|
||||
REM ON ...GOSUB (ELSE clause is optional):
|
||||
ON expression% GOSUB dest1, dest2 ... ELSE statements
|
||||
|
||||
REM ON ... PROC (ELSE clause is optional):
|
||||
ON expression% PROCone, PROCtwo ... ELSE statements
|
||||
11
Task/Conditional-structures/BQN/conditional-structures-1.bqn
Normal file
11
Task/Conditional-structures/BQN/conditional-structures-1.bqn
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
If ← {𝕏⍟𝕎@}´ # Also Repeat
|
||||
IfElse ← {c‿T‿F: c◶F‿T@}
|
||||
While ← {𝕩{𝔽⍟𝔾∘𝔽_𝕣_𝔾∘𝔽⍟𝔾𝕩}𝕨@}´ # While 1‿{... to run forever
|
||||
DoWhile ← {𝕏@ ⋄ While 𝕨‿𝕩}´
|
||||
For ← {I‿C‿P‿A: I@ ⋄ While⟨C,P∘A⟩}
|
||||
|
||||
# Switch/case statements have many variations; these are a few
|
||||
Match ← {𝕏𝕨}´
|
||||
Select ← {(⊑𝕩)◶(1↓𝕩)@}
|
||||
Switch ← {c←⊑𝕩 ⋄ m‿a←<˘⍉∘‿2⥊1↓𝕩 ⋄ (⊑a⊐C)◶m@}
|
||||
Test ← {fn←{C‿A𝕊e:C◶A‿E}´𝕩⋄Fn@}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
a<b ? a+↩1 ; # If
|
||||
a<c ? c-↩1 ; # Else If
|
||||
a-↩2 # Else
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
"foo" "bar" 3 4 > sel <<
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{3 4 >}
|
||||
{"foo"}
|
||||
{"bar"}
|
||||
ifte
|
||||
<<
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
({3 4 >} {"Three is greater than four" }
|
||||
{3 3 >} {"Three is greater than three"}
|
||||
{3 2 >} {"Three is greater than two" }
|
||||
{3 1 >} {"Three is greater than one" })
|
||||
cond
|
||||
<<
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
IF [NOT] ERRORLEVEL number command
|
||||
IF [NOT] string1==string2 command
|
||||
IF [NOT] EXIST filename command
|
||||
IF CMDEXTVERSION number command
|
||||
IF DEFINED variable command
|
||||
IF [/I] string1 compare-op string2 command
|
||||
where compare-op is:
|
||||
EQU - equal
|
||||
NEQ - not equal
|
||||
LSS - less than
|
||||
LEQ - less than or equal
|
||||
GTR - greater than
|
||||
GEQ - greater than or equal
|
||||
/I case insensitive string compares
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
IF EXIST %filename% (
|
||||
del %filename%
|
||||
) ELSE (
|
||||
echo %filename% not found
|
||||
)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
' lstack top value == 0 ? skip next instruction : don’t skip next instruction.
|
||||
" lstack top value > 0 ? skip next instruction : don’t skip next instruction.
|
||||
K lstack top value == 2nd value ? skip next instruction : don’t skip next instruction.
|
||||
L lstack top value > 2nd value ? skip next instruction : don’t skip next instruction.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
_`Enter integer n:`T'p`n = 0`>N`Enter integer m:`T'p`m = 0`>` and `Kp`m = n`;
|
||||
>`n > 0`d >`m > 0`d >Lp`m > n`;
|
||||
>`m < n`;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
Enter integer n:
|
||||
i3
|
||||
n > 0
|
||||
Enter integer m:
|
||||
i0
|
||||
m = 0 and m < n
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
v > "X",@ non-zero
|
||||
> & |
|
||||
> "0",@ zero
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
& #v_ "0",@ zero
|
||||
> "X",@ non-zero
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if i % 2 == 0
|
||||
print("even")
|
||||
else
|
||||
print("odd")
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if (i == 0)
|
||||
return "zero";
|
||||
elif (i % 2)
|
||||
return "odd";
|
||||
else
|
||||
return "even";
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
2+2:5
|
||||
& put$"Strange, must check that Bracmat interpreter."
|
||||
& 0
|
||||
| put$"That's what I thought."
|
||||
& Right
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
2+2
|
||||
: ( (<3|>5)
|
||||
& put$"Not quite, must check that Bracmat interpreter."
|
||||
| (3|5)
|
||||
& put$"Not far off, but must check that Bracmat interpreter some day."
|
||||
| ?
|
||||
& put$"That's what I thought."
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
[.]
|
||||
|
|
@ -0,0 +1 @@
|
|||
+[.]
|
||||
|
|
@ -0,0 +1 @@
|
|||
+[.-]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
blsq ) 9 2.%{"Odd""Even"}ch
|
||||
"Odd"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
blsq ) 9^^2.%{+.}if
|
||||
10
|
||||
blsq ) 10^^2.%{+.}if
|
||||
10
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
blsq ) 10^^2.%{-.}\/{+.}\/ie
|
||||
11
|
||||
blsq ) 9^^2.%{-.}\/{+.}\/ie
|
||||
8
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue