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
| Concept | What it is | Why it matters |
|---|---|---|
| GlyphToken™ | Canonical symbol for a term (e.g., TRUST, ENERGY_UNIT) | Immutable anchor for meaning |
| Lexeme | Named semantic unit mapped to ontology | Disambiguates language |
| Clause | Declarative rule with pre/post conditions | Contract/governance atom |
| Role | Actor capability descriptor | Scoped authority & consent |
| Context | Domain boundary (energy, law, identity) | Prevents cross-domain drift |
| Assertion | Must-hold truth (precondition/invariant) | Safety rails |
| Effect | Observable action/output | What actually happens |
| Receipt | Cryptographic proof of what ran | Auditable 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)
| Target | Output |
|---|---|
| Web2 | OpenAPI/JSON Schema + TypeScript/Express scaffold |
| Web3 | Solidity/Move contract stubs + ABI + event topics |
| Policy | OPA/Rego policies or Cedar/IAM JSON |
| Data | SQL/DDL migrations + CDC triggers |
| AI | Function-calling schemas + validator prompts |
| Telemetry | OTEL 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
TREASURERcan 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
lexemelines 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
criticalrequire 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.