* Documentation

Tiered Diagnostic Architecture

The three-tier intelligent diagnostic system in Turflang.

The primary research contribution of Turflang lies in a three-tier diagnostic architecture embedded seamlessly within the compiler pipeline. Rather than relying on post-hoc suggestions outside the compiler, Turflang integrates fine-tuned small language models (SLMs) during the syntax and semantic analysis phases. This allows it to deliver enhanced, context-sensitive help messages, learning-oriented explanations, and controlled code fixes.

Three Tiers of Diagnostics

Tier 1: Deterministic Rule-Based Diagnostics

The first tier consists of deterministic, rule-based diagnostics that map specific error categories to structured hints. This ensures rapid feedback and maintains classic predictability for standard code issues.

Tier 2: Offline AI Component

The second tier introduces an offline AI component designed to operate under constrained memory budgets. It provides context-sensitive suggestions without requiring external connectivity.

Tier 3: Online AI-Assisted Analysis

The third tier allows online AI-assisted analysis that leverages remote compute resources for broader contextual reasoning. This tier can perform on-demand optimizations and deep contextual analyses, making use of more powerful foundation models when necessary.

Example Error Handling

Here’s an example of how a rule-based or AI-assisted diagnostic might be evaluated at the compiler level:

void analyzeSyntaxNode(ASTNode* node) {
    if (node->hasMissingSemicolon()) {
        // Tier 1 Feedback
        reportError("Missing semicolon at the end of the statement.");
    } else if (node->hasTypeMismatch()) {
        // Tier 2 / 3: Invoke SLM for context-aware fix
        std::string suggestion = AI_SuggestFix(node, context);
        reportError("Type mismatch. Did you mean to cast to '" 
            + suggestion + "'?");
    }
}

Opt-In & Automatic Correction

All AI-assisted features are strictly opt-in through compile-time flags. This ensures the deterministic behavior of the compiler is preserved by default.

Additionally, an optional mode attempts automatic correction of non-logical errors under controlled conditions, supporting both direct modifications and educational comment-based learning fixes for beginner users.