SESI LANGUAGE SPECIFICATION
โŒ•

Sesi Language - Complete Implementation Summary

๐Ÿ“‹ Overview

Sesi is a highly legible, buildable programming language. It provides clean primitives for executing robust internal logic and external APIs, acting as the ideal layer to parse text, orchestrate shell commands, and interact with the file system. Unlike traditional languages, Sesi integrates command execution naturally, enabling developers to build context-aware scripts with minimal boilerplate.

๐ŸŽฏ Design Philosophy

  1. Practical Over Perfect: Focus on what developers actually need, not theoretical completeness.
  2. Transparency Over Magic: Sesi runs exactly what you write with clear costs and execution maps.
  3. Simplicity First: A custom tree-walking interpreter for clarity and maintainability.
  4. Type Safety with Flexibility: Static types for normal code, runtime checking for integration outputs.

๐Ÿ”ง Technology Stack

Component Technology Rationale
Language TypeScript Type safety, IDE support, easy debugging
Runtime Node.js 18+ Wide availability, async support
Reasoning Gemini 3.1 Latest models, 1M token context, fast
SDK @google/genai Official, well-maintained, async-first
Parser Recursive descent Simple, readable, extensible
Execution Tree-walking interpreter Easy to understand and modify
Testing Typescript Standard Node.js test framework

Why a tree-walking interpreter?

  • Simplicity: Easy to understand, modify, extend
  • Debugging: Can print AST and execution steps
  • Iteration: No compilation overhead, fast development
  • Good enough: Performance is adequate for v1+

Why recursive descent parser?

  • Clarity: Each grammar rule is a function
  • Flexibility: Easy to add new constructs
  • Error recovery: Can synchronize after errors
  • No dependencies: No external parser generators

Why Gemini specifically?

  • Instruction following: Excellent at understanding prompts
  • Function calling: Built-in tool use support
  • Context window: 1M tokens for long documents
  • Cost: Competitive pricing
  • Availability: Easy to use via official SDK

๐ŸŒŸ Language Features (V1)

Core Language โœ…

Variables & Bindings

let x = 10
let PI = 3.14159
let y  // null initially

Functions

fn add(a: number, b: number) -> number {return a + b}

fn greet(name: string = "World") {print "Hello, " + name}

Control Flow

if condition { ... } else { ... }
while condition { ... }
for x = 0 to 10 { ... }
for item in array { ... }
try { ... } catch (e) { ... }

Operators

  • Arithmetic: +, -, , /, %
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: &&, ||, !
  • Assignment: =

Data Types

  • Primitives: number, string, bool, null
  • Collections: array, object
  • Functions: First-class values
  • Union types: T | U
  • Optional: T?

Scoping

  • Lexical scoping with environment chain
  • Block scope for loops/conditionals
  • Closure support

Prompt Blocks

prompt greeting {"Hello, " name "!"}

Structured Output

let rawJson = "{\"projectName\": \"Sesi\", \"version\": \"1.5.5\", \"status\": \"active\"}"
let parsedRegistry = structured_output({projectName: string, version: string, status: string})(rawJson)

Integrated Reasoning Features โœ…

Reasoning Calls

let response = model("gemini-3-flash-preview") {temperature: 0.7, max_tokens: 1000} {"Your prompt here"}

Web Search Grounding

let response = model("gemini-3.1-flash-lite") {search, max_tokens: 1000} {"What is the weather in Tokyo?"}

Image Generation

let logo = image("gemini-3.1-flash-image") {ratio: "1:1", size: "512"} {"Your prompt here"}
write_image("logo.png", logo)

Temporal Context Injection โœ…

Every reasoning call automatically includes the current UTC date and time in its context, providing the script with a native sense of "now."

Implicit Statement Termination โœ…

Expressions ending in } (such as prompt blocks) no longer strictly require an escape character or semicolon to terminate, allowing for cleaner one-line or multi-line syntax.

