🔧 Lexical Programming Layer (LPL)

Where words compile to law, logic, and running systems.

The Lexical Programming Layer (LPL) is a lightweight, composable DSL and runtime that turns Logoscript / Deuscript semantics into executable artifacts: APIs, workflows, smart contracts, governance rules, identity policies, and telemetry pipelines. It’s the “semantic OS” that makes language actionable, auditable, and portable.


I. Purpose

  • Executable semantics: Turn well-defined terms into deterministic behavior.
  • Interoperability: Compile once, target many (Web2/3 APIs, Solidity/Move, Python/Typescript, policy engines).
  • Traceability: Every statement links back to glyphs, definitions, and consent.
  • Safety: Enforce meaning before execution: no semantics, no run.

II. Mental Model


Logoscript terms → LPL spec → Compiler/Transpiler → Targets (API/Contract/Workflow) ↘ Proofs & Receipts (Semantic Accounting Engine)

Key idea: If a clause can’t be defined, it cannot be executed.


III. Core Concepts

ConceptWhat it isWhy it matters
GlyphToken™Canonical symbol for a term (e.g., TRUST, ENERGY_UNIT)Immutable anchor for meaning
LexemeNamed semantic unit mapped to ontologyDisambiguates language
ClauseDeclarative rule with pre/post conditionsContract/governance atom
RoleActor capability descriptorScoped authority & consent
ContextDomain boundary (energy, law, identity)Prevents cross-domain drift
AssertionMust-hold truth (precondition/invariant)Safety rails
EffectObservable action/outputWhat actually happens
ReceiptCryptographic proof of what ranAuditable memory

IV. Minimal Syntax (LPL)

1) Module Header

