NERD (No Effort Required, Done) Language

repository·main·Indexed 41 days ago

https://github.com/nerd-lang/nerd-lang-core

An LLM-native intermediate language designed for machine authorship and agentic orchestration. NERD prioritizes token efficiency and native execution via LLVM, featuring built-in capabilities for HTTP requests, JSON handling, LLM calls (Claude), and the Model Context Protocol (MCP). It uses a C-based bootstrap compiler to translate English-word-based source code into LLVM IR and native binaries.

Tokens
3.5K
Snippets
12
Records
19
Agent score
51%

What's inside NERD

  1. Review the NERD development roadmap

    main

    The project is prioritizing agent-first capabilities. Current and upcoming features include:

    Completed:

    • Bootstrap compiler (C, LLVM IR, native binaries)
    • Control flow (if/else, loops, functions)
    • HTTP module (GET, POST)
    • LLM module (Claude API)
    • MCP support (remote tools)
    • Implicit main and .env support

    Near term:

    • JSON parsing and generation
    • String operations
    • SSE / HTTP streaming
    • OpenAI support
    • Improved error messages

    Medium term:

    • Conversation state / multi-turn
    • Human View generator
    • List operations
    • WASM target
  2. Understand the NERD architecture and compilation flow

    main

    NERD is designed as an agent-first, LLM-native language. The architecture follows a multi-layer approach:

    1. Human Layer: Humans provide intent via diagrams or English. Humans do not edit NERD code directly.
    2. AI Layer: LLMs read human intent and existing NERD code to write or modify NERD code. This layer is optimized for token efficiency (50-70% reduction).
    3. NERD Layer: The source code layer consisting of English words, types, functions, and modules, optimized for LLM consumption.
    4. Compiler: Translates NERD into LLVM IR and then into native binaries.
    5. Native Binary: The final executable running on x86_64 or ARM64 with no runtime dependencies.
  3. Understand the NERD Compiler Architecture

    main

    The NERD Bootstrap Compiler uses a traditional three-stage pipeline written in pure C:

    1. Lexer: Converts source text into tokens (English words to tokens).
    2. Parser: Builds an Abstract Syntax Tree (AST) from the tokens.
    3. Codegen: Generates LLVM IR from the AST.

    Dependencies:

    • The compiler itself requires only libc.
    • The runtime libraries (for HTTP, MCP, and LLM features) require libcurl.
    • To turn IR into native code, you need LLVM/clang.
  4. How NERD compiles to native code

    main

    NERD follows a compilation pipeline that transforms high-level English-word-based code into native binaries via LLVM:

    1. Lexer: Tokenizes English words into a token stream.
    2. Parser: Builds an Abstract Syntax Tree (AST) from the tokens.
    3. Codegen: Generates LLVM IR from the AST.
    4. LLVM/Clang: Compiles the LLVM IR into a native binary.

    To manually compile a file to LLVM IR for use with clang:

    ./nerd compile path/to/file.nerd -o output.ll
    clang -O2 output.ll -o output_binary
  5. Understand the NERD programming paradigm

    main

    NERD (No Effort Required, Done) is an LLM-native intermediate language designed for machine authorship rather than human editing. Unlike traditional languages (TypeScript, Python) optimized for human readability, NERD is optimized for LLM token efficiency and native execution.

    Core Principles

    • Machine Authorship: Humans act as stakeholders and reviewers, not authors. You do not edit NERD code directly; you instruct an AI to modify it.
    • Token Efficiency: NERD uses dense, English-like words that map to single tokens in LLM tokenizers, avoiding the fragmentation caused by symbols like {, }, or ===.
    • Human Observability: While humans cannot edit the source, they interact with a "translated view"—a high-level, read-only representation (often text-based or diagrammatic) that explains logic, data flow, and constraints.
    • Native Execution: NERD code compiles to native code via LLVM.

    Comparison of Workflow

    StepTraditional WorkflowNERD Workflow
    AuthoringHuman writes codeAI writes NERD
    EditingHuman edits linesHuman instructs AI
    ReviewHuman reads sourceHuman observes translated view
    ExecutionInterpreted/CompiledCompiles to native via LLVM
  6. Install the NERD compiler on macOS (Apple Silicon)

    main

    To install the latest NERD compiler on macOS with Apple Silicon, download the pre-compiled binary via curl and extract it using tar.

    curl -L https://github.com/Nerd-Lang/nerd-lang-core/releases/latest/download/nerd-darwin-arm64.tar.gz | tar -xz
    cd nerd-darwin-arm64 && ./nerd --version
  7. Install NERD on macOS Apple Silicon

    main

    To get started on macOS Apple Silicon, download the pre-compiled binary, extract it, and run your first program. You can also move the binary to /usr/local/nerd and update your PATH for global access.

    Quick Install

    # Download and extract
    curl -L https://github.com/Nerd-Lang/nerd-lang-core/releases/latest/download/nerd-darwin-arm64.tar.gz | tar -xz
    cd nerd-darwin-arm64
    
    # Run a test program
    echo 'out "Hello from NERD"\nout five plus three' > hello.nerd
    ./nerd run hello.nerd

    Global Installation

    sudo mv ../nerd-darwin-arm64 /usr/local/nerd
    echo 'export PATH="$PATH:/usr/local/nerd"' >> ~/.zshrc
    # Download and extract
    curl -L https://github.com/Nerd-Lang/nerd-lang-core/releases/latest/download/nerd-darwin-arm64.tar.gz | tar -xz
    cd nerd-darwin-arm64
    
    # Write a program
    echo 'out "Hello from NERD"
    out five plus three' > hello.nerd
    
    # Run it
    ./nerd run hello.nerd
  8. Compile NERD to a Native Binary

    main

    The NERD compiler generates LLVM IR (.ll files) rather than machine code directly. To create a runnable native binary, you must use clang to compile the generated IR. If your program requires a test harness, concatenate the program IR and the harness IR before compiling.

    Workflow:

    1. Generate LLVM IR using ./nerd compile.
    2. (Optional) Concatenate IR files using cat.
    3. Compile the resulting IR with clang -O2.
    # Compile NERD to LLVM IR
    ./nerd compile ../examples/math.nerd -o math.ll
    
    # Build native binary (with test harness)
    cat math.ll test_math.ll > combined.ll
    clang -O2 combined.ll -o math
    ./math
  9. Build NERD from source

    main

    To build the compiler from source, you need a C compiler and clang installed (e.g., via xcode-select --install on macOS). The build process uses a bootstrap directory.

    git clone https://github.com/Nerd-Lang/nerd-lang-core.git
    cd nerd-lang-core/bootstrap
    make
    ./nerd --version
    git clone https://github.com/Nerd-Lang/nerd-lang-core.git
    cd nerd-lang-core/bootstrap
    make
    ./nerd --version
  10. Compare NERD syntax with TypeScript

    main

    NERD achieves significant token savings (50-70%) by replacing verbose syntax and symbols with dense, single-token English words. This makes generation cheaper and allows more code to fit within LLM context windows.

    Basic Math Example

    TypeScript:

    function add(a, b) { return a + b; }
    function sub(a, b) { return a - b; }
    function mul(a, b) { return a * b; }
    function div(a, b) { return a / b; }

    NERD:

    fn add a b
    ret a plus b
    
    fn sub a b
    ret a minus b
    
    fn mul a b
    ret a times b
    
    fn div a b
    ret a over b

    Result: ~67% fewer tokens.

    Complex Logic Example (Calculator)

    TypeScript:

    type Input = { a: number; b: number; op: number };
    type Result = { ok: number } | { err: string };
    
    function calc(input: Input): Result {
      if (input.op === 0) return { ok: input.a + input.b };
      if (input.op === 1) return { ok: input.a - input.b };
      if (input.op === 2) return { ok: input.a * input.b };
      if (input.op === 3) return { ok: input.a / input.b };
      return { err: "unknown" };
    }

    NERD:

    type input num num int
    type result ok num or err str
    
    fn calc input result
    if third eq zero ret ok first plus second
    if third eq one ret ok first minus second
    if third eq two ret ok first times second
    if third eq three ret ok first over second
    ret err unknown

    Result: ~59% fewer tokens.