Skip to content

3 semantics from english to typed ast

TransCompilator edited this page Nov 26, 2026 · 1 revision

3 Semantics: From English to Typed AST

Source: https://deepwiki.com/PonvasanthPon/TransCompilator/3-semantics-from-english-to-typed-ast

Semantics: From English to Typed AST

Relevant source files

The following files were used as context for generating this wiki page:

The tc-semantics crate serves as the finite English semantic front end for tc_r1 [crates/tc-semantics/src/lib.rs:1-5]. Its primary responsibility is to bridge raw syntax trees and token streams into a structured, typed Abstract Syntax Tree (AST) consumed by tc-typeck [crates/tc-semantics/src/lib.rs:3-5,36].

This pipeline classifies sentences through a strict three-way intent gate, matches declarative signatures, normalizes value expressions, constructs semantic frames, analyzes discourse scope, and lowers executable English into Phase 1 typed representations.

Scoping and Child Pages

As a parent page, this section provides a high-level architectural overview of the semantic analysis phase. Detailed technical specifications, algorithm descriptions, and implementation internals are documented in the following child pages:


Architecture and Pipeline Overview

The translation process transforms raw parsed clauses into verified semantic artifacts through several modular passes. The top-level entry points lower_project and lower_project_outcome orchestrate this transformation, managing provenance collection via SentenceTrace and error reporting via SemanticError [crates/tc-semantics/src/lib.rs:105-202].

title "Semantic Pipeline: Natural Language to Code Entities"
graph TD
    SourceFiles["SourceFiles"] --> Segmenter["tc_syntax::segment_source"]
    Segmenter --> RawSentences["RawSentence"]
    RawSentences --> IntentGate["tc_semantics::intent"]
    IntentGate --> Trace["SentenceTrace"]
    Trace --> ClauseAnalysis["tc_semantics::clause_graph"]
    ClauseAnalysis --> FrameMatching["tc_semantics::frame"]
    FrameMatching --> LoweringEngine["tc_semantics::lower"]
    LoweringEngine --> TypedAST["tc_typeck::Program"]
    
    subgraph NaturalLanguageSpace
        SourceFiles
        RawSentences
    end

    subgraph CodeEntitySpace
        Trace
        ClauseAnalysis
        FrameMatching
        LoweringEngine
        TypedAST
    end
Loading

Sources: [crates/tc-semantics/src/lib.rs:1-48]


3.1 Intent Gate and Sentence Classification

Before any syntactic analysis or lowering occurs, the intent gate inspects each sentence to determine its computational viability. Sentences are categorized into an IntentVerdict via modules under intent/, identifying executable statements, omitted comments, or unsupported directives.

For full technical details, see Intent Gate and Sentence Classification.

Sources: [crates/tc-semantics/src/lib.rs:26-38]


3.2 Normalization and Value Parsing

Natural language introduces noise, contractions, colloquial openers, and textual representations of numbers. The normalization phase (normalize, number_words, and value) cleanses strings, expands contractions, strips casual openers, parses English number words into scalar values, and resolves anaphora.

For full technical details, see Normalization and Value Parsing.

Sources: [crates/tc-semantics/src/lib.rs:17-18]


3.3 Semantic Frames and Expressions

Executable statements map onto specific SemanticFrame variants—such as Emit, Assign, Transfer, and Swap—governed by place specifications and verb predicates. The expr and phrases modules handle expression lowering as well as custom user-defined phrase declarations and invocations.

title "Mapping Semantic Frames to Lowered Constructs"
graph LR
    Sentence["Natural Language Sentence"] --> Frame["tc_semantics::frame::SemanticFrame"]
    Frame --> Emit["Emit Frame"]
    Frame --> Assign["Assign Frame"]
    Frame --> Transfer["Transfer Frame"]
    Frame --> Swap["Swap Frame"]
    
    subgraph CodeEntitySpace
        Frame
        Emit
        Assign
        Transfer
        Swap
    end
Loading

For full technical details, see Semantic Frames and Expressions.

Sources: [crates/tc-semantics/src/lib.rs:14-15]


3.4 Discourse Scope and Program Synthesis

Paragraph boundaries, loop introductions, conditional blocks, and pass filters are managed across the discourse, discourse_scope, cond, and quantifier modules. This layer synthesizes multi-sentence paragraphs into coherent scoped blocks and control structures.

For full technical details, see Discourse Scope and Program Synthesis.

Sources: [crates/tc-semantics/src/lib.rs:11-13]


3.5 Clause Graphs and the Lowering Engine

The clause_graph module decomposes complex sentences into directed acyclic clause structures. The lower module then acts as the central translation engine, transforming these graphs and semantic frames into the Phase 1 typed AST (Program) [crates/tc-semantics/src/lib.rs:10,16].

For full technical details, see Clause Graphs and the Lowering Engine.

Sources: [crates/tc-semantics/src/lib.rs:10-16]


3.6 Paraphrase Echo and Diagnostics

To ensure transparency and deterministic behavior, tc-semantics provides a paraphrase echo generator (paraphrase) that mirrors parsed instructions back to the user. Errors during semantic analysis are collected into structured SemanticError diagnostic records with specific SemanticErrorKind categories [crates/tc-semantics/src/lib.rs:64-91].

For full technical details, see Paraphrase Echo and Diagnostics.

Sources: [crates/tc-semantics/src/lib.rs:19-22,64-91]


Clone this wiki locally