Objective:
Our objective is to design a Procedure-Oriented, Purpose-Based Programming Language called Solunox
, implemented in C++ using a Tree Walk Interpreter. This language serves as an educational tool for mastering Data Structures and Algorithms.
A Tree Walk Interpreter in Solunox
consists of three core components: Lexing, Parsing, and Output Generation.
- Lexing: The lexer converts the source script into a sequence of tokens.
- Parsing: The parser accepts the token array, constructs an Abstract Syntax Tree (AST), and performs semantic analysis.
- Output Generation: The code is interpreted by traversing the AST, which gives the interpreter its name.
Solunox
is designed with the unique feature of having no variables. This design choice encourages users to become proficient with data structures such as Stacks, Queues, Linked Lists, Trees, and Graphs. The language uses three primary containers whose combinations enable computation. Additionally, an immutable vector is provided for storing and passing data without modifying it.
These versatile containers can dynamically take on the roles of Stacks, Queues, or Priority Queues.
Operations:
cont << value
: Pushvalue
ontocont
.cont << input("Enter data")
: Insert user input intocont
.cont
: Retrieve the top element ofcont
.print(cont)
: Print the top element ofcont
.cont = value
: Set the top element ofcont
tovalue
.cont1 -> cont2
: Pop fromcont1
and push tocont2
.cont1 - n -> cont2
: Pop the lastn
elements fromcont1
and push tocont2
.cont -> n
: Pop and delete the lastn
elements fromcont
.cont?
: Returnfalse
ifcont
is empty, otherwisetrue
.
Functions are declared with:
$functionName() { /* body */ }
- If-Else:
if (condition) { /* code */ } else { /* code */ }
- Loop: Continuous loop until
break
. - Switch-Case: Evaluate an expression, match cases, with a default case.
Solunox
supports the following operations:
+
, -
, *
, /
, &&
, ||
, !
, ==
, !=
, <
, >
.
Each function has an immutable array constas
that stores data but does not allow modifications directly (changes are made via containers).
constas << value
: Pushvalue
ontoconstas
.constas?
: Return the length of the array, or0
if it is empty.constas[3]
: Retrieve the third element fromconstas
.
- Global Scope:
Solunox
does not support a global scope. - Function Scope: Each function has its own scope with a unique set of stacks and arrays.
Containers start as stacks by default and can be changed using ~spq~
. Containers must be empty before changing types.
cont~s;
: Convertcont
to a Stack.cont~q;
: Convertcont
to a Queue.cont~p;
: Convertcont
to a Priority Queue.
Solunox
supports Linked Lists, Graphs, and Trees. Their references can be stored in existing data structures and used as needed.
sol << new (SLL/DLL/CLL/TREE/HEAP/GRAPH)
: Create a new data structure.*sol
: Return the value stored insol
.sol ->
: Point to the child node.sol <-
: Point to the parent node.sol ->[0]
: Point to the first node in a tree/graph.a<->b
: Connect nodes (specific to Graphs).