initial commit
This commit is contained in:
parent
77786509df
commit
a3e07807e8
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
bin/
|
||||
*.l
|
||||
*.seed
|
4
src/adder.a68
Normal file
4
src/adder.a68
Normal file
@ -0,0 +1,4 @@
|
||||
BEGIN INT m = read int;
|
||||
INT n = read int;
|
||||
print (("sum is", m + n))
|
||||
END
|
1
src/aplusb.a68
Normal file
1
src/aplusb.a68
Normal file
@ -0,0 +1 @@
|
||||
print((read int + read int))
|
5
src/aplusb2.a68
Normal file
5
src/aplusb2.a68
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
open(stand in, "input.txt", stand in channel);
|
||||
open(stand out, "output.txt", stand out channel);
|
||||
print((read int + read int))
|
||||
|
5
src/ass1.a68
Normal file
5
src/ass1.a68
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN
|
||||
INT a = 1;
|
||||
a := a + 1;
|
||||
print(a)
|
||||
END
|
5
src/ass2.a68
Normal file
5
src/ass2.a68
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN
|
||||
INT a = 1;
|
||||
a := 2;
|
||||
print(a)
|
||||
END
|
6
src/ass3.a68
Normal file
6
src/ass3.a68
Normal file
@ -0,0 +1,6 @@
|
||||
BEGIN
|
||||
INT a;
|
||||
a := 1;
|
||||
a := a + 1;
|
||||
print(a)
|
||||
END
|
5
src/ass4.a68
Normal file
5
src/ass4.a68
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN
|
||||
REF INT a = LOC INT := 1;
|
||||
a := a + 1;
|
||||
print(a)
|
||||
END
|
6
src/ass5.a68
Normal file
6
src/ass5.a68
Normal file
@ -0,0 +1,6 @@
|
||||
BEGIN
|
||||
REF INT a = LOC INT; # Allocate but don’t initialize #
|
||||
a := 1; # Assign initial value #
|
||||
a := a + 1; # Increment #
|
||||
print(a)
|
||||
END
|
6
src/ass6.a68
Normal file
6
src/ass6.a68
Normal file
@ -0,0 +1,6 @@
|
||||
BEGIN
|
||||
INT a := 1;
|
||||
a := a + 1;
|
||||
a +:= 1;
|
||||
print(a)
|
||||
END
|
18
src/assignments.a68
Normal file
18
src/assignments.a68
Normal file
@ -0,0 +1,18 @@
|
||||
BEGIN
|
||||
INT a; # Declare without init #
|
||||
INT b;
|
||||
INT c;
|
||||
|
||||
a := 1; # Assign separately #
|
||||
b := 1;
|
||||
c := a + b;
|
||||
|
||||
print(c);
|
||||
|
||||
a := a + 1; # Standard assignment #
|
||||
INT poly = a * (a + 1);
|
||||
poly := poly +1;
|
||||
|
||||
print(a);
|
||||
print(poly)
|
||||
END
|
20
src/big_fact.a68
Normal file
20
src/big_fact.a68
Normal file
@ -0,0 +1,20 @@
|
||||
BEGIN
|
||||
PR precision 3000 PR
|
||||
OP *:= = (REF LONG LONG INT x, LONG LONG INT y) VOID: x := x * y;
|
||||
|
||||
PROC factorial = (LONG LONG INT n) LONG LONG INT:
|
||||
BEGIN
|
||||
LONG LONG INT result := 1;
|
||||
LONG LONG INT i := 1;
|
||||
WHILE i <= n DO
|
||||
result *:= i;
|
||||
i +:= 1
|
||||
OD;
|
||||
result
|
||||
END;
|
||||
|
||||
print("Enter a number: ");
|
||||
LONG LONG INT a;
|
||||
read((a));
|
||||
print(("Factorial of ", a, " is ", factorial(a)))
|
||||
END
|
5
src/coerce-test.a68
Normal file
5
src/coerce-test.a68
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN
|
||||
LONG INT a;
|
||||
read((a));
|
||||
print(a) # Just echo the input #
|
||||
END
|
11
src/copyback.a68
Normal file
11
src/copyback.a68
Normal file
@ -0,0 +1,11 @@
|
||||
BEGIN
|
||||
INT n = read int;
|
||||
FLEX [n] INT u;
|
||||
|
||||
[UPB u + 1] INT v;
|
||||
v[: UPB u] := u;
|
||||
u := v;
|
||||
print((n, newline));
|
||||
print((v, newline));
|
||||
print((u, newline))
|
||||
END
|
19
src/customplusab.a68
Normal file
19
src/customplusab.a68
Normal file
@ -0,0 +1,19 @@
|
||||
BEGIN
|
||||
OP +:= = (REF INT x, INT y) VOID: x := x + y; # Define +:= #
|
||||
|
||||
INT a; # No init #
|
||||
INT b;
|
||||
INT c;
|
||||
|
||||
a := 1;
|
||||
b := 1;
|
||||
c := a + b;
|
||||
|
||||
print(c);
|
||||
|
||||
a +:= 1; # Use custom operator #
|
||||
INT poly = a * (a + 1);
|
||||
|
||||
print(a);
|
||||
print(poly)
|
||||
END
|
7
src/fact.a68
Normal file
7
src/fact.a68
Normal file
@ -0,0 +1,7 @@
|
||||
BEGIN
|
||||
PROC factorial = (INT n) INT:
|
||||
IF n <= 1 THEN 1 ELSE n * factorial(n - 1) FI;
|
||||
|
||||
INT a := 5;
|
||||
print(("Factorial of ", a, " is ", factorial(a))) # Factorial of +5 is +120 #
|
||||
END
|
20
src/fact_input.a68
Normal file
20
src/fact_input.a68
Normal file
@ -0,0 +1,20 @@
|
||||
BEGIN
|
||||
PR precision 256 PR
|
||||
OP *:= = (REF LONG LONG INT x, LONG LONG INT y) VOID: x := x * y;
|
||||
|
||||
PROC factorial = (LONG LONG INT n) LONG LONG INT:
|
||||
BEGIN
|
||||
LONG LONG INT result := 1;
|
||||
LONG LONG INT i := 1;
|
||||
WHILE i <= n DO
|
||||
result *:= i;
|
||||
i +:= 1
|
||||
OD;
|
||||
result
|
||||
END;
|
||||
|
||||
print("Enter a number: ");
|
||||
LONG LONG INT a;
|
||||
read((a));
|
||||
print(("Factorial of ", a, " is ", factorial(a)))
|
||||
END
|
5
src/hello.a68
Normal file
5
src/hello.a68
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN
|
||||
INT a := 1; # Mutable variable #
|
||||
a +:= 1; # Built-in increment #
|
||||
print(a) # Output 2 #
|
||||
END
|
1
src/input.txt
Normal file
1
src/input.txt
Normal file
@ -0,0 +1 @@
|
||||
3 4
|
6
src/more_slicing.a68
Normal file
6
src/more_slicing.a68
Normal file
@ -0,0 +1,6 @@
|
||||
BEGIN
|
||||
STRING s := "abcdefghijklmnopqrstuvwxyz";
|
||||
print((s, newline));
|
||||
s[2 : 7] := s[9 : 14];
|
||||
print((s, newline))
|
||||
END
|
2
src/ops.a68
Normal file
2
src/ops.a68
Normal file
@ -0,0 +1,2 @@
|
||||
OP *:= = (REF INT x, INT y) VOID: x := x * y; # Multiply-and-assign #
|
||||
PROC add = (INT x, INT y) INT: x + y; # Simple procedure #
|
1
src/output.txt
Normal file
1
src/output.txt
Normal file
@ -0,0 +1 @@
|
||||
+7
|
5
src/prec_chk.a68
Normal file
5
src/prec_chk.a68
Normal file
@ -0,0 +1,5 @@
|
||||
BEGIN
|
||||
PR precision 256 PR
|
||||
LONG LONG INT a := LONG LONG 10 ^ 200; # Widen 10 to LONG LONG INT #
|
||||
print(a)
|
||||
END
|
17
src/realplusab.a68
Normal file
17
src/realplusab.a68
Normal file
@ -0,0 +1,17 @@
|
||||
BEGIN
|
||||
INT a; # No init #
|
||||
INT b;
|
||||
INT c;
|
||||
|
||||
a := 1;
|
||||
b := 1;
|
||||
c := a + b;
|
||||
|
||||
print(c);
|
||||
|
||||
a PLUSAB 1; # Test prelude operator #
|
||||
INT poly = a * (a + 1);
|
||||
|
||||
print(a);
|
||||
print(poly)
|
||||
END
|
16
src/rows.a68
Normal file
16
src/rows.a68
Normal file
@ -0,0 +1,16 @@
|
||||
BEGIN
|
||||
OP ELEM = (INT needle, [] INT haystack) BOOL:
|
||||
BEGIN
|
||||
BOOL found := FALSE;
|
||||
FOR i FROM LWB haystack TO UPB haystack DO
|
||||
IF haystack[i] = needle THEN
|
||||
found := TRUE
|
||||
FI
|
||||
OD;
|
||||
found
|
||||
END;
|
||||
|
||||
[] INT first primes = (1, 3, 5, 7, 11);
|
||||
print (first primes[1]);
|
||||
print (1 ELEM first primes) # prints two times +1 #
|
||||
END
|
16
src/sizing.a68
Normal file
16
src/sizing.a68
Normal file
@ -0,0 +1,16 @@
|
||||
BEGIN
|
||||
INT n = read int; # Read size n from console input (e.g., 3) #
|
||||
FLEX [n] INT u; # Declare flexible row u with n elements (uninitialized) #
|
||||
FOR i FROM 1 TO n DO
|
||||
u[i] := read int # Initialize u’s n elements with console input #
|
||||
OD;
|
||||
[n + 1] INT v; # Declare fixed row v with n+1 elements (uninitialized) #
|
||||
FOR i FROM 1 TO n + 1 DO
|
||||
v[i] := 0 # Initialize all v elements to 0 #
|
||||
OD;
|
||||
v[: UPB u] := u; # Copy u’s n elements into v’s first n positions #
|
||||
u := v; # Assign v to u, resizing u to n+1 and copying values #
|
||||
print((n, newline)); # Print original size n #
|
||||
print((u, newline)); # Print u (now n+1 elements) #
|
||||
print((v, newline)) # Print v (n+1 elements) #
|
||||
END
|
20
src/slices.a68
Normal file
20
src/slices.a68
Normal file
@ -0,0 +1,20 @@
|
||||
BEGIN
|
||||
[, ] INT r =
|
||||
((1, 2, 3, 4),
|
||||
(5, 6, 7, 8),
|
||||
(9, 10, 11, 12),
|
||||
(13, 14, 15, 16));
|
||||
|
||||
put(stand out, (r[2, 2], newline));
|
||||
put(stand out, (r[3, ], " ", newline)); # Space between elements #
|
||||
put(stand out, (r[, 2 UPB r], " ", newline));
|
||||
put(stand out, (r[3, 2], newline));
|
||||
put(stand out, (r[2, ], " ", newline));
|
||||
put(stand out, (r[, 3], " ", newline));
|
||||
|
||||
[] CHAR word = 3 * "ab";
|
||||
print((word,newline));
|
||||
|
||||
[1 : 5] INT first_primes := (1, 3, 5, 7, 11);
|
||||
print(first_primes[3])
|
||||
END
|
7
src/test1.a68
Normal file
7
src/test1.a68
Normal file
@ -0,0 +1,7 @@
|
||||
#include "ops.a68"
|
||||
BEGIN
|
||||
INT a := 1;
|
||||
a +:= 1; # Built-in #
|
||||
a *:= 2; # Custom from ops.a68 #
|
||||
print(a) # 4 (1 + 1 = 2, 2 * 2 = 4) #
|
||||
END
|
17
src/types.a68
Normal file
17
src/types.a68
Normal file
@ -0,0 +1,17 @@
|
||||
BEGIN
|
||||
|
||||
INT a = 1; # standard integer #
|
||||
LONG b = 1234567890987654321; # long integer #
|
||||
LONG LONG c = 1234567890987654321234567890987654321; # long long int #
|
||||
INT x = 5, y = 10; # works #
|
||||
INT one = 1, start = one; # will not work because order is arbitrary with comma #
|
||||
INT one = 1; INT start = one; # will work because order is linear with semicolon #
|
||||
REAL n = 2.795; # standard real #
|
||||
LONG REAL m = 18.2020202020202999222922922222991; # long real #
|
||||
DOUBLE pi times 2 = 6.283185307179586476925286767; # also long real #
|
||||
|
||||
INT q = READ INT; # read input to integer blam #
|
||||
REAL k = READ REAL; # read input to real kapow #
|
||||
REAL frumkin = 18.625;INT fleegle = ROUND(frumpkin) # real to int conversion is done by rounding #
|
||||
|
||||
END
|
23
src/types2.a68
Normal file
23
src/types2.a68
Normal file
@ -0,0 +1,23 @@
|
||||
BEGIN
|
||||
INT a = 1; # standard integer #
|
||||
LONG INT b = 1234567890987654321; # long integer (corrected LONG syntax) #
|
||||
LONG LONG INT c = 1234567890987654321234567890987654321; # long long int (corrected syntax) #
|
||||
INT x = 5, y = 10; # works #
|
||||
INT one = 1; INT start = one; # works with semicolons #
|
||||
REAL n = 2.795; # standard real #
|
||||
LONG REAL m = 18.2020202020202999222922922222991; # long real #
|
||||
DOUBLE pi_times_2 = 6.283185307179586476925286767; # also long real (no spaces in identifier) #
|
||||
|
||||
INT q; # declare q first #
|
||||
REAL k; # declare k first #
|
||||
read((q, k)); # read input into q and k #
|
||||
|
||||
REAL frumkin = 18.625;
|
||||
INT fleegle = ROUND(frumkin); # real to int conversion by rounding #
|
||||
|
||||
print(("a = ", a, " b = ", b, newline));
|
||||
print(("c = ", c, " x = ", x, " y = ", y, newline));
|
||||
print(("one = ", one, " start = ", start, newline));
|
||||
print(("n = ", n, " m = ", m, newline));
|
||||
print(("q = ", q, " k = ", k, newline)) # optional: output to verify #
|
||||
END
|
26
src/types3.a68
Normal file
26
src/types3.a68
Normal file
@ -0,0 +1,26 @@
|
||||
BEGIN
|
||||
INT a = 1; # standard integer #
|
||||
LONG INT b = 1234567890987654321; # long integer #
|
||||
LONG LONG INT c = 1234567890987654321234567890987654321; # long long int #
|
||||
INT x = 5, y = 10; # works #
|
||||
INT one = 1; INT strt = one; # works with semicolons #
|
||||
REAL n = 2.795; # standard real #
|
||||
LONG REAL m = 18.2020202020202999222922922222991; # long real #
|
||||
DOUBLE pi_times_2 = 6.283185307179586476925286767; # also long real #
|
||||
|
||||
INT q; # declare q first #
|
||||
REAL k; # declare k first #
|
||||
read((q, k)); # read input into q and k #
|
||||
|
||||
REAL frumkin = 18.625;
|
||||
INT fleegle = ROUND(frumkin); # real to int conversion by rounding #
|
||||
|
||||
print(("a = ", a, " b = ", b, newline));
|
||||
print(("c = ", c, newline));
|
||||
print(("x = ", x, " y = ", y, newline));
|
||||
print(("one = ", one, " start = ", strt, newline));
|
||||
print(("n = ", n, " m = ", m, newline));
|
||||
print(("pi_times_2 = ", pi_times_2, newline));
|
||||
print(("q = ", q, " k = ", k, newline));
|
||||
print(("frumkin = ", frumkin, " fleegle = ", fleegle, newline))
|
||||
END
|
Loading…
Reference in New Issue
Block a user