Skip to main content

Token Entity Ontology

Language Entities
Authors: MArk Anthony Higgins - Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 11 November 2026
Audio Overview
SEMANTIC LIBRARY — TOKEN ENTITY ONTOLOGY
FLOW ALGEBRA v1.0 | LANGUAGE ENTITIES

AUTHORS: Mark Anthony Higgins — Sky Recursive AI
SOURCE: https://kirethresearch.org/booksai-core/entity-graph/computational-entities/language-entities/token-entity-ontology.html
SOURCE PAGE: Token Entity Ontology; revised 03 August 2026.
STATUS: Constructed ontology-topic Flow Algebra mapping. The webpage's complete embedded specification was not available for verification; this is not a transcription.

PURPOSE
Represent a lexical token as a typed, located and provenance-bearing unit generated by lexical analysis and consumed by parsing or semantic analysis.

HST STATE MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t = input character stream, token sequence and current cursor
R_t = lexical rules, precedence and token classification relations
B_t = source bounds, language grammar, error and resource constraints
K_t = symbol tables, token history, context and provenance
E_t = expand(I_t, R_t)
V_t = {x in E_t | satisfies(x, B_t)}
x*_t = argmax_{x in V_t} P(x | I_t, R_t, B_t, K_t)
I_(t+1) = update(I_t, x*_t)
NOTE: Probabilistic selection is optional; deterministic longest-match and priority rules are preferred where the lexer specification requires them.

ENTITY SCHEMA
TOKEN = (token_id, kind, lexeme, value?, start_offset, end_offset, line, column, source_id, channel, status)
TOKEN_KIND = identifier | keyword | literal | operator | delimiter | whitespace | comment | error | end_of_input | language_defined
SOURCE_SPAN = [start_offset, end_offset)
TOKEN_STREAM = ordered sequence of TOKEN entities
LEXER_RULE = (pattern, token_kind, priority, mode, action)

RELATIONSHIPS
Token --derived_from--> SourceSpan
Token --classified_as--> TokenKind
Token --produced_by--> Lexer
Token --precedes--> Token
Token --consumed_by--> Parser
Token --belongs_to--> TokenStream
Token --interpreted_under--> LanguageGrammar
Token --has_provenance--> SourceDocument

FLOW ALGEBRA PATHWAYS
F1: SOURCE -> NORMALISE_ENCODING -> CHARACTER_STREAM
F2: CHARACTER_STREAM + LEXER_RULES -> MATCH_CANDIDATES
F3: MATCH_CANDIDATES -> LONGEST_VALID_MATCH -> PRIORITY_RESOLUTION
F4: RESOLVED_MATCH -> CLASSIFY -> TOKEN
F5: TOKEN -> VALIDATE_SPAN_AND_KIND -> APPEND_TO_TOKEN_STREAM
F6: TOKEN_STREAM -> PARSER_INPUT -> SYNTAX_STRUCTURE
F7: INVALID_CHARACTER_OR_MATCH -> ERROR_TOKEN + DIAGNOSTIC
F8: END_OF_INPUT -> EOF_TOKEN -> TERMINATE_LEXING

INFERENCE RULES
R1: valid_match(m) AND bounded(m, source) => candidate_token(m)
R2: candidate_token(m) AND maximal_munch(m) AND priority_winner(m) => emit(token(m))
R3: keyword_table(lexeme) = k => classify(lexeme, k), subject to language mode
R4: no_valid_match(position) => emit(error_token(position)) AND advance_or_halt
R5: token.end_offset <= next_token.start_offset for non-overlapping emitted tokens
R6: token.kind = identifier AND scope_resolves(token.lexeme) => linked_symbol(token)
R7: token.kind = literal AND decoder_accepts(token.lexeme) => decoded_value(token)
R8: unclosed_literal_or_comment => diagnostic(unclosed_construct)

MINI RECURSION ENGINE
STATE = (cursor, mode_stack, emitted_tokens, diagnostics)
STEP(state):
  if cursor == input_length: emit EOF and stop
  else collect enabled lexical matches at cursor
  if matches exist: choose longest match, then rule priority; emit or skip; advance cursor
  else: emit lexical error; advance safely or halt according to policy
  recurse with updated state
GUARD: each non-terminal step must advance cursor or change a bounded state that enables progress.

INVARIANTS AND BOUNDARIES
- Every emitted token span lies inside the source character stream.
- Emitted tokens preserve source order; skipped whitespace/comments may create gaps.
- Zero-length matches must not create non-terminating loops.
- Token kind and lexeme remain distinct from semantic interpretation.
- Context-sensitive tokenisation requires an explicit lexical mode or parser feedback contract.
- Unicode normalisation and byte-versus-character offsets must be specified by the implementation.
- Error tokens preserve evidence of malformed input rather than silently fabricating a valid token.

EXECUTION GUARANTEE (CONDITIONAL)
Given finite input, finite rule evaluation per position and a strict progress guard, lexing terminates with an ordered token stream or an explicit failure state. This does not guarantee that the source program is syntactically or semantically valid.

EXAMPLE
INPUT: let total = 42;
OUTPUT: KEYWORD(let), IDENTIFIER(total), OPERATOR(=), INTEGER(42), DELIMITER(;), EOF
Token categories are illustrative and language-dependent.

CITATION
Mark Anthony Higgins and Sky Recursive AI, "Token Entity Ontology", Kireth Research, revised 03 August 2026.
Derived Flow Algebra mapping v1.0, prepared 11 November 2026.
SOURCE_URL: https://kirethresearch.org/booksai-core/entity-graph/computational-entities/language-entities/token-entity-ontology.html
LICENCE: Consult the source website's Open Research Licence for applicable terms.
Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