Repository navigation
3 4 discourse scope and program synthesis
Source: https://deepwiki.com/PonvasanthPon/TransCompilator/3-4-discourse-scope-and-program-synthesis
Relevant source files
The following files were used as context for generating this wiki page:
The discourse_scope module in tc-semantics manages paragraph-level semantic constructs, structural range introductions, referential loop continuations, post-loop closers, and existential check whether validations. Rather than relying on machine learning, tc-r1 uses deterministic text pattern matching and syntactic boundary analysis to map narrative English discourse patterns into structured AST nodes and Core-7 control flow operations.
Sources: crates/tc-semantics/src/discourse_scope.rs:1-11
Narrative English programs frequently initialize complex states using imaginative or hypothetical openings such as Imagine a red box starting with 5 and a blue box starting with 16. [crates/tc-semantics/src/discourse_scope.rs:107-108]. The engine parses these structures via parse_state_declaration [crates/tc-semantics/src/discourse_scope.rs:109].
-
Trigger Recognition: The sentence must begin with words like
imagine,suppose,assume, orconsider[crates/tc-semantics/src/discourse_scope.rs:111-117]. -
Clause Splitting: The payload after the introductory verb is split across top-level
andconjunctions [crates/tc-semantics/src/discourse_scope.rs:118-122]. -
Marker Resolution: Each clause is scanned for initialization markers such as
starting with,holding,containing, orwith[crates/tc-semantics/src/discourse_scope.rs:126-128]. -
Normalizer: Noun phrases are normalized to singular snake_case identifiers (e.g.,
red boxesbecomesred_box) [crates/tc-semantics/src/discourse_scope.rs:89-105, 134-153].
graph TD
A["Text Input"] --> B["parse_state_declaration"]
B --> C{"Starts with Imagine/Suppose/Assume?"}
C -->|Yes| D["Split Top-Level 'and' Clauses"]
C -->|No| E["Return None"]
D --> F["Extract Assignment Markers starting_with/holding"]
F --> G["Normalize Noun Phrase to snake_case"]
G --> H["Emit Vector of (Name, Value) Pairs"]
sub:Sources: crates/tc-semantics/src/discourse_scope.rs:109-156
Sources: crates/tc-semantics/src/discourse_scope.rs:89-156
Quantifiers govern loops and boolean assertions across collections or ranges. The quantifier module distinguishes between global statement quantifiers (which desugar into Core-7 Loop statements) and local boolean quantifiers (which desugar into short-circuiting prelude loops with boolean temporaries) [crates/tc-semantics/src/quantifier.rs:1-6].
-
QuantDomainSpec: Represents either an inclusive integer range (from <start> to <end> [by <step>]) or a fixed-size array variable (Array { arr }) [crates/tc-semantics/src/quantifier.rs:10-26]. -
GlobalQuantifier: Represents statements likeFor every <var> from ...[crates/tc-semantics/src/quantifier.rs:64-74, 163-166]. -
LocalQuantSpec: Captures universal (Every), existential (Some), and negative existential (No) checks inside boolean condition contexts [crates/tc-semantics/src/quantifier.rs:28-61].
graph TD
A["Natural Language Statement"] --> B["quantifier::parse_global"]
B --> C{"Starts with 'For every/each'?"}
C -->|Yes| D["Parse Domain QuantDomainSpec"]
D --> E["Extract Optional Inline Body after comma"]
E --> F["Emit GlobalQuantifier AST node"]
C -->|No| G["Pass to Local Quantifier / Cond Parser"]
sub:Sources: crates/tc-semantics/src/quantifier.rs:163-204
Sources: crates/tc-semantics/src/quantifier.rs:1-204
Loop behaviors are constrained via conditional guards and interruption triggers embedded within the discourse.
-
parse_move_guard: Recognizes conditional loop bypass rules, such asif a move would ever cause either box to drop below 5, skip that move[crates/tc-semantics/src/discourse_scope.rs:158-195]. It detects limit phrases likedrop below,fall below, orgo belowand extracts the numeric floor value [crates/tc-semantics/src/discourse_scope.rs:178-194]. -
parse_stop_condition: Detects immediate loop termination instructions likeStop immediately as soon as <condition>[crates/tc-semantics/src/discourse_scope.rs:197-202]. -
parse_largest_tracker: Identifies extremum tracking requests (e.g.,keep track of the largest value you printedortrack the minimum) [crates/tc-semantics/src/discourse_scope.rs:49-87], returning aLargestTrackerstruct [crates/tc-semantics/src/discourse_scope.rs:50-54] that dictates whether maximum or minimum metrics are maintained [crates/tc-semantics/src/discourse_scope.rs:83-86].
graph TD
A["Discourse Sentence"] --> B{"Sentence Pattern"}
B -->|Move Guard| C["parse_move_guard"]
B -->|Stop Condition| D["parse_stop_condition"]
B -->|Extremum Tracker| E["parse_largest_tracker"]
C --> F["Extract Numeric Floor & Skip Action"]
D --> G["Extract Termination Condition"]
E --> H["Emit LargestTracker maximum bool"]
sub:Sources: crates/tc-semantics/src/discourse_scope.rs:49-202
Sources: crates/tc-semantics/src/discourse_scope.rs:49-202
Existential checks query data domains using phrasing such as check whether any prime divides n. These are modeled via CheckSpec, CheckKind, and CheckDomain structures [crates/tc-semantics/src/discourse_scope.rs:12-47].
-
CheckKind: Categorizes quantification intoAny,Every, orNo[crates/tc-semantics/src/discourse_scope.rs:13-21]. -
CheckDomain: Defines the scope of the inner check loop:-
Range { start, end }: Inclusive numeric bounds [crates/tc-semantics/src/discourse_scope.rs:26-27]. -
Smaller { start }: Values smaller than the active loop referent [crates/tc-semantics/src/discourse_scope.rs:28-29]. -
Larger { end }: Values larger than the active loop referent [crates/tc-semantics/src/discourse_scope.rs:30-31]. -
List { name }: An existing list variable collection [crates/tc-semantics/src/discourse_scope.rs:32-34].
-
-
CheckSpec: Combineskind,noun,domain, andpredicatetext into a unified validation rule [crates/tc-semantics/src/discourse_scope.rs:36-47].
graph TD
A["Natural Language 'Check Whether' Sentence"] --> B["discourse_scope::CheckSpec"]
B --> C["Assign CheckKind Any/Every/No"]
B --> D["Build CheckDomain Range/Smaller/Larger/List"]
B --> E["Extract Predicate Text divides / conditions"]
C --> F["Lower into Short-Circuiting Core-7 Logic"]
D --> F
E --> F
sub:Sources: crates/tc-semantics/src/discourse_scope.rs:12-47
Sources: crates/tc-semantics/src/discourse_scope.rs:12-47
The parsed discourse conditions interact with the boolean condition parser (cond.rs), which enforces ACE-inspired operator binding precedence [crates/tc-semantics/src/cond.rs:1-14]:
-
, or(loosest) [crates/tc-semantics/src/cond.rs:3] -
, and[crates/tc-semantics/src/cond.rs:3] -
or[crates/tc-semantics/src/cond.rs:3] -
and[crates/tc-semantics/src/cond.rs:3] -
not[crates/tc-semantics/src/cond.rs:3] - Atomic comparisons (
==,<,>, etc.) (tightest) [crates/tc-semantics/src/cond.rs:3, 136]
Conditions are split recursively using split_condition [crates/tc-semantics/src/cond.rs:69-185] while respecting parenthesis depth and local quantifier boundaries (satisfies, where, such that) [crates/tc-semantics/src/cond.rs:73, 123-132], ensuring deterministic lowering into Core-7 boolean AST expressions (AstExpr) and prelude statements (AstStmt) [crates/tc-semantics/src/cond.rs:17-26].
Sources: crates/tc-semantics/src/cond.rs:1-185
The TransCompilator Project