Async Polling for MAX_TOKENS โœ…

The runtime natively polls the model if it hits a MAX_TOKENS finish status during large generation tasks.

Tool Calling

let result = tool_call(functionName)(model(gemini-3.1-flash-lite) {"Your prompt here"})

Memory

memory conversation {"Initial context"}
conversation = conversation + "User: How are you?"
print("Current Conversation Memory:")
print(conversation)

// Demonstrate using the memory in a model call
print("Calling model with memory context...")
let response = model("gemini-3-flash-preview") {conversation}
print("Reasoning Response:", response)

๐ŸŒ Built-in Global Variables

  • args (array): Contains the command-line arguments passed to the script, excluding Sesi runtime options and the script path.

๐Ÿ› ๏ธ Built-in Functions

I/O

  • print(...args)
  • read_file(path)
  • write_file(path, content)
  • write_image(path, content)
  • list_dir(path)
  • make_dir(path)
  • spawn(path)
  • exec(command)
  • time()
  • random()
  • debug()

Type & Conversion Functions

  • type(value)
  • str(value)
  • to_json(value)
  • from_json(string)
  • num(value)
  • bool(value)
  • convert(type) { config } { file }

Collection Functions

  • len(collection)
  • push(array, value)
  • pop(array)
  • join(array, sep)
  • split(string, sep)
  • keys(object)
  • values(object)
  • range(n)

Network

  • web_get(url, headers)
  • web_send(url, body, headers)
  • listen(port, handler)
  • api(port, handler)
  • live(filePath, exportName)

Concurrency

  • multi_req(fns)

Tools

  • define_tool(name, fn, description)
  • list_tools()
  • tool_call(name)(...)

Reasoning

  • workflow(steps, input)
  • set_alias(alias, model)

Error Handling

  • error_type(type, message, data)
  • raise_error(type_or_error, message, data)

Math

  • exp(x)

Standard Library Modules

Sesi supports importing standard utility library modules natively at runtime:

  • std/math: Constants PI, E, and functions sin, cos, tan, sqrt, floor, ceil, abs, pow, log, exp
  • std/time: now(), sleep(ms), and format(timestamp, options) for timezone/locale formatting
  • std/json: stringify(val) and parse(str)
  • std/audio: play, beep, synth, save, sequence, mix for sound synthesis. Upgraded to a professional DSP backend with Stereo Panning, ADSR Envelopes, Low-Pass Filtering, Soft-Clipping, physical modeling drums (kick, snare, hat, clap), and sf2 (High-speed FluidSynth batch-rendering for SoundFonts).
  • std/theory: chord(root, type), scale(root, type), transpose(notes, steps), duration(minutes, seconds), and bar(bars, bpm, beatsPerBar?) for algorithmic composition, timing conversions, and harmonic logic.
  • std/draw: Upgraded SVG generation library supporting complex shapes (ellipse, polygon, path), definition management (gradient, style), inline XML (raw), formatting/indentation, and class/attribute mappings via optional trailing options dictionaries.
  • std/db: db_open(filename, password?) returning a Document Database instance (with automatic AES-256-CBC disk encryption if a passphrase is provided) supporting collections and CRUD operations:

- db.collection(name) -> Collection object

- collection.insert(document)

- collection.find(query?)

- collection.update(query, update_obj)

- collection.delete(query)

๐Ÿ“Š Implementation Statistics

Metric Value
Total lines of code ~4,000
Source files 9
Documentation pages 23
Example programs 31
Built-in functions 50+
Supported operators 20+
AST node types 30+
Token types 50+

๐Ÿš€ Getting Started

Installation

cd Sesi
npm install
npm run build
npm install -g .

Run Example

sesi examples/main/01_hello.sesi

Run with Reasoning

sesi examples/optional/08_model_call.sesi

Run Tests

npm test

๐Ÿ’ก Key Implementation Details

