2KWLang
2KWLang (short for 2-Keyword Language) is an esolang by User:PythonshellDebugwindow.
Syntax
There are only two keywords in this language, as the name implies, and they are import
and print
.
Import
To import the file named fname (must be a string) for its side effects only:
import fname;
Output
To print x with a newline:
print x;
Without a newline:
print x | "";
Read file to STDOUT
To print out the contents of the file named fname (again, must be a string):
print import fname;
Input
To get user input:
print "\n";
where n is a digit 0-9. To retrieve it once inputted:
print "\n";
where n is a digit 0-9.
Math
These operators have C-like syntax and the same precedence. 2KWLang has the following mathematical operators: +, -, *, /, %, &&, ||, &, |, !, ~, and ^.
Comparison
These operators also have C-like syntax. 2KWLang has the following comparison operators: ==, !=, >, <, >=, and <=.
Parentheses
Like in C, the ( ) parentheses/round brackets use surround notation, and they are only used for grouping
Ternary operator
Again, C-like syntax for the x ? y : z
ternary operator. 0 and the empty string are considered falsy, all other values are considered truthy.
String, integer, and floating-point literals
Strings have double quotes around them:
"Hello World"
but these quotes can be escaped:
"This string has escaped \"quotes\" in it!"
Integers and floating-points are like in C:
12345 67.098
and they allow leading zeros.
Looping
2KWLang programs can import themselves, even conditionally using the ternary operator.
Examples
Hello, World!
print "Hello, World!";
Cat
print "\0"; print "\0";
Quine (maybe cheating)
print import "nameOfThisFile";
where nameOfThisFile is the name of the file being executed.
Truth-machine
Requires 3 files: main.2kwl, 1.2kwl, and 0.2kwl.
main.2kwl
:
print "\0"; import (("\0" == "1") ? "1.2kwl" : "0.2kwl");
1.2kwl
:
print "1"; import "1.2kwl";
0.2kwl
:
print "0";