Skip to content

how_it_works

BlidDev edited this page Jan 9, 2024 · 3 revisions

How it works

Before starting to code in Niv, it is really important to know how some core language aspects work.


The node system

By definition, everything in a Niv script is a node. Nodes are separated by whitespaces and can be divided into 2 types:

  • Value: A simple value such as a number or a string.

  • Nived: A node that holds other nodes, marked by surrounding (), most often a command such as (cal 1 + 1).

All nested nodes can and will be traversed util they return a Value node, for example:

// The following line
// (The reason `set` is not surrounded by `()` is because 
// the first node is always considered a nested one)

set my_variable (cal 1 + (cal 3 * 5))

// Will convert into

set my_variable (cal 1 + 15)
// |
// V
set my_variable 16
// The `set` command returns the variable value so:

16

How Niv destiguishes between data types

By default, Niv's parser consideres every value node to be a string data type (even values that are not surrounded by quotes). Then the parser goes over the value nodes and checks if it can be determined as another data type such as I32. It is also important to note that the only way to define a CHAR rather than a single character STR is by surrounding your character with ''.

Clone this wiki locally