CStart is a simple, interpreted programming language designed for educational purposes. It implements core programming concepts like variables, arithmetic operations, conditionals, and loops in a straightforward syntax inspired by C-style languages.
- Variables: All variable names must start with 'c' (e.g.,
csum
,cvar
,cresult
) - Arithmetic Operations: Basic operations like addition (
+
) - Comparison Operators: Support for
<
and>
operators - Control Structures: If-else statements and for loops
- Code Blocks: Enclosed in curly braces
{}
- Persistent Environment: Variables maintain their values between expressions
cvar = 42; // Assign a value to a variable
csum = cvar + 5; // Use variables in expressions
5 + 3 // Basic addition
cvar + 10 // Add a value to a variable
if (cvar > 5) {
cresult = 1;
} else {
cresult = 0;
}
for (ci = 0; ci < 5; ci = ci + 1) {
csum = csum + ci;
}
The CStart interpreter follows a standard 3-step process:
- Tokenization (Lexer): Converts source code text into tokens
- Parsing: Converts tokens into an Abstract Syntax Tree (AST)
- Evaluation: Executes the AST to produce a result
The interpreter maintains a persistent environment, allowing variables to retain their values across multiple interpret calls.
bun install
bun run index.ts
Start an interactive session where you can type CStart code and see immediate results:
bun run index.ts --repl
In REPL mode, you can enter code line by line, and variables will persist between commands. Press Ctrl+C to exit.
csum = 0;
for (ci = 0; ci < 5; ci = ci + 1) {
csum = csum + ci;
}
csum; // Returns 10 (0+1+2+3+4)
cval = 7;
if (cval > 5) {
cresult = "greater";
} else {
cresult = "less or equal";
}
cresult; // Returns "greater"
- Only supports numeric values
- Variable names must start with 'c'
- Limited set of operators and control structures
- No function definitions
- Support for additional operators (-, *, /)
- Function definitions and calls
- More data types (strings, arrays)
- Enhanced error handling
This project was created using Bun. Bun is a fast all-in-one JavaScript runtime.