Skip to content

Commit db8b0e1

Browse files
committed
Repo Update
Complete E-Lang to CP-Lang refactor and compiler implementation - Rebranded entire project from E-Lang to CP-Lang - Changed all unit names from ELang to CPLang prefix - Updated copyright to tinyBigGAMES LLC 2025-present - New project identity C Power Pascal Clarity - Website changed to https://cp-lang.org/ - Implemented complete lexical analyzer in CPLang.Lexer.pas - Added comprehensive parser in CPLang.Parser.pas - Built full semantic analysis system in CPLang.Semantic.pas - Created complete type system in CPLang.Types.pas - Added LLVM integration and code generation - Implemented include system with preprocessor directives - Built comprehensive error handling and reporting - Added symbol table management - Created platform abstraction layer - Implemented compiler orchestration with progress reporting - Language supports C99 syntax with Pascal keywords - Mandatory main function requirement - Variable declarations with initialization - Functions and procedures with external linking - Record types and arrays - Full control flow statements - Expression evaluation with operator precedence - Preprocessor directives support - 18 Pascal units plus 1 include file - Targets 64-bit platforms Windows Linux macOS - Requires Delphi 12 or higher - Professional compiler architecture with multi-phase compilation
1 parent 095428a commit db8b0e1

36 files changed

+3002
-3545
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,5 @@ src/todo.md
9393
checkpoint.zip
9494
checkpoint_base.zip
9595
CPascal-main.zip
96+
bin/math.e
97+
bin/test.e

