Language Basics
Comments
Section titled “Comments”Single-line comments start with //
.
// This is a commentauto x = 10; // Comment after code
Variables
Section titled “Variables”Declare variables with auto
. Types are inferred dynamically. Statements usually end with ;
.
auto message = "Hello Nyx";auto count = 100;auto active = true;
Data Types
Section titled “Data Types”- Numbers: Double-precision floating-point values.
auto pi = 3.14;auto quantity = 10;
- Strings: Sequences of characters in double quotes (
"
).- Escapes:
\"
(double quote),\\
(backslash). - Literal sequences like
\n
,\r
,\e
in Nyx strings are processed into actual control characters by output functions (output
,put
) and relevant standard library functions when the string is used by them. - Interpolation:
#{expression}
embeds an expression’s string value.
- Escapes:
auto version = "1.0";output("Nyx v#{version}\nRunning...");
- Booleans:
true
orfalse
.
auto isReady = true;
- Lists: Ordered, mixed-type collections in
[]
. Zero-indexed. Negative indices supported.
auto items = [1, "apple", true];output(items[0]); // 1output(items[-1]); // trueauto combined = items + [2.5, "banana"];auto repeated = ["go"] * 2; // ["go", "go"]
Predefined Global Variables
Section titled “Predefined Global Variables”nyx_null
: Represents a null or absent value.
auto data = nyx_null;if (data == nyx_null) { output("Data is null."); }
SCRIPT_ARGS
: A list of command-line arguments passed to the script. (See Getting Started).
Operators
Section titled “Operators”- Arithmetic:
+
,-
,*
,/
,%
- Comparison:
==
,!=
,<
,<=
,>
,>=
- Logical:
and
,or
,not
(keyword),!
(unary) - Assignment:
=
- Postfix Increment/Decrement:
++
,--
(value = counter++;
) - Member Access:
.
(for module members)
Control Flow
Section titled “Control Flow”if/else
: Conditional execution. Parentheses around condition are mandatory.
if (x > 10) { output("Greater"); } else { output("Not greater"); }
for
: C-style loop. Parentheses around clauses are mandatory.
for (auto i = 0; i < 3; i++) { output(i); }
break;
/continue;
: Exit or skip to next iteration of the innermostfor
loop.
Functions
Section titled “Functions”Define with func
. No semicolon needed after }
. Implicitly return nyx_null
if no return
statement is executed.
func multiply(a, b) = { return a * b;}auto product = multiply(6, 7); // product is 42
Built-in Tools
Section titled “Built-in Tools”output(expression);
: Prints the string value ofexpression
, then a newline. Processes\\n
,\\e
, etc., in string expressions.put(expression);
: Likeoutput
, but no trailing newline. Flushes output. Processes\\n
,\\e
, etc.len(collection);
: Returns length of a string or list.@Typedef(expression);
: A statement that prints the type name of the expression’s result (e.g., “NUMBER”, “STRING”).