Language Reference

Complete B3D syntax guide and language specifications

Table of Contents

Program Structure

Every B3D program consists of four main blocks in order:

Syntax: All blocks must appear in this exact order
<Config> // Project configuration project_name = 'project_name' version = '1.0.0' </Config> <Include> // Dependencies and imports include std.io include py:module_name </Include> <Data> // Global variable declarations variable_name = value </Data> <Main> // Program execution logic // Your code here </Main>

Data Types

Basic Types

// Strings name = 'Alice' message = "Hello World" // Numbers age = 25 // Integer pi = 3.14159 // Float // Booleans is_active = true is_complete = false // Null empty_value = null

Collection Types

// Lists/Arrays numbers = [1, 2, 3, 4, 5] names = ['Alice', 'Bob', 'Charlie'] mixed = [1, 'text', 3.14, true] // Dictionaries/Objects person = { 'name': 'Alice', 'age': 30, 'active': true } // Nested structures data = { 'users': [ {'name': 'Alice', 'id': 1}, {'name': 'Bob', 'id': 2} ], 'count': 2 }

Variables

Scope Rules:
  • Variables in <Data> block are global
  • Variables in <Main> and functions are local
  • Local variables can shadow global ones
<Data> global_var = 'I am global' counter = 0 </Data> <Main> // Local variable local_var = 'I am local' // Modify global variable counter = counter + 1 // Shadow global variable global_var = 'I am now local' </Main>

String Interpolation

B3D features powerful string interpolation with {variable} syntax:

Basic Interpolation

name = 'Alice' age = 25 // Simple variable interpolation greeting = 'Hello, {name}!' message = 'You are {age} years old'

Expression Interpolation

// Mathematical expressions next_year = 'Next year you will be {age + 1}' // Function calls current_time = 'Current time: {timestamp()}' // Complex expressions calculation = 'Result: {(10 + 5) * 2}'

Collection Access

scores = [95, 87, 92] person = {'name': 'Alice', 'city': 'New York'} // Array indexing first_score = 'First score: {scores[0]}' last_score = 'Last score: {scores[-1]}' // Dictionary access info = 'Name: {person["name"]}, City: {person["city"]}' // Nested access users = [{'name': 'Alice'}, {'name': 'Bob'}] first_user = 'First user: {users[0]["name"]}'

Functions

Function Definition

defne - Private function (local scope)
defni - Public function (exportable)
// Private function defne calculate_area(width, height): { return width * height } // Public function defni greet_user(name): { return 'Hello, {name}!' } // Function with multiple statements defne process_data(data): { if (data.length > 0): { result = analyze(data) print('Processing complete') return result } else: { return null } }

Function Calls

// Call functions area = calculate_area(10, 5) greeting = greet_user('Alice') // Chain function calls result = process_data(load_data('file.txt'))

Control Flow

Conditional Statements

// If statement if (condition): { // code } // If-else if (age >= 18): { print('Adult') } else: { print('Minor') } // If-elif-else if (score >= 90): { grade = 'A' } elif (score >= 80): { grade = 'B' } elif (score >= 70): { grade = 'C' } else: { grade = 'F' }

Loops

// For loop (iterate over collections) for (item in items): { print('Processing: {item}') } // While loop counter = 0 while (counter < 10): { print('Counter: {counter}') counter = counter + 1 } // Fixed iteration loop with timing loop(5, 1000): { // 5 iterations, 1000ms delay print('Iteration: {loop_index}') } // Infinite loop with control lofini(500): { // 500ms delay between iterations if (lofini_index > 10): { break() } print('Infinite loop: {lofini_index}') }

Loop Control

// Break out of loop for (i in range(100)): { if (i > 5): { break() } print('Number: {i}') } // Special loop variables loop(10): { print('Current iteration: {loop_index}') } lofini(1000): { print('Infinite iteration: {lofini_index}') if (lofini_index >= 5): break() }

Operators

Arithmetic Operators

a + b // Addition a - b // Subtraction a * b // Multiplication a / b // Division a % b // Modulus

Comparison Operators

a == b // Equal a != b // Not equal a < b // Less than a > b // Greater than a <= b // Less than or equal a >= b // Greater than or equal

Logical Operators

a && b // Logical AND a || b // Logical OR !a // Logical NOT

Built-in Functions

// Output print(message) // Print to console print(arg1, arg2, arg3) // Print multiple arguments // Utility timestamp() // Current timestamp break() // Break from loop // Type checking type(variable) // Get variable type length(collection) // Get collection length // String operations upper(string) // Convert to uppercase lower(string) // Convert to lowercase trim(string) // Remove whitespace // Math functions abs(number) // Absolute value max(a, b) // Maximum value min(a, b) // Minimum value round(number) // Round to nearest integer

Python Integration

Including Python Modules

<Include> include py:numpy include py:pandas include py:matplotlib.pyplot include py:requests </Include>

Using Python Functions

// NumPy operations data = numpy.array([1, 2, 3, 4, 5]) mean_value = numpy.mean(data) std_dev = numpy.std(data) // Pandas DataFrames df = pandas.read_csv('data.csv') filtered = df[df['age'] > 18] // HTTP requests response = requests.get('https://api.example.com/data') json_data = response.json() // Matplotlib plotting matplotlib.pyplot.plot([1, 2, 3], [4, 5, 6]) matplotlib.pyplot.savefig('plot.png')

Error Handling

// Try-catch block try: { risky_operation() result = divide(10, 0) } catch (error): { print('Error occurred: {error}') result = 'default_value' } // Nested error handling try: { file_content = read_file('data.txt') try: { parsed_data = parse_json(file_content) } catch (parse_error): { print('JSON parse error: {parse_error}') parsed_data = {} } } catch (file_error): { print('File error: {file_error}') parsed_data = {} }