This repo is now deprecated, in favor of the much faster, vastly improved CalcLang2.
A pointless scripting language that does math. Made with ANTLR 4 and Java. Terrible docs.
The only type is Double
. They can be negative, and you may omit the decimals.
Hexadecimal is accepted too.
0x10 becomes 16.0
3 becomes 3.0
3.5 because 3.5
- else
- end
- fn
- if
- inc
- loop
- ret
In a word, no. However, you can print. ES6-like string interpolation is allowed. Just include an expression. Yes, you can perform arithmetic, call functions, or resolve variables within strings.
print "Not another hello world..."
print "${2 + 2} = 4"
Booleans in Calclang are mapped to numbers.
true becomes 1.0
false becomes 0.0
1.0 == true
0.0 == false
if (true)
print "Hello, bool!"
end if
- Predefined Constants:
- PI
- AVOGADRO
- PLANCK
- SPEED_OF_LIGHT
- E
- I
- INFINITY
- Predefined Functions:
- Build the jar, or compile the source and run the classes.
- Run it with the option -h.
- With no options, you will enter... REPL mode. Which, of course, is broken.
- Not all of the examples work yet... i.e. Fibonacci
To reproduce...
mvn clean install
- You must have an
fn main()
block for anything to happen.
- Only can declare variables within functions.
- If you want to do it globally, prefix with "global"
global one = 1
fn hi()
two = 2
print "one=${one}, two=${two}"
end fn
- No nesting yet
// Can have 0 or more params. The parentheses() are required.
// You must have a return statement.
fn sinFromDegrees(deg)
ret sin(rad(deg))
end sinFromDegrees
- Only at the top of the file
inc "./myfile.calc"
- No for statements yet, sorry
times = 5000
loop times
print "I like it!"
end loop