AI-Native Syntax & Vocabulary
Relevant source files
The following files were used as context for generating this wiki page:
AI-Native Syntax & Vocabulary represents the core design philosophy of Sploosh, where the language's grammar and lexicon are optimized for Large Language Model (LLM) accuracy and "first-shot" generation. The goal is to provide a syntax that fits entirely within a standard LLM system prompt, minimizing ambiguity by ensuring there is only one canonical way to express any given operation.
This design approach inverts traditional human-centric language design. Instead of prioritizing human ergonomics that often lead to multiple syntactic synonyms, Sploosh selects tokens and structures from the most-trained vocabulary across the top dozen programming languages to ensure that LLM completions converge on correct code with minimal context.
Design Principles and LLM Optimization
The vocabulary of Sploosh is strictly limited to tokens that appear frequently in training data for models like Claude, GPT, and Gemini. This reduces the cognitive load on the model and increases the probability of correct code generation.
Core Principles for AI-Native Construction
- One Way to Do Everything: Zero syntactic synonyms or style debates to prevent model "guessing" (README.md:12-14).
- Familiar Vocabulary: Keywords are drawn from high-frequency tokens like
fn,let,match, andimpl(VISION.md:73-75). - Prompt-Loadable Core: The language specification is CI-enforced to stay under specific token budgets to ensure it fits in a single prompt (README.md:16-20).
Token Budget Enforcement
The project utilizes automated scripts to ensure the language remains "AI-native" by monitoring the size of its specification mirrors.
| Mirror Type | Token Limit (cl100k_base) | Purpose |
|---|---|---|
_CORE | 5,600 | General language syntax and standard features |
_WEB3 | 1,500 | Specialized on-chain and smart contract syntax |
Sources: scripts/check_prompt_budget.py:12-16, VISION.md:81-86
Lexical Surface and Keywords
The Sploosh lexer identifies 45 total keywords, divided into 36 reserved keywords and 9 contextual keywords. This limited set ensures that the model does not have to navigate a complex or novel vocabulary.
Reserved Keywords
Reserved keywords are tokens that the lexer always treats as keywords, preventing their use as identifiers to maintain syntactic clarity.
// crates/sploosh-lexer/src/lib.rs:77-113
pub enum Keyword {
Fn, Let, Const, Type, Struct, Enum, Trait, Impl, Mod, Use, Pub, Extern,
If, Else, Match, For, In, While, Loop, Break, Continue, Return,
SelfValue, SelfType, True, False, As, Actor, Spawn, Async, Await,
Select, Move, Onchain, Offchain, Emit,
}
Contextual Keywords
Contextual keywords are only treated as such by the parser in specific positions, allowing them to remain valid identifiers elsewhere. This includes terms like send, recv, storage, and mut (crates/sploosh-lexer/src/lib.rs:152-156).
Numeric and String Literals
Sploosh supports a variety of numeric bases and suffixes common in systems programming, ensuring a familiar surface for models trained on Rust or C++.
- Bases: Decimal, Hexadecimal (
0x), Octal (0o), and Binary (0b) (crates/sploosh-lexer/src/lib.rs:249-255). - Suffixes: Standard width-specific types such as
i128,u256,f64, etc. (crates/sploosh-lexer/src/lib.rs:163-165).
Structural Syntax and Data Flow
The syntax is designed to be explicit, avoiding implicit conversions or hidden control flow that could confuse an AI agent.
Expression Flow Diagram
The following diagram illustrates the relationship between the lexer and parser in generating the Abstract Syntax Tree (AST) from AI-native tokens.
This diagram shows the transformation from source text to a typed AST, highlighting the reliance on a simplified token set.
Sources: README.md:124-135, crates/sploosh-parser/src/lib.rs:12-18
Pipeline and Error Handling
Sploosh uses a pipeline operator |> and the ? error propagation operator to create a clear, linear flow of data, which is highly readable for LLMs.
// README.md:63
let report = input |> parse? |> validate? |> transform?;
On-Chain Vocabulary
For Web3 targets, Sploosh introduces specific structural keywords that enforce blockchain constraints at compile time.
onchain mod: Declares a module for EVM/SVM targets (VISION.md:95-97).storage { }: A specific block within on-chain modules for defining persistent state (README.md:70-73).- Attributes:
@payableand@reentrantprovide explicit metadata for on-chain functions (VISION.md:104-106).
Implementation Architecture
The compiler bootstrap crates are organized to strictly adhere to the specification (§16 EBNF grammar).
The relationship between lexical tokens and the recursive-descent parser ensures that the "AI-native" constraints are enforced during the construction of the AST.
Sources: crates/sploosh-lexer/src/lib.rs:7-21, crates/sploosh-parser/src/lib.rs:32-45
Conclusion
The AI-native syntax and vocabulary of Sploosh prioritize predictable generation over human-centric flexibility. By utilizing a familiar, restricted keyword set and enforcing prompt-sized documentation, Sploosh enables a "prompt → compilable program" workflow. This structure ensures that both the model and the developer have a single, unambiguous source of truth for the language's behavior.