An experimental transpiler for indentation-based C syntax.
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.
- Basic transpiler for simple C programs
- CLI interface with build and run options
- Integration with multiple C compilers (TCC, GCC, Clang)
- Limited to simple function definitions and statements
- Memory management issues in transpiler
- Some advanced C features not yet supported
cd cspaced
make
sudo make install# 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# 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 --compilecspaced (hello.csp):
#include <stdio.h>
int main(void):
printf("Hello, cspaced!\n")
printf("This is the future of C programming!\n")
return 0Generated C (hello.c):
#include <stdio.h>
int main(void) {
printf("Hello, cspaced!\n");
printf("This is the future of C programming!\n");
return 0;
}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 0Generated 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;
}- 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 */
- File extension:
.csp - Indentation: 2 spaces (enforced consistently)
- Semicolons: Optional, inferred from newlines
- Braces: Replaced by indentation +
: - Keywords: All C keywords supported
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
- Memory corruption in transpiler prevents processing complex programs
- Limited support for C expressions and declarations
- Compilation errors with certain C standard library functions
- 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
- Complex expressions and operators
- Arrays and pointers syntax
- Struct/union definitions
- Function calls with arguments
- Error recovery and reporting
- Fix memory management issues in transpiler
- Implement proper AST parsing for expressions
- Add comprehensive error reporting
- Expand support for variable declarations
- Add support for arrays, pointers, and structs
- Implement function call syntax
- Improve preprocessor directive handling
- Add basic optimization passes
- Bidirectional C↔cspaced conversion
- IDE integration and LSP support
- Advanced optimizations and features
- Package management integration
- 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
- TCC: Primary testing compiler
- GCC: Expected to work (limitations tested)
- Clang: Expected to work (limitations tested)
- Linux: Primary development platform
- macOS, Windows: Should work (build system agnostic)
- Target: C99 compatibility
- May require adjustment for embedded/systems C99 subsets
See CONTRIBUTING.md for development setup and contribution guidelines.
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.
- Technical Risk: High (memory issues, limited feature set)
- Maintenance Risk: Medium (actively developed but incomplete)
- Adoption Risk: High (significant limitations, not production-ready)
Currently maintained by a single developer. Community engagement through GitHub issues and discussions encouraged.
Bugs and feature requests tracked in the issue tracker.
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
MIT License - see LICENSE file for details.
"The future of C is indentation-based"
— Every Python developer who still needs C performance