Stremax-Lang is a simple programming language designed specifically for blockchain development and smart contract execution. It provides a clean syntax and built-in primitives for common blockchain operations.
- Simple, expressive syntax
- Built-in blockchain primitives (addresses, transactions, etc.)
- Smart contract support
- Type safety for blockchain operations
- Easy integration with existing blockchain platforms
- Proper block scoping for variables
- Logical operators with short-circuit evaluation
- ✅ Lexer: Tokenizes source code into tokens
- ⏳ Parser: Partially implemented, needs completion
- ⏳ Interpreter: Basic structure implemented, needs completion
- ✅ Blockchain: Basic blockchain implementation with blocks, transactions, and mining
- ✅ Smart Contracts: Basic smart contract implementation with state, functions, and events
- ✅ CLI: Command-line interface for running Stremax-Lang programs
- ✅ Block Scoping: Variables defined in blocks are now properly scoped
- ✅ Boolean Literals: Direct support for boolean literals (true/false)
- ✅ Logical Operators: Support for logical AND (&&) and OR (||) with short-circuit evaluation
- ✅ Functions: Support for function declarations, calls, closures, and recursion
- ✅ String/Integer Concatenation: Enhanced support for string concatenation with different types
- ✅ Arrays: Support for array literals, array access, and nested arrays
- ✅ Maps: Support for map/hash/dictionary literals with string, integer, or boolean keys
cmd/stremax: Command-line tools for the languagepkg/lexer: Lexical analyzer for tokenizing source codepkg/parser: Parser for building abstract syntax treespkg/interpreter: Interpreter for executing Stremax-Lang codepkg/blockchain: Blockchain-specific functionalityexamples: Example programs written in Stremax-Lang
// Contract definition
contract TokenContract {
// State variables
state {
owner: Address
totalSupply: Int
balances: Map<Address, Int>
}
// Constructor
constructor(initialSupply: Int) {
owner = msg.sender
totalSupply = initialSupply
balances[owner] = initialSupply
}
// Functions
function transfer(to: Address, amount: Int) {
require(balances[msg.sender] >= amount, "Insufficient balance")
balances[msg.sender] -= amount
balances[to] += amount
emit Transfer(msg.sender, to, amount)
}
// Events
event Transfer(from: Address, to: Address, amount: Int)
}
Int: Integer valuesString: String valuesBool: Boolean values (true/false)Address: Blockchain addresses
- Arithmetic:
+,-,*,/ - Comparison:
==,!=,<,> - Logical:
&&(AND),||(OR),!(NOT)
Address: Represents a blockchain addressMap<K, V>: Key-value mapping (e.g.,Map<Address, Int>for balances)
contract ContractName {
// State variables
state {
variable1: Type
variable2: Type
// ...
}
// Constructor
constructor(param1: Type, param2: Type) {
// Initialization code
}
// Functions
function functionName(param1: Type, param2: Type): ReturnType {
// Function body
}
// Events
event EventName(param1: Type, param2: Type)
}
msg.sender: The address that called the current functionmsg.value: The amount of cryptocurrency sent with the function callnow(): The current timestamp
if (condition) { ... } else { ... }: Conditional executionrequire(condition, "error message"): Assert a condition or revert the transaction
emit EventName(arg1, arg2): Emit an eventaddress.transfer(amount): Transfer cryptocurrency to an addressaddress.send(amount): Send cryptocurrency to an address (returns success/failure)
See the examples directory for basic examples demonstrating language features:
- Variable assignment and arithmetic
- String operations
- Conditional expressions
- Boolean operations and logical operators
- Error handling
- Block scoping
See these examples for more complex use cases (not fully supported yet):
- examples/token.sx: An ERC20-like token implementation
- examples/voting.sx: A voting contract implementation
- examples/auction.sx: An auction contract implementation
# Clone the repository
git clone https://github.com/Stremax-Team/stremax-lang.git
cd stremax-lang
# Build the compiler
go build -o stremax ./cmd/stremax# Run a program
./stremax run -file ./examples/simple.sx# Deploy a contract to a blockchain (not implemented yet) (result with error)
./stremax deploy -file ./examples/token.sxContributions are welcome! Please feel free to submit a Pull Request.
The API documentation is available on pkg.go.dev. This documentation is automatically generated from the code comments.
To write good documentation comments:
- Every exported function, type, and variable should have a comment
- Comments for functions should explain what the function does, its parameters, and its return values
- Use complete sentences that start with the name of the thing being described
- Follow the Go Documentation Comments guidelines
Example of a well-documented function:
// ParseProgram parses the input source code and returns an AST representation.
// It returns nil and populates the Errors slice if any parsing errors occur.
func (p *Parser) ParseProgram() *Program {
// Implementation...
}MIT