Pre-Release 0.1.1 of Lucy Lang
Pre-release
Pre-release
Version 0.1.1 - Pre-Release of Lucy Lang
- Add - operator. i.e. -1, -sin(x).
- Fix call statement bug
- Add NotExpr node
- Add system library and import keyword
- Add Lucy Example Code
$ java -jar target/lucy-0.1.1.jar
usage: lucy [options] target
-c,--compile <file> compile lucy source code to lucy X bit code
-d,--dump <file> dump lucy X object to human readable form
-h,--help print the help message and exit
-o,--output <output> output file path
-r,--run <file> run lucy X bit code
-t,--token <file> dump lucy tokens
-v,--version print the version information and exit
import "std"
func power(n, exp) {
result = 1
while exp > 0 {
result = result * n
exp = exp - 1
}
return result
}
func factorial(n) {
if n <= 1 {
return 1
} else {
return n * factorial(n-1)
}
}
func sin(x) {
var upper = 50, i = 0, sum = 0, sign = true
while i < upper {
if sign {
sum = sum + power(x, 1 + 2 * i) / factorial(1 + 2 * i)
} else {
sum = sum - power(x, 1 + 2 * i) / factorial(1 + 2 * i)
}
sign = !sign
i = i + 1
}
return sum
}
func cos(x) {
var upper = 50, i = 0, sum = 0, sign = true
while i < upper {
if sign {
sum = sum + power(x, 2 * i) / factorial(2 * i)
} else {
sum = sum - power(x, 2 * i) / factorial(2 * i)
}
sign = !sign
i = i + 1
}
return sum
}
func main() {
print("input n: ")
n = input()
while n != "end" {
n = number(n)
print("sin(" + string(n) + ") = " + string(sin(n)) + "\n")
print("cos(" + string(n) + ") = " + string(cos(n)) + "\n")
print("input n: ")
n = input()
}
}