Skip to the content.

struixLang Documentation

Table of Contents


About struixLang

struixLang is a stack-based, case-insensitive programming language implemented in Python 3. It operates on a stack, which is a list of objects that the program manipulates. The language also utilizes a dictionary containing words (functions or commands) that can be executed within a program.

struixLang includes a rich set of built-in words and provides mechanisms for defining new user-defined words within the language itself.


Use Cases

struixLang is ideal for:


Getting Started

To run the struixLang interpreter, execute the repl.py file using Python 3:

python3 repl.py

Alternatively, you can integrate the interpreter into your own Python programs:

import struixTerp
import struixPrimitives

# Create a new interpreter instance
terp = struixTerp.Terp()

# Add built-in words to the interpreter
struixPrimitives.AddWords(terp)

# Run struixLang code
terp.run("""
    var a
    a = 10
    "The value of a is:" print
    a fetch print
""")

Data Types

struixLang supports the following data types:


Core Concepts

The Stack

At the heart of struixLang is the stack. The stack operates on a Last-In-First-Out (LIFO) principle. Items are pushed onto the stack and popped off the stack during operations.

Words (Commands)

Words are the commands or functions in struixLang. They manipulate the stack or perform actions.

Variables and Constants

Comments

Comments are used to include explanatory notes in the code and are ignored during execution.


Basic Operations

Input and Output

Mathematical Operations

struixLang uses postfix notation (Reverse Polish Notation) for operations.

Stack Manipulation


Advanced Operations

Logical Operations

Logical operations in struixLang work with boolean values (true and false).

Bitwise Operations

String Manipulation

Multiline Strings

Lists and Arrays

Control Structures


Built-in Functions

Mathematical Functions

Time and Date Functions

Random Number Generation

File Input/Output

Networking Functions


Examples

Hello, World

"Hello, World!" print

Factorial Calculation

var n
"Enter a number:" print
input n store
var result
1 result store

[ n fetch 1 > ]  # Condition
[
  n fetch result fetch * result store
  n fetch 1 - n store
] while

"Factorial is:" print
result fetch print

Fibonacci Sequence

var a
var b
var temp
0 a store
1 b store
10 var count count store  # Number of terms

[ count fetch 0 > ]  # Condition
[
  a fetch print
  b fetch a store
  a fetch b fetch + b store
  count fetch 1 - count store
] while

File Reading

"r" "data.txt" open_file var file file store
file fetch read_file print
file fetch close_file

Conclusion

struixLang is a versatile and powerful stack-based programming language that provides a rich set of features for both simple and complex programming tasks. Its simplicity and extensibility make it suitable for a wide range of applications, from scripting and automation to educational purposes.