Définition K expérimentale
Le sous-langage compte quatre lemmes : les littéraux entiers et booléens, +, < et select.
// SPDX-FileCopyrightText: 2026 Cyprien PIERRE
// SPDX-License-Identifier: CECILL-2.1
//
// Integer and boolean literals of the experimental K7PL subset, and the
// partial classifier that the other lexemes of this directory extend.
// Normative source: spec/Spec/C5.lean and spec/Spec/C6.lean (repository-relative paths).
module LITERALS
imports INT
imports BOOL
imports K-EQUAL
// K7PL Chapter 5 uses prefix S-expressions. Builtin Int and Bool values
// are subsorts of K7Exp, avoiding duplicate syntax for literal tokens.
syntax K7Exp ::= Int
| Bool
// Only values may close the strictness contexts generated by K.
syntax KResult ::= Int | Bool
// Partial classifier for the two base types in this prototype.
syntax K7Type ::= "IntType" [symbol(k7IntType)]
| "BoolType" [symbol(k7BoolType)]
| typeOf(K7Exp) [function]
// Partial classifier; ill-typed expressions have no typeOf result.
// This is not the complete K7PL typing judgment.
rule typeOf(_I:Int) => IntType
rule typeOf(true) => BoolType
rule typeOf(false) => BoolType
endmodule
// SPDX-FileCopyrightText: 2026 Cyprien PIERRE
// SPDX-License-Identifier: CECILL-2.1
//
// The lexeme `+`, the layer 3 glyph whose alias is `add` (chapter 1, table of glyphs).
// Its production keeps the parentheses of the experimental subset.
requires "literals.k"
module ADD
imports LITERALS
syntax K7Exp ::= "(" "+" K7Exp K7Exp ")" [symbol(k7Add), strict]
// Chapter 5 arithmetic example family. The rule uses the source production
// itself; k7Add is an internal label, not source syntax.
rule (+ I:Int J:Int) => I +Int J [label(k7AddEval)]
rule typeOf((+ E1:K7Exp E2:K7Exp)) => IntType
requires typeOf(E1) ==K IntType andBool typeOf(E2) ==K IntType
endmodule
// SPDX-FileCopyrightText: 2026 Cyprien PIERRE
// SPDX-License-Identifier: CECILL-2.1
//
// The lexeme `<`, the layer 3 glyph whose alias is `lt` (chapter 1, table of glyphs).
// Its production keeps the parentheses of the experimental subset.
requires "literals.k"
module LT
imports LITERALS
syntax K7Exp ::= "(" "<" K7Exp K7Exp ")" [symbol(k7Lt), strict]
// Comparison returns a builtin Bool value injected into K7Exp.
rule (< I:Int J:Int) => I <Int J [label(k7LessThanEval)]
rule typeOf((< E1:K7Exp E2:K7Exp)) => BoolType
requires typeOf(E1) ==K IntType andBool typeOf(E2) ==K IntType
endmodule
// SPDX-FileCopyrightText: 2026 Cyprien PIERRE
// SPDX-License-Identifier: CECILL-2.1
//
// The lexeme `select` in its conditional reading (chapter 5). The word is also the
// alias of the glyph for selection by indices (chapter 1): that reading is not modelled here.
// Its production keeps the parentheses of the experimental subset.
requires "literals.k"
module SELECT
imports LITERALS
// Only the condition is strict: select does not evaluate its unchosen branch.
syntax K7Exp ::= "(" "select" K7Exp K7Exp K7Exp ")" [symbol(k7Select), strict(1)]
// Call-by-value conditional: strict(1) evaluates only the condition.
rule (select true E1:K7Exp _E2:K7Exp) => E1 [label(k7SelectTrue)]
rule (select false _E1:K7Exp E2:K7Exp) => E2 [label(k7SelectFalse)]
rule typeOf((select C:K7Exp E1:K7Exp E2:K7Exp)) => typeOf(E1)
requires typeOf(C) ==K BoolType andBool typeOf(E1) ==K typeOf(E2)
endmodule
Le module LEXICON compose ces lemmes en une définition exécutable.
// SPDX-FileCopyrightText: 2026 Cyprien PIERRE // SPDX-License-Identifier: CECILL-2.1 // // Composition of the lexemes of lexicon/lexemes/ into one executable definition: // one prefix expression runs in the K cell. requires "lexemes/literals.k" requires "lexemes/add.k" requires "lexemes/lt.k" requires "lexemes/select.k" module LEXICON imports LITERALS imports ADD imports LT imports SELECT configuration <k> $PGM:K7Exp </k> endmodule