Skip to content

demosthenez/cspaced

Repository files navigation

cspaced

An experimental transpiler for indentation-based C syntax.

Overview

cspaced is a proof-of-concept transpiler that converts indentation-based C syntax to standard curly-brace C. It demonstrates Python-style indentation applied to C, removing the need for braces and providing optional semicolons.

Current Implementation Status

Functionality

  • Basic transpiler for simple C programs
  • CLI interface with build and run options
  • Integration with multiple C compilers (TCC, GCC, Clang)

Limitations

  • Limited to simple function definitions and statements
  • Memory management issues in transpiler
  • Some advanced C features not yet supported

Installation

cd cspaced
make
sudo make install

Usage

Basic Transpilation

# Transpile cspaced to C
cspaced hello.csp

# Specify output file
cspaced hello.csp -o output.c

# Convert C to cspaced (future feature)
cspaced hello.c --from-c

Compilation & Execution

# Transpile and compile
cspaced hello.csp --compile

# Transpile, compile and run
cspaced hello.csp --run

# Specify compiler
cspaced hello.csp --gcc --compile
cspaced hello.csp --tcc --run
cspaced hello.csp --clang --compile

Syntax Examples

Hello World

cspaced (hello.csp):

#include <stdio.h>

int main(void):
    printf("Hello, cspaced!\n")
    printf("This is the future of C programming!\n")
    return 0

Generated C (hello.c):

#include <stdio.h>

int main(void) {
    printf("Hello, cspaced!\n");
    printf("This is the future of C programming!\n");
    return 0;
}

Functions & Control Flow

cspaced:

int fibonacci(int n):
    if (n <= 1):
        return n
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)

int main(void):
    printf("fib(10) = %d\n", fibonacci(10))

    for (int i = 0; i < 3; i++):
        printf("Iteration %d\n", i)

    return 0

Generated C:

int fibonacci(int n) {
    if (n <= 1) {
        return n;
    } else {
        return fibonacci(n - 1) + fibonacci(n - 2);
    }
}

int main(void) {
    printf("fib(10) = %d\n", fibonacci(10));

    for (int i = 0; i < 3; i++) {
        printf("Iteration %d\n", i);
    }

    return 0;
}

Supported Constructs

  • Functions: int func(void):
  • Control Flow: if (condition):, while (condition):, for (init; cond; update):
  • Variables: int x = 42;
  • Preprocessor: #include, #define (unchanged)
  • Comments: // line comments, /* block comments */

Syntax Specification

  • File extension: .csp
  • Indentation: 2 spaces (enforced consistently)
  • Semicolons: Optional, inferred from newlines
  • Braces: Replaced by indentation + :
  • Keywords: All C keywords supported

Architecture

cspaced/
├── src/           # Source code
│   ├── main.c     # CLI interface
│   ├── lexer.c    # Tokenization
│   ├── parser.c   # AST building
│   ├── transpiler.c # C generation
│   └── compiler.c # Compiler integration
├── include/       # Headers
├── examples/      # Sample programs
└── Makefile       # Build system

Known Issues and Limitations

Critical Issues

  • Memory corruption in transpiler prevents processing complex programs
  • Limited support for C expressions and declarations
  • Compilation errors with certain C standard library functions

Current Capabilities

  • Simple function definitions: int main(void):
  • Basic variable declarations
  • Simple if statements: if (x > 0):
  • For/while loops and return statements
  • Preprocessor directives pass-through

Missing Features

  • Complex expressions and operators
  • Arrays and pointers syntax
  • Struct/union definitions
  • Function calls with arguments
  • Error recovery and reporting

Development Roadmap

Short Term (0-3 months)

  • Fix memory management issues in transpiler
  • Implement proper AST parsing for expressions
  • Add comprehensive error reporting
  • Expand support for variable declarations

Medium Term (3-6 months)

  • Add support for arrays, pointers, and structs
  • Implement function call syntax
  • Improve preprocessor directive handling
  • Add basic optimization passes

Long Term (6+ months)

  • Bidirectional C↔cspaced conversion
  • IDE integration and LSP support
  • Advanced optimizations and features
  • Package management integration

Performance Expectations

  • Transpilation Speed: Expected to be fast once memory issues resolved
  • Generated Code: Zero performance penalty vs manually written C
  • Memory Usage: Dependent on source file size, likely efficient
  • Scalability: Designed for large codebases but not yet tested

Compatibility

Compiler Support

  • TCC: Primary testing compiler
  • GCC: Expected to work (limitations tested)
  • Clang: Expected to work (limitations tested)

Platform Support

  • Linux: Primary development platform
  • macOS, Windows: Should work (build system agnostic)

C Standard

  • Target: C99 compatibility
  • May require adjustment for embedded/systems C99 subsets

Contributing

See CONTRIBUTING.md for development setup and contribution guidelines.

Project Status

This is an experimental proof-of-concept demonstrating indentation-based C syntax. The core idea has been validated, but production use requires significant additional development.

Risk Assessment

  • Technical Risk: High (memory issues, limited feature set)
  • Maintenance Risk: Medium (actively developed but incomplete)
  • Adoption Risk: High (significant limitations, not production-ready)

Support and Community

Currently maintained by a single developer. Community engagement through GitHub issues and discussions encouraged.

Bugs and feature requests tracked in the issue tracker.

Contributing

The cspaced project welcomes contributions! Key areas:

  • AST Improvements: Better expression parsing
  • Error Handling: More descriptive error messages
  • C to cspaced: Full bidirectional conversion
  • IDE Support: Syntax highlighting, LSP integration
  • Documentation: Tutorials, language reference

License

MIT License - see LICENSE file for details.


"The future of C is indentation-based"

— Every Python developer who still needs C performance

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published