Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -1,9 +1,9 @@
|
|||
# operator to turn two boolean values into an integer - name inspired by the COBOL sample #
|
||||
PRIO ALSO = 1;
|
||||
OP ALSO = ( BOOL a, b )INT: IF a AND b THEN 1 ELIF a THEN 2 ELIF b THEN 3 ELSE 4 FI;
|
||||
OP ALSO = ( BOOL av, bv )INT: IF av AND bv THEN 1 ELIF av THEN 2 ELIF bv THEN 3 ELSE 4 FI;
|
||||
|
||||
# using the above operator, we can use the standard CASE construct to provide the #
|
||||
# required construct, e.g.: #
|
||||
# required costruct, e.g.: #
|
||||
BOOL a := TRUE, b := FALSE;
|
||||
CASE a ALSO b
|
||||
IN print( ( "both: a and b are TRUE", newline ) )
|
||||
|
|
|
|||
31
Task/Extend-your-language/C++/extend-your-language.cpp
Normal file
31
Task/Extend-your-language/C++/extend-your-language.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Header file "if2.hpp"
|
||||
#ifndef if2_HPP_
|
||||
#define if2_HPP_
|
||||
|
||||
#define if2(first, second, both_true, first_true, second_true, neither_true) \
|
||||
const uint32_t value = ( first ? 0 : 2 ) + ( second ? 0 : 1 ); \
|
||||
switch ( value ) { \
|
||||
case 0: both_true; break; \
|
||||
case 1: first_true; break; \
|
||||
case 2: second_true; break; \
|
||||
case 3: neither_true; break; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Main file
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include "if2.hpp"
|
||||
|
||||
int main() {
|
||||
for ( uint32_t N = 10; N <= 20; ++N ) {
|
||||
std::cout << N;
|
||||
if2(N % 2 == 0, N % 3 == 0,
|
||||
std::cout << " is divisible by both 2 and 3" << "\n",
|
||||
std::cout << " is divisible by 2, but not by 3" << "\n",
|
||||
std::cout << " is divisible by 3, but not by 2" << "\n",
|
||||
std::cout << " isn't divisible by 2, nor by 3" << "\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">switch</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">condition1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">condition2</span><span style="color: #0000FF;">}</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #0000FF;">{</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">}:</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #0000FF;">{</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">}:</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #0000FF;">{</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">}:</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #0000FF;">{</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">}:</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">switch</span>
|
||||
<!--
|
||||
switch {condition1,condition2} do
|
||||
case {true,true}:
|
||||
case {true,false}:
|
||||
case {false,true}:
|
||||
case {false,false}:
|
||||
end switch
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">if2</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">c1</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">c2</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">c1</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span><span style="color: #0000FF;">+</span><span style="color: #000000;">c2</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function if2(bool c1, bool c2)
|
||||
return c1*10+c2
|
||||
end function
|
||||
|
||||
<span style="color: #008080;">switch</span> <span style="color: #000000;">if2</span><span style="color: #0000FF;">(</span><span style="color: #000000;">condition1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">condition2</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #000000;">11</span><span style="color: #0000FF;">:</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">:</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #000000;">01</span><span style="color: #0000FF;">:</span>
|
||||
<span style="color: #008080;">case</span> <span style="color: #000000;">00</span><span style="color: #0000FF;">:</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">switch</span>
|
||||
<!--
|
||||
switch if2(condition1,condition2) do
|
||||
case 11:
|
||||
case 10:
|
||||
case 01:
|
||||
case 00:
|
||||
end switch
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">enum</span> <span style="color: #000000;">BOTH</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0b11</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">FIRST</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0b10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">SECOND</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0b01</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">NEITHER</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0b00</span>
|
||||
enum BOTH = 0b11, FIRST = 0b10, SECOND = 0b01, NEITHER = 0b00
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">if2</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">c1</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">bool</span> <span style="color: #000000;">c2</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">c1</span><span style="color: #0000FF;">*</span><span style="color: #000000;">2</span><span style="color: #0000FF;">+</span><span style="color: #000000;">c2</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function if2(bool c1, bool c2)
|
||||
return c1*2+c2
|
||||
end function
|
||||
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">if2</span><span style="color: #0000FF;">(</span><span style="color: #000000;">condition1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">condition2</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">=</span><span style="color: #000000;">BOTH</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">elsif</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">=</span><span style="color: #000000;">FIRST</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">elsif</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">=</span><span style="color: #000000;">SECOND</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">elsif</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">=</span><span style="color: #000000;">NEITHER</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<!--
|
||||
integer r = if2(condition1,condition2)
|
||||
if r=BOTH then
|
||||
elsif r=FIRST then
|
||||
elsif r=SECOND then
|
||||
elsif r=NEITHER then
|
||||
end if
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">global</span> <span style="color: #008080;">constant</span> <span style="color: #000000;">T_if2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5200</span> <span style="color: #000000;">tt_stringF</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"if2"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_if2</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">global</span> <span style="color: #008080;">constant</span> <span style="color: #000000;">T_else1</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5200</span> <span style="color: #000000;">tt_stringF</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"else1"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_else1</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">global</span> <span style="color: #008080;">constant</span> <span style="color: #000000;">T_else2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5200</span> <span style="color: #000000;">tt_stringF</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"else2"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_else2</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
global constant T_if2 = 5200 tt_stringF("if2",T_if2)
|
||||
global constant T_else1 = 5200 tt_stringF("else1",T_else1)
|
||||
global constant T_else2 = 5200 tt_stringF("else2",T_else2)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,2 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #000080;font-style:italic;">--constant T_endelseelsif = {T_end,T_else,T_elsif,T_case,T_default,T_fallthru,T_fallthrough}</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">T_endelseelsif</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">T_end</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_else</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_else1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_else2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_elsif</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_case</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_default</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_fallthru</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_fallthrough</span><span style="color: #0000FF;">}</span>
|
||||
<!--
|
||||
--constant T_endelseelsif = {T_end,T_else,T_elsif,T_case,T_default,T_fallthru,T_fallthrough}
|
||||
constant T_endelseelsif = {T_end,T_else,T_else1,T_else2,T_elsif,T_case,T_default,T_fallthru,T_fallthrough}
|
||||
|
|
|
|||
|
|
@ -1,3 +1 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">elsif</span> <span style="color: #000000;">ttidx</span><span style="color: #0000FF;">=</span><span style="color: #000000;">T_if2</span> <span style="color: #008080;">then</span> <span style="color: #000000;">DoIf2</span><span style="color: #0000FF;">()</span>
|
||||
<!--
|
||||
elsif ttidx=T_if2 then DoIf2()
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">N</span><span style="color: #0000FF;">=</span><span style="color: #000000;">10</span> <span style="color: #008080;">to</span> <span style="color: #000000;">20</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d is "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">N</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">if2</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">N</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">N</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"divisible by both two and three.\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">else1</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"divisible by two, but not by three.\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">else2</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"divisible by three, but not by two.\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">else</span>
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"neither divisible by two, nor by three.\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #000000;">if2</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<!--
|
||||
for N=10 to 20 do
|
||||
printf(1,"%d is ",N)
|
||||
if2 mod(N,2)=0, mod(N,3)=0 then
|
||||
puts(1,"divisible by both two and three.\n")
|
||||
else1
|
||||
puts(1,"divisible by two, but not by three.\n")
|
||||
else2
|
||||
puts(1,"divisible by three, but not by two.\n")
|
||||
else
|
||||
puts(1,"neither divisible by two, nor by three.\n")
|
||||
end if2
|
||||
end for
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue