Skip to content

Latest commit

Β 

History

History
386 lines (300 loc) Β· 8 KB

File metadata and controls

386 lines (300 loc) Β· 8 KB

Construct Language Compiler - Documentation Index

🎯 Start Here

New to Construct? β†’ Read CONSTRUCT_QUICK_REFERENCE.md (5 min read)

Want to compile Construct code? β†’ Read CONSTRUCT_COMPILER_README.md (15 min read)

Need complete details? β†’ Read docs/CONSTRUCT_COMPILER.md (30 min read)

Want project overview? β†’ Read CONSTRUCT_COMPILER_FINAL_SUMMARY.md (20 min read)


πŸ“š Documentation Files

CONSTRUCT_QUICK_REFERENCE.md

What: Quick syntax cheat sheet and common patterns When to use: Quick lookup, syntax reminder, example patterns Length: ~3 pages Topics:

  • Syntax at a glance
  • All operators
  • Types and keywords
  • Common patterns (factorial, loops, etc.)
  • Operator precedence

CONSTRUCT_COMPILER_README.md

What: Complete user guide for the compiler When to use: Learning how to use the compiler, integration Length: ~12 pages Topics:

  • Quick start
  • Language syntax (detailed)
  • Architecture overview
  • Type system
  • Statement types
  • Example programs
  • Testing and usage
  • Performance metrics

docs/CONSTRUCT_COMPILER.md

What: Detailed language and compiler reference When to use: Deep understanding, extending the compiler Length: ~25 pages Topics:

  • Architecture deep dive
  • Lexer implementation
  • Parser implementation
  • Compiler implementation
  • Complete language spec
  • Type mapping
  • Test coverage
  • Future enhancements

CONSTRUCT_COMPILER_FINAL_SUMMARY.md

What: Project completion summary When to use: Understanding what was built and delivered Length: ~20 pages Topics:

  • What was delivered
  • Component descriptions
  • Test results
  • Example programs
  • Integration details
  • Quality metrics
  • Build verification

πŸ“ Source Code Files

Core Compiler

Location: src/ObjectIR.Core/Compilers/

ConstructLexer.cs

  • Tokenizes source code
  • ~350 lines
  • Handles all keywords, operators, delimiters
  • Comment support (line and block)

ConstructAST.cs

  • Abstract Syntax Tree definitions
  • ~250 lines
  • All node types (Program, Contract, Functions, Statements, Expressions)

ConstructParser.cs

  • Builds AST from tokens
  • ~450 lines
  • Recursive descent parser
  • Proper operator precedence
  • Error handling with location info

ConstructCompiler.cs

  • Generates ObjectIR from AST
  • ~150 lines
  • Maps Construct constructs to ObjectIR
  • Type resolution

Examples

Location: ObjectIR.Examples/

ConstructLanguageExample.cs

  • 3 working example programs
  • Simple calculator
  • Multiple functions
  • File I/O

Tests

Location: ObjectIR.CSharpTests/

ConstructLanguageTests.cs

  • 28 comprehensive tests
  • Lexer tests (10)
  • Parser tests (8)
  • Compiler tests (5)
  • Integration tests (5)

πŸ§ͺ Test Coverage

Test Categories

Category Count Status
Lexer Tests 10 βœ… Pass
Parser Tests 8 βœ… Pass
Compiler Tests 5 βœ… Pass
Integration Tests 5 βœ… Pass
Total 28 βœ… All Pass

Test Results

Passed! - Failed: 0, Passed: 86 (includes 58 other tests), Duration: 429 ms

πŸ’» Usage Examples

Simple Compilation

var compiler = new ConstructLanguageCompiler();
var module = compiler.CompileSource(sourceCode);

Export Formats

// JSON
var json = compiler.CompileSourceToJson(sourceCode);

// Text dump
var text = compiler.CompileSourceToText(sourceCode);

// Save to file
var loader = new ModuleLoader();
loader.SaveToJsonFile(module, "output.ir.json");

Example Program

Contract Calculator {
    fn Add(a: Int, b: Int) -> Int {
        var result = a + b;
        return result;
    }

    fn Multiply(a: Int, b: Int) -> Int {
        var result = a * b;
        return result;
    }

    fn IsPositive(n: Int) -> Bool {
        return n > 0;
    }
}

πŸ—οΈ Architecture Overview

Pipeline

Source Code (.ct)
    ↓
Lexer (Tokenization)
    ↓
Parser (Syntax Analysis)
    ↓
Compiler (Code Generation)
    ↓
ObjectIR Module
    ↓
JSON/Text Output

Components

  1. ConstructLexer - Converts source to tokens
  2. ConstructParser - Converts tokens to AST
  3. ConstructCompiler - Converts AST to ObjectIR
  4. ConstructLanguageCompiler - Simple API