Lexer Design

  • Character-by-character scanning
  • Keyword recognition
  • String/number literal parsing
  • Comment stripping
  • Position tracking for error messages

Parser Design

  • Recursive descent parsing
  • Expression precedence (11 levels)
  • Error recovery via synchronization
  • Full AST construction
  • Support for all language constructs

Interpreter Design

  • Tree-walking evaluation
  • Environment chain for scoping
  • Async support for reasoning calls
  • Control flow exceptions (return, break, continue)
  • Built-in function dispatch

Reasoning Runtime Design

  • Async Gemini API calls (via @google/genai)
  • Response parsing and validation
  • Memory buffer management
  • Structured output JSON extraction with automatic schema simplification
  • Automatic injection of current UTC date/time context
  • Graceful error handling

๐Ÿ“š Documentation Coverage

โœ… SPECIFICATION.md (600+ lines)

  • Complete language grammar
  • All language constructs
  • Type system details
  • Built-in functions
  • Runtime semantics
  • Module system design

โœ… ARCHITECTURE.md (400+ lines)

  • Component stack diagram
  • Execution flow explanation
  • Scope management
  • Type system details
  • Reasoning integration flow
  • Error handling strategy
  • Performance characteristics

โœ… BUILTINS.md (450+ lines)

  • Complete function reference
  • Usage examples
  • Return value documentation
  • Performance notes
  • Standard library plans

โœ… REASONING.md (500+ lines)

  • Systems reasoning overview
  • Prompt blocks explained
  • Model call configuration
  • Structured output guide
  • Memory system details
  • Practical patterns
  • Error handling
  • Performance tips

โœ… ROADMAP.md (400+ lines)

  • V1.0 features (Complete)
  • V1.5 improvements (Complete)
  • V2.0 async & advanced reasoning (Q3-Q4 2026)
  • V3.0 systems framework
  • V4.0+ vision
  • Community involvement
  • Backwards compatibility

๐ŸŽ“ Example Programs

File Demonstrates
main/01_hello.sesi Basic print
main/02_variables.sesi Variables and operations
main/03_functions.sesi Functions, parameters, defaults
main/04_conditionals.sesi If/else logic
main/05_loops.sesi While, for, for-in
main/06_arrays_objects.sesi Collections and indexing
main/07_prompts.sesi Prompt blocks
optional/08_model_call.sesi Basic reasoning calls
main/09_structured_output.sesi Structured output
optional/10_code_generation.sesi Code generation
main/11_memory_storage.sesi Multi-turn with memory
main/12_classification.sesi Classification
main/13_data_pipeline.sesi Data pipeline
optional/14_folder_explainer.sesi Directory parsing & reasoning
optional/15_image_generation.sesi Image generation
main/16_modules.sesi Imports/exports & std namespaces
main/17_http_client.sesi HTTP GET and POST operations
main/18_parallel_requests.sesi Parallel request concurrency
main/19_search_web.sesi Web search integration
optional/20_model_aliases.sesi Custom model naming aliases
main/21_custom_tools.sesi Custom runtime tool definitions
optional/22_reasoning_plus_custom_tools.sesi Compose reasoning & tools
main/23_file_conversion.sesi Document and media conversion via convert()
main/24_http_server.sesi Native async HTTP server (listen, live)
main/24_http_handler.sesi Dynamic routing HTTP handler
main/25_webpage_server.sesi High-performance dynamic HTML site rendering
main/26_database.sesi Embedded Document Database (std/db) crud operations
main/27_robust_web_db.sesi Secured combined API server backed by persistent DB
optional/28_streaming.sesi Streaming API responses
main/29_tool_piping.sesi Tool-chaining and data pipelining
main/30_error_recovery.sesi Robust error handling and retry policies
main/31_synthesizer.sesi Music and SVG native capabilities

๐Ÿ”ฎ Future Directions

