Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
10
Task/Conditional-structures/Ada/conditional-structures-1.adb
Normal file
10
Task/Conditional-structures/Ada/conditional-structures-1.adb
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;
|
||||
13
Task/Conditional-structures/Ada/conditional-structures-2.adb
Normal file
13
Task/Conditional-structures/Ada/conditional-structures-2.adb
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,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-5.adb
Normal file
13
Task/Conditional-structures/Ada/conditional-structures-5.adb
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;
|
||||
10
Task/Conditional-structures/Ada/conditional-structures-7.adb
Normal file
10
Task/Conditional-structures/Ada/conditional-structures-7.adb
Normal file
|
|
@ -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;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
num: 2
|
||||
|
||||
switch num=2 [
|
||||
print "yep, num is 2"
|
||||
][
|
||||
print "something went wrong..."
|
||||
]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
good: function [name][
|
||||
what: (attr'what) ?? "morning"
|
||||
print ["Good" what name "!"]
|
||||
]
|
||||
|
||||
good "Nick"
|
||||
good.what:"night" "John"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
x: 2
|
||||
|
||||
case x [
|
||||
1 -> print "x is one!"
|
||||
2 -> print "x is two!"
|
||||
any -> print "x is none of the above"
|
||||
]
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
loop 1..5 'num [
|
||||
when.has: num [
|
||||
[< 2] -> print [num ": it's less than 2"]
|
||||
[= 2] -> print [num ": it's 2!"]
|
||||
[= 3] -> print [num ": it's 3!"]
|
||||
true -> print [num ": the number is too big"]
|
||||
]
|
||||
]
|
||||
|
|
@ -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,19 @@
|
|||
if condition-1
|
||||
imperative-statement-1
|
||||
else
|
||||
imperative-statement-2
|
||||
end-if
|
||||
|
||||
if condition-1
|
||||
if condition-a
|
||||
imperative-statement-1a
|
||||
else
|
||||
imperative-statement-1
|
||||
end-if
|
||||
else
|
||||
if condition-a
|
||||
imperative-statement-2a
|
||||
else
|
||||
imperative-statement-2
|
||||
end-if
|
||||
end-if
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
evaluate identifier-1
|
||||
when 'good'
|
||||
good-imperative-statement
|
||||
when 'bad'
|
||||
bad-imperative-statement
|
||||
when 'ugly'
|
||||
when 'awful'
|
||||
ugly-or-awful-imperative-statement
|
||||
when other
|
||||
default-imperative-statement
|
||||
end-evaluate
|
||||
|
||||
evaluate true
|
||||
when condition-1
|
||||
condition-1-imperative-statement
|
||||
when condition-2
|
||||
condition-2-imperative-statement
|
||||
when condition-3
|
||||
condition-3-imperative-statement
|
||||
when other
|
||||
default-condition-imperative-statement
|
||||
end-evaluate
|
||||
|
||||
evaluate identifier-1 also identifier-2
|
||||
when 10 also 20
|
||||
one-is-10-and-two-is-20-imperative-statement
|
||||
when 11 also 30
|
||||
one-is-11-and-two-is-30-imperative-statement
|
||||
when 20 also any
|
||||
one-is-20-and-two-is-anything-imperative-statement
|
||||
when other
|
||||
default-imperative-statement
|
||||
end-evaluate
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
i = random 10
|
||||
i = random 1 10
|
||||
if i mod 2 = 0
|
||||
print i & " is divisible by 2"
|
||||
elif i mod 3 = 0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
import gleam/int
|
||||
import gleam/io
|
||||
|
||||
pub fn conditional_example(x: Int) {
|
||||
// if's below are called "pattern guards".
|
||||
case x {
|
||||
x if x < 0 -> io.println(x |> int.to_string <> " is negative")
|
||||
x if x == 0 -> io.println(x |> int.to_string <> " is zero")
|
||||
_ -> io.println(x |> int.to_string <> " is positive")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
// Pattern matching is the only conditional structure in Gleam.
|
||||
conditional_example(-10)
|
||||
conditional_example(0)
|
||||
conditional_example(10)
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
HAI 1.3
|
||||
|
||||
I HAS A PASSWERD ITZ "SWORDFISH"
|
||||
BOTH SAEM PASSWERD AN "SWORDFISH", O RLY? BTW if
|
||||
YA RLY BTW then
|
||||
VISIBLE "UR PASSWERD IS WIN"
|
||||
MEBBE BOTH SAEM PASSWERD AN "12345" BTW else if
|
||||
VISIBLE "U HAS STOOPIDEST PASSWERD EVAR"
|
||||
NO WAI BTW else
|
||||
VISIBLE "UR PASSWERD IS FAIL. ENTRY ARE DENIED."
|
||||
OIC
|
||||
|
||||
I HAS A FOOD ITZ "CHEEZBURGER"
|
||||
FOOD, WTF? BTW switch
|
||||
OMG "FISH"
|
||||
VISIBLE "DO WANT"
|
||||
GTFO
|
||||
OMG "CHEEZBURGER"
|
||||
VISIBLE "I CAN HAS IT?"
|
||||
OMG "COOKIE"
|
||||
VISIBLE "I EATED IT"
|
||||
GTFO
|
||||
OMG "CHIKIN"
|
||||
VISIBLE "ITZ FINGER LIKIN GUD!"
|
||||
OMGWTF BTW default case
|
||||
VISIBLE "DO NOT WANT"
|
||||
OIC
|
||||
|
||||
KTHXBYE
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
if cond then
|
||||
foo();
|
||||
elsif cond then
|
||||
bar();
|
||||
else
|
||||
baz();
|
||||
end
|
||||
|
||||
// if's are expressions and can yield the value of the last expression in each branch
|
||||
var int x = if y > z then
|
||||
y + 1
|
||||
else
|
||||
z
|
||||
end
|
||||
;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
switch x do
|
||||
case 1:
|
||||
foo();
|
||||
fallthrough; // Falls through and also executes "case 2"'s code
|
||||
case 2:
|
||||
bar();
|
||||
break; // Break out of switch.
|
||||
default:
|
||||
baz();
|
||||
break;
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
var int x = y > z ? y + 1 : z;
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# standard if
|
||||
if (condition) {
|
||||
# ...
|
||||
}
|
||||
|
||||
# if-then-else
|
||||
if (condition) {
|
||||
# ...
|
||||
} else {
|
||||
# ...
|
||||
}
|
||||
|
||||
# if-then-elseif-else
|
||||
if (condition) {
|
||||
# ...
|
||||
} elseif (condition2) {
|
||||
# ...
|
||||
} else {
|
||||
# ...
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# standard switch
|
||||
switch ($var) {
|
||||
1 { "Value was 1" }
|
||||
2 { "Value was 2" }
|
||||
default { "Value was something else" }
|
||||
}
|
||||
|
||||
# switch with wildcard matching
|
||||
switch -Wildcard ($var) {
|
||||
"a*" { "Started with a" }
|
||||
"*x" { "Ended with x" }
|
||||
}
|
||||
|
||||
# switch with regular expression matching
|
||||
switch -Regex ($var) {
|
||||
"[aeiou]" { "Contained a consonant" }
|
||||
"(.)\1" { "Contained a character twice in a row" }
|
||||
}
|
||||
|
||||
# switch allows for scriptblocks too
|
||||
switch ($var) {
|
||||
{ $_ % 2 -eq 0 } { "Number was even" }
|
||||
{ $_ -gt 100 } { "Number was greater than 100" }
|
||||
}
|
||||
|
||||
# switch allows for handling a file
|
||||
switch -Regex -File somefile.txt {
|
||||
"\d+" { "Line started with a number" }
|
||||
"\s+" { "Line started with whitespace" }
|
||||
}
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
# riscv assembly raspberry pico2 rp2350
|
||||
# program condstruct.s
|
||||
# connexion putty com3
|
||||
/*********************************************/
|
||||
/* CONSTANTES */
|
||||
/********************************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../constantesRiscv.inc"
|
||||
.equ BUFFERSIZE, 255
|
||||
/*******************************************/
|
||||
/* INITIALED DATAS */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessStart: .asciz "Program riscv start.\r\n"
|
||||
szMessEndOk: .asciz "Program riscv end OK.\r\n"
|
||||
szCariageReturn: .asciz "\r\n"
|
||||
|
||||
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 equal.\n"
|
||||
szMessTest3N: .asciz "The test 3 is not equal.\n"
|
||||
szMessTest4: .asciz "The test 4 is equal.\n"
|
||||
szMessTest4N: .asciz "The test 4 is not equal.\n"
|
||||
|
||||
szMessTest5: .asciz "The test 5 is <.\n"
|
||||
szMessTest5N: .asciz "The test 5 is not <.\n"
|
||||
szMessTest6: .asciz "The test 6 is <.\n"
|
||||
szMessTest6N: .asciz "The test 6 is not <.\n"
|
||||
szMessTest7: .asciz "The test 7 is >=.\n"
|
||||
szMessTest7N: .asciz "The test 7 is not >=.\n"
|
||||
|
||||
szMessTest8: .asciz "Result test 8 (slt) : "
|
||||
szMessTest9: .asciz "Result test 9 (snez) : "
|
||||
|
||||
|
||||
.align 2
|
||||
/*******************************************/
|
||||
/* UNINITIALED DATA */
|
||||
/*******************************************/
|
||||
.bss
|
||||
sConvArea: .skip 24
|
||||
.align 2
|
||||
|
||||
/**********************************************/
|
||||
/* SECTION CODE */
|
||||
/**********************************************/
|
||||
.text
|
||||
.global main
|
||||
|
||||
main:
|
||||
call stdio_init_all # général init
|
||||
1: # start loop connexion
|
||||
li a0,0 # raz argument register
|
||||
call tud_cdc_n_connected # waiting for USB connection
|
||||
beqz a0,1b # return code = zero ?
|
||||
|
||||
la a0,szMessStart # message address
|
||||
call writeString # display message
|
||||
|
||||
# TEST 1 : test equal zero
|
||||
#li t0,0 # comments
|
||||
li t0,1 # or uncomments
|
||||
beqz t0,1f
|
||||
la a0,szMessTest1N
|
||||
j 2f
|
||||
1:
|
||||
la a0,szMessTest1
|
||||
2:
|
||||
call writeString
|
||||
|
||||
# TEST 2 : test not equal zero
|
||||
#li t0,0 # comments
|
||||
li t0,1 # or uncomments
|
||||
bnez t0,1f
|
||||
la a0,szMessTest2
|
||||
j 2f
|
||||
1:
|
||||
la a0,szMessTest2N
|
||||
2:
|
||||
call writeString
|
||||
|
||||
# TEST 3 : test equal 5
|
||||
#li t0,1 # comments
|
||||
li t0,5 # or uncomments
|
||||
li t1,5
|
||||
beq t0,t1,1f
|
||||
la a0,szMessTest3N
|
||||
j 2f
|
||||
1:
|
||||
la a0,szMessTest3
|
||||
2:
|
||||
call writeString
|
||||
|
||||
# TEST 4 : test not equal 5
|
||||
#li t0,5 # comments
|
||||
li t0,6 # or uncomments
|
||||
li t1,5
|
||||
bne t0,t1,1f
|
||||
la a0,szMessTest4
|
||||
j 2f
|
||||
1:
|
||||
la a0,szMessTest4N
|
||||
2:
|
||||
call writeString
|
||||
|
||||
# TEST 5 : test < 5 SIGNED
|
||||
li t0,-6 # comments
|
||||
#li t0,4 # or uncomments
|
||||
li t1,5
|
||||
blt t0,t1,1f
|
||||
la a0,szMessTest5N
|
||||
j 2f
|
||||
1:
|
||||
la a0,szMessTest5
|
||||
2:
|
||||
call writeString
|
||||
|
||||
# TEST 6 : test < 5 UNSIGNED
|
||||
li t0,-6 # comments
|
||||
#li t0,4 # or uncomments
|
||||
li t1,5
|
||||
bltu t0,t1,1f
|
||||
la a0,szMessTest6N
|
||||
j 2f
|
||||
1:
|
||||
la a0,szMessTest6
|
||||
2:
|
||||
call writeString
|
||||
|
||||
# TEST 7 : test >= 5 SIGNED
|
||||
li t0,-6 # comments
|
||||
#li t0,4 # or uncomments
|
||||
li t1,5
|
||||
bge t0,t1,1f
|
||||
la a0,szMessTest7N
|
||||
j 2f
|
||||
1:
|
||||
la a0,szMessTest7
|
||||
2:
|
||||
call writeString
|
||||
|
||||
# TEST8 value 1 if 4 < 5 else value 0
|
||||
la a0,szMessTest8
|
||||
call writeString
|
||||
li t0,4 # comments or uncomments
|
||||
#li t0,6 # comments or uncomments
|
||||
li t1,5
|
||||
slt a0,t0,t1
|
||||
la a1,sConvArea
|
||||
call conversion10
|
||||
la a0,sConvArea
|
||||
call writeString
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
|
||||
# TEST9 value 1 if t0 <>0 else value 0
|
||||
la a0,szMessTest9
|
||||
call writeString
|
||||
li t0,4 # comments or uncomments
|
||||
#li t0,0 # comments or uncomments
|
||||
snez a0,t0
|
||||
la a1,sConvArea
|
||||
call conversion10
|
||||
la a0,sConvArea
|
||||
call writeString
|
||||
la a0,szCariageReturn
|
||||
call writeString
|
||||
|
||||
|
||||
la a0,szMessEndOk # message address
|
||||
call writeString # display message
|
||||
call getchar
|
||||
100: # final loop
|
||||
j 100b
|
||||
|
||||
/************************************/
|
||||
/* file include Fonctions */
|
||||
/***********************************/
|
||||
/* for this file see risc-v task include a file */
|
||||
.include "../../includeFunctions.s"
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
If condition1 Then
|
||||
statement
|
||||
End If
|
||||
|
||||
If condition1 Then
|
||||
statement
|
||||
ElseIf condition2 Then
|
||||
statement
|
||||
...
|
||||
ElseIf conditionN Then
|
||||
statement
|
||||
Else
|
||||
statement
|
||||
End If
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
If condition Then statement
|
||||
|
||||
If condition Then statement Else statement
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
Select Case Expression
|
||||
Case Value1: statement
|
||||
Case Value2: statement
|
||||
...
|
||||
Case ValueN: statement
|
||||
Case Else: statement
|
||||
End Select
|
||||
|
||||
Select Case Expression
|
||||
Case Value1
|
||||
statements
|
||||
Case Value2
|
||||
statements
|
||||
...
|
||||
Case ValueN
|
||||
statements
|
||||
Case Else
|
||||
statements
|
||||
End Select
|
||||
Loading…
Add table
Add a link
Reference in a new issue