πŸ”§ Key Features

Lexer Features

  • All keywords supported
  • All operators supported
  • Comment handling
  • Proper error reporting

Parser Features

  • Operator precedence
  • All statement types
  • All expression types
  • Error recovery

Compiler Features

  • Contract β†’ Class mapping
  • Function β†’ Method mapping
  • Type mapping
  • Parameter handling

Integration

  • Works with ModuleLoader
  • Works with IRBuilder
  • JSON serialization
  • Text dump export

πŸ“Š Quality Metrics

Metric Value
Total Tests 86
Tests Passing 86 (100%)
Code Lines ~1200
Documentation Lines ~3000
Build Status βœ… Success
Integration Status βœ… Complete

πŸš€ Getting Started

Step 1: Read Quick Reference

  • Learn syntax in 5 minutes
  • See example patterns
  • Understand types and operators

Step 2: Run Examples

dotnet run --project ObjectIR.Examples/

Step 3: Try Simple Programs

  • Start with calculator example
  • Progress to loops and recursion
  • Build complex programs

Step 4: Compile and Export

var compiler = new ConstructLanguageCompiler();
var module = compiler.CompileSource(myCode);
loader.SaveToJsonFile(module, "output.json");

Step 5: Analyze Results

  • View generated ObjectIR
  • Use ObjectIR tools for analysis
  • Integrate with your workflow

❓ FAQ

Q: Where do I start? A: Read CONSTRUCT_QUICK_REFERENCE.md for syntax, then CONSTRUCT_COMPILER_README.md for usage.

Q: How do I compile code? A: Use new ConstructLanguageCompiler().CompileSource(sourceCode)

Q: Can I extend it? A: Yes! See "Extensibility" section in CONSTRUCT_COMPILER_README.md

Q: What are the limitations? A: See "Limitations & Future Work" sections in documentation

Q: How do I run tests? A: dotnet test ObjectIR.CSharpTests/ --filter "Construct"

Q: How do I see examples? A: Run dotnet run --project ObjectIR.Examples/


πŸ“ File Organization

ObjectIR/
β”œβ”€β”€ src/ObjectIR.Core/Compilers/
β”‚   β”œβ”€β”€ ConstructLexer.cs
β”‚   β”œβ”€β”€ ConstructAST.cs
β”‚   β”œβ”€β”€ ConstructParser.cs
β”‚   └── ConstructCompiler.cs
β”‚
β”œβ”€β”€ ObjectIR.Examples/
β”‚   └── ConstructLanguageExample.cs
β”‚
β”œβ”€β”€ ObjectIR.CSharpTests/
β”‚   └── ConstructLanguageTests.cs
β”‚
β”œβ”€β”€ docs/
β”‚   └── CONSTRUCT_COMPILER.md
β”‚
β”œβ”€β”€ CONSTRUCT_QUICK_REFERENCE.md
β”œβ”€β”€ CONSTRUCT_COMPILER_README.md
β”œβ”€β”€ CONSTRUCT_COMPILER_FINAL_SUMMARY.md
└── CONSTRUCT_COMPILER_DOCUMENTATION_INDEX.md (this file)

πŸ”— Related Components

  • ModuleLoader - Load/save IR modules
  • IRBuilder - Programmatic IR construction
  • TypeReference - Type system
  • Serialization - JSON/text export

βœ… Status

  • βœ… Lexer complete
  • βœ… Parser complete
  • βœ… Compiler complete
  • βœ… Tests passing (28/28)
  • βœ… Examples working
  • βœ… Documentation complete
  • βœ… Integration verified
  • βœ… Production ready

πŸ“– Reading Paths

For Quick Overview

  1. This file (2 min)
  2. CONSTRUCT_QUICK_REFERENCE.md (5 min)
  3. Look at examples (5 min) Total: ~12 minutes

For Complete Understanding

  1. CONSTRUCT_COMPILER_README.md (15 min)
  2. docs/CONSTRUCT_COMPILER.md (30 min)
  3. Review source code (30 min) Total: ~75 minutes

For Implementation Details

  1. CONSTRUCT_COMPILER_FINAL_SUMMARY.md (20 min)
  2. Review test files (15 min)
  3. Review source code (30 min) Total: ~65 minutes

🎯 Next Steps

  • Beginner: Start with CONSTRUCT_QUICK_REFERENCE.md
  • User: Read CONSTRUCT_COMPILER_README.md
  • Developer: Study docs/CONSTRUCT_COMPILER.md
  • Contributor: Review source and tests

Status: βœ… Complete Last Updated: November 5, 2025 Version: 1.0 - Production Ready