README.md

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
![E-Lang](media/e-lang.png)
1+
![CP-Lang](media/cp-lang.png)
22
[![Chat on Discord](https://img.shields.io/discord/754884471324672040?style=for-the-badge)](https://discord.gg/tPWjMwK) [![Follow on Bluesky](https://img.shields.io/badge/Bluesky-tinyBigGAMES-blue?style=for-the-badge&logo=bluesky)](https://bsky.app/profile/tinybiggames.com)
3-
> 🚧 **E-Lang is Work in Progress**
3+
> 🚧 **CP-Lang is Work in Progress**
44
>
5-
> E-Lang is currently under active development and evolving quickly. Some features described in this documentation may be incomplete, experimental, or subject to significant changes as the project matures.
5+
> CP-Lang is currently under active development and evolving quickly. Some features described in this documentation may be incomplete, experimental, or subject to significant changes as the project matures.
66
>
7-
> We welcome your feedback, ideas, and issue reports — your input will directly influence the direction and quality of E-Lang as we strive to build the ultimate modern programming language.
7+
> We welcome your feedback, ideas, and issue reports — your input will directly influence the direction and quality of CP-Lang as we strive to build the ultimate modern programming language.
88
99
## C Power, Pascal Clarity
1010

11-
E-Lang is a modern programming language that combines **C99 semantics with Pascal-style syntax**, giving you the raw power and flexibility of C with the clean, readable elegance of Pascal.
11+
CP-Lang is a modern programming language that combines **C99 semantics with Pascal-style syntax**, giving you the raw power and flexibility of C with the clean, readable elegance of Pascal.
1212

13-
### Why E-Lang?
13+
### Why CP-Lang?
1414

1515
- **🚀 C99 Performance** - Full access to pointers, manual memory management, and low-level system programming
1616
- **📖 Pascal Readability** - Clean, self-documenting syntax that's easy to read and maintain
@@ -25,15 +25,15 @@ E-Lang is a modern programming language that combines **C99 semantics with Pasca
2525
2626
function main(): int32
2727
begin
28-
msg: string := "Hello, E-Lang!";
29-
count: int32 := 42;
28+
var msg: char := "Hello, CP-Lang!";
29+
var count: int32 := 42;
3030
31-
if count > 0 then
32-
printf("%s Count: %d\n", msg, count)
33-
else
34-
printf("Nothing to count\n");
31+
if count > 0 then
32+
printf("%s Count: %d\n", msg, count)
33+
else
34+
printf("Nothing to count\n");
3535
36-
return 0;
36+
return 0;
3737
end
3838
```
3939

@@ -47,52 +47,53 @@ end
4747
### 🔧 **Rich Type System**
4848
```pascal
4949
// Basic types
50-
x: int32 := 100;
51-
y: float := 3.14;
52-
flag: bool := true;
50+
var x: int32 := 100;
51+
var y: float := 3.14;
52+
var flag: bool := true;
5353
5454
// Sized integers
55-
byte_val: uint8 := 255;
56-
big_num: int64 := 9223372036854775807;
55+
var byte_val: uint8 := 255;
56+
var big_num: int64 := 9223372036854775807;
5757
5858
// Pointers and arrays
59-
ptr: ^int32;
60-
numbers: array[10] of int32;
59+
var ptr: ^int32;
60+
var numbers: array[10] of int32;
6161
6262
// Records (structs)
6363
type Point = record
64-
x, y: float;
64+
x, y: float;
6565
end;
6666
```
6767

6868
### ⚙️ **Powerful Control Flow**
6969
```pascal
70-
// Modern for loops
71-
for i := 0; i < 10; i := i + 1 do
72-
printf("Count: %d\n", i);
70+
// Pascal-style for loops
71+
var i: int32;
72+
73+
for i := 1 to 10 do
74+
printf("Count: %d\n", i);
7375
74-
// Pascal-style for loops
7576
for i := 1 to 100 do
76-
process(i);
77+
process(i);
7778
7879
// Pattern matching
7980
case value of
80-
1..10: printf("Small");
81-
11..50: printf("Medium");
82-
else printf("Large");
83-
end;
81+
1..10: printf("Small");
82+
11..50: printf("Medium");
83+
else
84+
printf("Large");
85+
end
8486
```
8587

8688
### 🔗 **C99 Compatibility**
8789
```pascal
88-
#include <stdlib>
89-
#define MAX_SIZE 1024
90+
#include <stdlib.e>
9091
9192
function allocate_buffer(): ^char
9293
begin
93-
buffer: ^char := malloc(MAX_SIZE);
94-
return buffer;
95-
end;
94+
var buffer: ^char := malloc(1024);
95+
return buffer;
96+
end
9697
```
9798

9899
---

bin/test.e

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
// Main program
22

3+
#include "math.e"
4+
#include "math.e"
5+
36
function printf(const AFormat: ^char, ...): int32 external "msvcrt.dll";
47

58
function main(): int32
69
begin
710
printf("Hello, %s\n", "World!");
11+
printf("add(7, 3): %d\n", add(7, 3));
12+
13+
var i: int32;
14+
15+
printf("for-loop-to:\n");
16+
for i := 1 to 10 do
17+
begin
18+
printf("%d\n", i);
19+
end
20+
21+
printf("\nfor-loop-downto:\n");
22+
for i := 10 downto 1 do
23+
begin
24+
printf("%d\n", i);
25+
end
26+
827
return 0;
928
end
Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
(* E Language Grammar - C99 with Pascal Syntax, Mandatory Main Function *)
1+
# CP-Lang Grammar Specification
22

3+
**CP Language Grammar - C99 with Pascal Syntax, Mandatory Main Function**
4+
5+
## Program Structure
6+
7+
```bnf
38
program ::= translation_unit main_function
49
510
translation_unit ::= (preprocessor_directive | declaration)*
611
712
main_function ::= "function" "main" "(" ")" ":" "int32" statement_block
13+
```
814

9-
(* Preprocessor Directives *)
15+
## Preprocessor Directives
16+
17+
```bnf
1018
preprocessor_directive ::= "#include " ("<" IDENTIFIER ">" | STRING_LITERAL)
1119
| "#includepath " STRING_LITERAL
1220
| "#define " IDENTIFIER replacement_list?
@@ -24,25 +32,40 @@ preprocessor_directive ::= "#include " ("<" IDENTIFIER ">" | STRING_LITERAL)
2432
replacement_list ::= token_sequence
2533
token_sequence ::= [^\n]+
2634
constant_expression ::= expression
35+
```
36+
37+
## Declarations
2738

39+
```bnf
2840
declaration_list ::= declaration*
2941
3042
declaration ::= variable_declaration
3143
| function_declaration
3244
| type_declaration
3345
| statement
46+
```
3447

35-
(* Variable Declarations - can appear anywhere like C *)
48+
### Variable Declarations
49+
50+
Variables can appear anywhere like C:
51+
52+
```bnf
3653
variable_declaration ::= "var" identifier_list ":" type_spec init_value? ";"
3754
3855
identifier_list ::= IDENTIFIER ("," IDENTIFIER)*
3956
4057
init_value ::= ":=" expression
58+
```
4159

42-
(* Type Declarations *)
60+
### Type Declarations
61+
62+
```bnf
4363
type_declaration ::= "type" IDENTIFIER "=" type_spec ";"
64+
```
65+
66+
### Function Declarations
4467

45-
(* Function Declarations *)
68+
```bnf
4669
function_declaration ::= function_header statement_block
4770
| function_header "external" STRING_LITERAL ";"
4871
@@ -57,10 +80,11 @@ param_def_list ::= param_def ("," param_def)* ("," "...")?
5780
param_def ::= param_modifier? identifier_list ":" type_spec
5881
5982
param_modifier ::= "ref" | "const"
83+
```
6084

61-
(* No separate return_type rule needed - incorporated into function_header *)
85+
## Type Specifications
6286

63-
(* Type Specifications *)
87+
```bnf
6488
type_spec ::= basic_type
6589
| pointer_type
6690
| array_type
@@ -84,8 +108,11 @@ field_def ::= identifier_list ":" type_spec
84108
85109
function_type ::= "function" parameter_list return_type
86110
| "procedure" parameter_list
111+
```
87112

88-
(* Statements *)
113+
## Statements
114+
115+
```bnf
89116
statement_block ::= "begin" statement_list "end"
90117
91118
statement_list ::= statement*
@@ -108,7 +135,11 @@ statement ::= assignment_statement ";"
108135
assignment_statement ::= lvalue ":=" expression
109136
110137
call_statement ::= expression
138+
```
139+
140+
### Control Flow Statements
111141

142+
```bnf
112143
if_statement ::= "if" expression "then" statement ("else" statement)?
113144
114145
while_statement ::= "while" expression "do" statement
@@ -135,8 +166,13 @@ return_statement ::= "return" expression?
135166
goto_statement ::= "goto" IDENTIFIER
136167
137168
label_statement ::= IDENTIFIER ":"
169+
```
170+
171+
**Note:** For Pascal-style for-loops (first form), the IDENTIFIER must refer to a previously declared variable of an ordinal type (integer types: int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, or char). Boolean, floating-point, string, pointer, array, and record types are not allowed as they lack practical discrete ordering semantics required by "to" and "downto" operations.
172+
173+
## Expressions
138174

139-
(* Expressions *)
175+
```bnf
140176
expression ::= conditional_expression
141177
142178
conditional_expression ::= logical_or_expression ("?" expression ":" conditional_expression)?
@@ -178,14 +214,38 @@ lvalue ::= IDENTIFIER
178214
| "(" lvalue ")"
179215
180216
constant ::= INTEGER_LITERAL | REAL_LITERAL | CHAR_LITERAL | BOOLEAN_LITERAL
217+
```
181218

182-
(* Comments - C-style *)
219+
## Lexical Elements
220+
221+
### Comments
222+
223+
C-style comments are supported:
224+
225+
```bnf
183226
COMMENT ::= "//" [^\n]* "\n"
184227
| "/*" .* "*/"
228+
```
229+
230+
### Literals
185231

232+
```bnf
186233
BOOLEAN_LITERAL ::= "true" | "false"
187234
IDENTIFIER ::= [a-zA-Z_][a-zA-Z0-9_]*
188235
INTEGER_LITERAL ::= [0-9]+ | "0x"[0-9a-fA-F]+ | "0"[0-7]+
189236
REAL_LITERAL ::= [0-9]+"."[0-9]+([eE][+-]?[0-9]+)?
190237
CHAR_LITERAL ::= "'"[^']"'"
191-
STRING_LITERAL ::= '"'[^"]*'"'
238+
STRING_LITERAL ::= '"'[^"]*'"'
239+
```
240+
241+
## Language Features
242+
243+
- **C99 syntax** with Pascal keywords and structure
244+
- **Mandatory main function** requirement
245+
- **Preprocessor directives** for include management and conditional compilation
246+
- **Strong typing** with comprehensive type system
247+
- **Pascal-style** begin/end blocks and control structures
248+
- **Modern data types** including sized integers and floating-point types
249+
- **Record types** for structured data
250+
- **Function pointers** and external function declarations
251+
- **Flexible variable declarations** that can appear anywhere in scope

0 commit comments

Comments
 (0)