-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34db107
commit 762c034
Showing
33 changed files
with
685 additions
and
4,005 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
.vscode/* | ||
CMakeFiles/* | ||
*/CMakeFiles/* | ||
*.cmake | ||
*/Makefile | ||
Makefile | ||
CMakeCache.txt | ||
|
||
ocean | ||
src/ocean.tab.cpp | ||
src/ocean.tab.hpp | ||
src/lex.yy.cpp | ||
scratch/* | ||
|
||
*/*.output | ||
# Added by cargo | ||
|
||
/target |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "ocean" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,4 @@ | ||
# ocean | ||
A C-like programming language (get it like sea-like like an ocean lol) | ||
|
||
### Building | ||
This project uses flex and bison so install them. _add some instructions about this_ | ||
|
||
Then in the root folder of this repo run: | ||
|
||
```cmake .``` | ||
|
||
to build the makefile then: | ||
|
||
```make``` | ||
|
||
to build the project then | ||
|
||
```{install???}``` | ||
|
||
to install. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
isEven: func = (x: i64) -> (result: bool = x % 2 == 0) | ||
|
||
isEmpty: func = (x: string) -> (result: bool = x == "") | ||
|
||
collatz: func = (input: i64) -> (path: i64[]) { | ||
loop input != 1 { | ||
path.append(input) | ||
if !input.isEven() { | ||
input = input / 2 | ||
} else { | ||
input = 3 * input + 1 | ||
} | ||
} | ||
} | ||
|
||
while true { | ||
print("Input a number: ") | ||
userinput: string = input() | ||
if !userinput.isEmpty() { | ||
parsed: auto = userInput.parsei64 # the type here is optional i64 | ||
if parsed.has_value() { | ||
result: auto = parsed.collatz() | ||
println(result.size()) | ||
println(result) | ||
break | ||
} | ||
println(`{userinput} is not an integer`) | ||
} else { | ||
println("not a number") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fib: func = (input: i64) -> (result: i64) { | ||
if input == 0 { | ||
result = 0 | ||
} else { | ||
result = input + fib(input - 1) | ||
} | ||
} | ||
|
||
println(9.fib) | ||
println(fib(10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use io | ||
|
||
println("Hello, World!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
gcd: func = (a: i64, b: i64) -> (result: i64) { | ||
# If A=0 then GCD(A, B)=B since the Greatest Common Divisor of 0 and B is B. | ||
# If B=0 then GCD(a,b)=a since the Greatest Common Divisor of 0 and a is a. | ||
# Let R be the remainder of dividing A by B assuming A > B. (R = A % B) | ||
# Find GCD( B, R ) because GCD( A, B ) = GCD( B, R ). Use the above steps again. | ||
|
||
loop a != 0 || b != 0 { | ||
new_a: i64 = b | ||
new_b: i64 = a % b | ||
} | ||
|
||
if a == 0 { | ||
result = b | ||
} else if b == 0 { | ||
result = a | ||
} | ||
} | ||
|
||
abs: func = (a: i64) -> (result: i64) { | ||
if a < 0 { | ||
result = -a | ||
} else { | ||
result = a | ||
} | ||
} | ||
|
||
lcm: func = (a: i64, b: i64) -> (result: i64 = abs(a) * abs(b) / gcd(a, b)) | ||
|
||
op _+_ left = (x: auto T, y: T) -> (result: T = add(x, y)) | ||
|
||
op _-_ left = (x: auto T, y: T) -> (result: T = subtract(x, y)) | ||
|
||
pack rational { | ||
numerator: i64 | ||
denominator: i64 | ||
} | ||
|
||
add: func = (a: rational, b: rational) -> (result: rational) { | ||
mul: i64 = lcm(a.denominator, b.denominator) | ||
res = { a.numerator * mul + b.numerator * mul, mul }; | ||
} | ||
|
||
subtract: func = (a: rational, b: rational) -> (res: rational) { | ||
mul: i64 = lcm(a.denominator, b.denominator) | ||
res = { a.numerator * mul - b.numerator * mul, mul }; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.