Skip to content

Commit 180772d

Browse files
committed
AST WIP
1 parent 895bead commit 180772d

4 files changed

Lines changed: 23 additions & 24 deletions

File tree

include/ps_parse_executable.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212
#include "ps_compiler.h"
1313
#include "ps_lexer.h"
14+
#include "ps_symbol.h"
1415

1516
#ifdef __cplusplus
1617
extern "C"
1718
{
1819
#endif
1920

20-
bool ps_parse_procedure_or_function_declaration(ps_compiler *compiler, ps_symbol_kind kind);
21-
bool ps_parse_procedure_or_function_call(ps_compiler *compiler, ps_ast_block *block, ps_ast_node *expression,
21+
bool ps_parse_procedure_or_function_declaration(ps_compiler *compiler, ps_ast_block *block,
22+
ps_ast_block **executable, ps_symbol_kind kind);
23+
bool ps_parse_procedure_or_function_call(ps_compiler *compiler, ps_ast_block *block, ps_ast_call **call,
2224
ps_symbol *executable);
2325
bool ps_parse_variable_reference(ps_compiler *compiler, ps_ast_block *block, ps_symbol **variable);
2426

src/ps_parse_declaration.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ bool ps_parse_block(ps_compiler *compiler, ps_ast_block *block)
218218
}
219219
} while (loop);
220220

221-
ps_ast_statement_list *statement_list = NULL;
222-
if (!ps_parse_compound_statement(compiler, block, &statement_list))
223-
TRACE_ERROR("COMPOUND")
221+
ps_ast_statement_list **statement_list = NULL;
222+
if (!ps_parse_compound_statement(compiler, block, statement_list))
223+
TRACE_ERROR("COMPOUND_STATEMENT")
224224
block->statement_list = statement_list;
225225

226226
PARSE_END("OK")

src/ps_parse_executable.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ bool ps_parse_actual_signature(ps_compiler *compiler, ps_ast_block *block, ps_as
157157
ps_symbol *argument = NULL;
158158
ps_value *value = NULL;
159159
ps_symbol *variable = NULL;
160-
ps_value result;
161160
uint8_t parameter_count = formal_signature->parameter_count;
162161
uint8_t i = 0;
163162
ps_ast_node *args[16] = {0};
@@ -250,20 +249,18 @@ bool ps_parse_actual_signature(ps_compiler *compiler, ps_ast_block *block, ps_as
250249

251250
/**
252251
* Visit procedure or functions (with return type) declaration:
253-
* PROCEDURE IDENTIFIER [ ( PARAMETER_DEFINITION [ , PARAMETER_DEFINITION ] ) ] ;
254-
* FUNCTION IDENTIFIER [ ( PARAMETER_DEFINITION [ , PARAMETER_DEFINITION ] ) ] : TYPE_REFERENCE ;
252+
* PROCEDURE IDENTIFIER [ '(' PARAMETER_DEFINITION [ ',' PARAMETER_DEFINITION ] ')' ] ';'
253+
* FUNCTION IDENTIFIER [ '(' PARAMETER_DEFINITION [ ',' PARAMETER_DEFINITION ] ')' ] ':' TYPE_REFERENCE ';'
255254
* [ CONST ... TYPE ... VAR ... ]*
256-
* BEGIN
257-
* COMPOUND_STATEMENT [ ; ]
258-
* END ;
259-
* PARAMETER_DEFINITION = IDENTIFIER [ ':' TYPE_REFERENCE ] [ 'VAR' ] ;
260-
* Done:
261-
* - allow procedure parameters
262-
* - allow by reference parameters
255+
* 'BEGIN'
256+
* COMPOUND_STATEMENT [ ';' ]
257+
* 'END' ';'
258+
* PARAMETER_DEFINITION = [ 'VAR' ] IDENTIFIER ':' TYPE_REFERENCE
263259
*/
264-
bool ps_parse_procedure_or_function_declaration(ps_compiler *compiler, ps_ast_block *block, ps_symbol_kind kind)
260+
bool ps_parse_procedure_or_function_declaration(ps_compiler *compiler, ps_ast_block *block, ps_ast_block **executable,
261+
ps_symbol_kind kind)
265262
{
266-
PARSE_BEGIN("PROCEDURE_OR_FUNCTION", "");
263+
PARSE_BEGIN("EXECUTABLE", "PROCEDURE_OR_FUNCTION");
267264

268265
ps_identifier identifier;
269266
ps_symbol *executable_symbol = NULL;
@@ -290,12 +287,12 @@ bool ps_parse_procedure_or_function_declaration(ps_compiler *compiler, ps_ast_bl
290287
executable_symbol = ps_compiler_find_symbol(compiler, block, identifier, true);
291288
if (executable_symbol != NULL)
292289
RETURN_ERROR(PS_ERROR_SYMBOL_EXISTS);
293-
// Create new environment for the procedure/function
294-
if (!ps_compiler_enter_environment(compiler, identifier))
295-
{
296-
goto cleanup;
297-
}
298-
has_environment = true;
290+
// // Create new environment for the procedure/function
291+
// if (!ps_compiler_enter_environment(compiler, identifier))
292+
// {
293+
// goto cleanup;
294+
// }
295+
// has_environment = true;
299296
READ_NEXT_TOKEN
300297

301298
// Initialize signature

src/ps_parse_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ bool ps_parse_assignment_or_procedure_call(ps_compiler *compiler, ps_ast_block *
398398
if (compiler->debug >= COMPILER_DEBUG_VERBOSE)
399399
fprintf(stderr, "INFO\tAssignment to current function '%s' as Result\n", (char *)identifier);
400400
// Assign to the not so implicit "Result" local variable
401-
symbol = ps_compiler_find_symbol(compiler, block, result_identifier, false);
401+
symbol = ps_compiler_find_symbol(compiler, block, "RESULT", false);
402402
}
403403
else
404404
{

0 commit comments

Comments
 (0)