V2: Async & Advanced Logic

  • Async/await
  • Streaming responses
  • Advanced memory with embeddings
  • finally blocks, custom error types, retry policies, timeout handling

V3: Systems Framework

  • System state machines
  • Multi-process collaboration
  • Knowledge base integration
  • RAG (Retrieval-Augmented Generation)

V4+: Scale & Optimization

  • Bytecode compilation
  • JIT compilation
  • Distributed execution
  • Cross-model orchestration

๐Ÿงช Testing Strategy

Component Testing

  • Lexer: Token stream correctness
  • Parser: AST structure correctness
  • Interpreter: Evaluation correctness

Example Coverage

  • 31 complete example programs
  • Covers all major language features
  • Demonstrates reasoning integration
  • Real-world use cases

๐Ÿ“– Learning Path

  1. Start: QUICKSTART.md - Get running in 5 minutes
  2. Builtins: BUILTINS.md - Built-in functions
  3. CLI: CLI.md - Complete CLI flags & parametric execution guide
  4. Basics: examples/main/01-06 - Core language features
  5. Prompts: examples/main/07 - Prompt blocks
  6. Reasoning: examples/optional/08, examples/main/09, examples/optional/10, examples/main/11-12 - Reasoning feature exploration
  7. Advanced: REASONING.md - Patterns and best practices
  8. Systems: examples/main/13, examples/optional/14 - Systems reasoning and data pipelines
  9. Modules: examples/main/16 - Modules & std library namespaces
  10. Image Generation: IMAGE_GENERATION.md examples/optional/15 - Generating images natively
  11. Concurrency: examples/main/17-18 - Concurrency & coordination
  12. Web Search: examples/main/19 - Web search integration
  13. Model Aliases: examples/optional/20 - Custom model naming aliases
  14. Custom Tools: examples/main/21, examples/optional/22 - Custom runtime tool definitions and compose reasoning with custom tools
  15. Specification: SPECIFICATION.md - Complete grammar
  16. Architecture: ARCHITECTURE.md - How it works
  17. Roadmap: ROADMAP.md - Future vision

๐Ÿค Contributing Path

  1. Report bugs with minimal examples
  2. Suggest language features via RFCs
  3. Add built-in functions
  4. Improve documentation
  5. Submit example programs
  6. Help with test coverage

๐ŸŽ What's Included

  • โœ… Complete interpreter (3000+ lines of TypeScript)
  • โœ… Full language specification (600+ lines)
  • โœ… Architecture documentation (400+ lines)
  • โœ… API reference (450+ lines)
  • โœ… Systems reasoning guide (500+ lines)
  • โœ… Development roadmap (400+ lines)
  • โœ… 30+ example programs
  • โœ… CLI executable
  • โœ… Test suite
  • โœ… Quick start guide

๐Ÿ“ Next Steps

  1. Build and install: npm install && npm run build && npm install -g .
  2. Try examples: sesi examples/main/01_hello.sesi
  3. Set up Reasoning: Set GEMINI_API_KEY in .env
  4. Explore Reasoning: sesi examples/optional/08_model_call.sesi
  5. Read docs: Start with SPECIFICATION.md
  6. Write programs: Create your own .sesi files
  7. Check roadmap: See where language is headed

๐Ÿš€ Philosophy

"Sesi demonstrates that coding shouldn't need to be hard to understand, eliminating the boilerplate of traditional development and lowering the entry-level for those interested in code or programming."

The language is designed to evolve. V1+ provides a solid foundation. V2+ adds power. The architecture supports this gracefully without breaking existing programs.


Status: โœ… Complete V1.5 implementation

Ready for: File manipulation and process orchestration

Not ready for: Massive-scale production (until v2.0 bytecode)

Next milestone: V2.0 (Async & advanced reasoning)

Sesi is not just an experiment in language design. Use it to learn, explore, and evolve what the future of coding will become.


For more information, see the documentation in docs/ and examples in examples/.