“`lpl
module Energy.Governance v1.2
using Logoscript v1.4, Deuscript v0.9
context ENERGY_LEDGER

2) Lexemes

lexeme ENERGY_UNIT := "kWh" glyph:ENERGY.KWH
lexeme CARBON_CREDIT := "tCO2e" glyph:CARBON.TONNE
lexeme TRUST_LEVEL := enum { LOW, MEDIUM, HIGH } glyph:TRUST.LVL

3) Roles & Consent

role OPERATOR requires TRUST_LEVEL >= MEDIUM
role AUDITOR  requires TRUST_LEVEL >= HIGH
consent MODEL := { revocable:true, notify:true, scope:"ENERGY" }

4) Resources / Schemas

resource MeterReading {
  meter_id: string
  quantity: ENERGY_UNIT
  timestamp: datetime
  signature: bytes
}

5) Assertions (Pre/Post/Invariant)

assert pre ValidateSignature(r:MeterReading) by KMS.ED25519
assert inv r.quantity >= 0
assert post LedgerBalance(meter_id) += r.quantity

6) Clauses (Executable Rules)

clause PostReading(r:MeterReading) requires role OPERATOR, consent MODEL {
  when pre all pass
  do   Ledger.Append("ENERGY", r)
  emit Receipt("ENERGY.POST", r.meter_id, r.quantity, r.timestamp)
}

7) Effects & Events

effect EmitCarbonSwap(meter_id, qty:ENERGY_UNIT) {
  let credits = Convert.KWhToTCO2e(qty)
  call CarbonMarket.Mint(meter_id, credits) onchain ETH
  emit Receipt("CARBON.MINT", meter_id, credits)
}

V. Interop Targets (One Spec → Many Backends)

TargetOutput
Web2OpenAPI/JSON Schema + TypeScript/Express scaffold
Web3Solidity/Move contract stubs + ABI + event topics
PolicyOPA/Rego policies or Cedar/IAM JSON
DataSQL/DDL migrations + CDC triggers
AIFunction-calling schemas + validator prompts
TelemetryOTEL pipelines + SIEM rules

LPL ships with adapters: lplc --target openapi|solidity|rego|prisma|otel|cedar


VI. Semantic Accounting Integration

Every execution yields a Receipt:

{
  "id": "rcpt_01HZX8...",
  "module": "Energy.Governance@1.2",
  "clause": "PostReading",
  "inputs": { "meter_id": "M-8801", "quantity": "15.0 kWh" },
  "assertions": ["ValidateSignature:ok","qty>=0:ok"],
  "effects": ["Ledger.Append:ok"],
  "signer": "did:solveforce:ron",
  "hash": "bafy...Qm",
  "timestamp": "2025-08-07T19:04:33Z"
}

Receipts are anchored to the Semantic Accounting Engine for audit & dispute resolution.


VII. Safety Model

  • Fail-closed: missing lexeme/definition → compile error.
  • Typed semantics: units, roles, consent are types, not comments.
  • Determinism: side effects are declared; undeclared effects disallowed.
  • RBAC/ABAC by language: requires role ... compiles to policy.

VIII. Example: Smart Contract from LPL

LPL

module Treasury.Contracts v0.8
lexeme TOKEN := "GLYPH" glyph:TOKEN.GLYPH
role TREASURER requires TRUST_LEVEL >= HIGH

resource Transfer {
  from: did
  to: did
  amount: decimal[TOKEN]
  memo: string?
}

assert pre amount > 0
assert inv Balance(from) >= amount

clause TransferToken(t:Transfer) requires role TREASURER, consent MODEL {
  do   EVM.Token(TOKEN).transfer(t.from, t.to, t.amount)
  emit Receipt("TOKEN.XFER", t.from, t.to, t.amount)
}

Compiles to

  • Solidity function with checks
  • ABI entry + event Receipt
  • Policy binding: only TREASURER can call

IX. EBNF (Compact)

module     = "module", ident, version, { using }, context ;
using      = "using", ident, version ;
context    = "context", ident ;
lexeme     = "lexeme", IDENT, ":=", string, "glyph:", IDENT ;
role       = "role", IDENT, "requires", expr ;
resource   = "resource", IDENT, "{", field, { field }, "}" ;
assert     = "assert", ("pre"|"post"|"inv"), expr ;
clause     = "clause", IDENT, "(", params, ")", "requires", reqs, "{", body, "}" ;
effect     = "effect", IDENT, "(", params, ")", "{", body, "}" ;
expr       = ... ;  // boolean/arith w/ units, roles, consent

X. Logoscript / Deuscript Hooks

  • lexeme lines bind to Logoscript definitions (grapheme → meaning → code).
  • glyph: points to Deuscript axiom nodes for provenance.
  • Compiler refuses ambiguous or undefined glyphs.

XI. Consent & Privacy

consent PII := { revocable:true, encrypt:"KMS", purpose:"BILLING" }
clause ExportPII(d:Customer) requires role AUDITOR, consent PII {
  do DataVault.Export(d).encrypt(KMS)
  emit Receipt("PII.EXPORT", d.id)
}
  • Revocation invalidates future use; receipts keep a non-sensitive hash for audit.

XII. Tooling

  • lplc: CLI compiler/transpiler
  • lpl-validate: static analyzer (units, roles, consent, effects)
  • lpl-prove: generates proof obligations for critical clauses
  • lpl-viz: renders flow/role diagrams (SVG)

XIII. Quick Start (Dev)

# compile to multiple targets
lplc build energy.lpl --target openapi,solidity,rego,otel

# validate and emit receipts schema
lpl-validate energy.lpl --strict

# visualize flow
lpl-viz energy.lpl -o energy.svg

XIV. Versioning & Governance

  • SemVer modules; breaking semantic changes require major bump.
  • Receipts pin module hash.
  • Review gates: clauses tagged critical require multi-sig approval.

XV. Why LPL?

  • Language-first engineering: meaning drives machines.
  • Single source of truth: policy, code, and contracts from one spec.
  • Auditable by design: receipts, proofs, consent.
  • Future-proof: new targets via adapters; semantics remain stable.

In LPL, text is tech.
If it’s not defined, it cannot decide. If it cannot be proven, it must not run.