|
20 | 20 |
|
21 | 21 | <module_header> ::= "module" <identifier> ";" |
22 | 22 |
|
23 | | -<import_clause> ::= "import" <identifier_list> ";" |
| 23 | +<import_clause> ::= "import" <qualified_identifier_list> ";" |
| 24 | +
|
| 25 | +<qualified_identifier_list> ::= <qualified_identifier> ("," <qualified_identifier>)* |
| 26 | +
|
| 27 | +<qualified_identifier> ::= <identifier> ("." <identifier>)* |
24 | 28 |
|
25 | 29 | <identifier_list> ::= <identifier> ("," <identifier>)* |
26 | 30 |
|
27 | 31 | <exports_clause> ::= "exports" <export_list> ";" |
28 | 32 |
|
29 | | -<export_list> ::= <identifier> ("," <identifier>)* |
| 33 | +<export_list> ::= <qualified_identifier> ("," <qualified_identifier>)* |
30 | 34 | ``` |
31 | 35 |
|
32 | 36 | ## Compiler Directives |
|
113 | 117 | | "public"? <external_function> |
114 | 118 | | "public"? <inline_function> |
115 | 119 | | "public"? <varargs_function> |
| 120 | + | "public"? <external_varargs_function> |
116 | 121 |
|
117 | 122 | <function_header> ::= "function" <identifier> "(" <parameter_list>? ")" ":" <type_definition> |
118 | 123 | | "procedure" <identifier> "(" <parameter_list>? ")" |
|
135 | 140 |
|
136 | 141 | <varargs_function> ::= "function" <identifier> "(" <parameter_list> "," "..." ")" ":" <type_definition> <calling_convention>? ";" |
137 | 142 | | "procedure" <identifier> "(" <parameter_list> "," "..." ")" <calling_convention>? ";" |
| 143 | +
|
| 144 | +<external_varargs_function> ::= "function" <identifier> "(" <parameter_list> "," "..." ")" ":" <type_definition> <calling_convention>? "external" <string>? ";" |
| 145 | + | "function" <identifier> "(" <parameter_list> "," "..." ")" ":" <type_definition> "external" <string>? <calling_convention>? ";" |
| 146 | + | "procedure" <identifier> "(" <parameter_list> "," "..." ")" <calling_convention>? "external" <string>? ";" |
| 147 | + | "procedure" <identifier> "(" <parameter_list> "," "..." ")" "external" <string>? <calling_convention>? ";" |
138 | 148 | ``` |
139 | 149 |
|
140 | 150 | ## Statements |
@@ -384,4 +394,21 @@ PChar char* 8/4 8/4 |
384 | 394 | Records map to C structs with identical layout and alignment. |
385 | 395 | Arrays map to C arrays with identical memory layout. |
386 | 396 | Function pointers use C calling conventions by default. |
387 | | -``` |
| 397 | +``` |
| 398 | + |
| 399 | +## 🆕 External VarArgs Functions (Added for Phase 1A) |
| 400 | + |
| 401 | +The `<external_varargs_function>` rule enables essential C library integration by combining external function declarations with variadic arguments. This allows direct integration with functions like `printf`, `scanf`, and other C runtime functions that require variable argument lists. |
| 402 | + |
| 403 | +**Examples:** |
| 404 | +```pascal |
| 405 | +// Standard C runtime functions |
| 406 | +function printf(format: PChar, ...): Int32 cdecl external 'msvcrt.dll'; |
| 407 | +procedure fprintf(stream: Pointer; format: PChar, ...): cdecl external 'msvcrt.dll'; |
| 408 | +function scanf(format: PChar, ...): Int32 cdecl external 'msvcrt.dll'; |
| 409 | +
|
| 410 | +// Custom varargs functions from external libraries |
| 411 | +function MyLogger(level: Int32; format: PChar, ...): Boolean stdcall external 'mylib.dll'; |
| 412 | +``` |
| 413 | + |
| 414 | +This addition maintains full BNF compliance while enabling the essential external function capabilities required for real-world C library integration. |
0 commit comments