1010#include "ps_array.h"
1111#include "ps_functions.h"
1212#include "ps_parse.h"
13+ #include "ps_parse_executable.h"
1314#include "ps_parse_expression.h"
1415#include "ps_parser.h"
1516#include "ps_procedures.h"
1617#include "ps_string.h"
1718#include "ps_system.h"
1819
19- // #define MODE_EXEC 0
20- // static int mode = MODE_EXEC;
21-
2220/**
23- * This is the entry point for visiting all expressions.
21+ * This is the entry point for parsing all expressions.
2422 */
2523bool ps_parse_expression (ps_compiler * compiler , ps_ast_block * block , ps_ast_node * * expression )
2624{
2725 return ps_parse_or_expression (compiler , block , expression );
2826}
2927
3028/**
31- * Visit
29+ * Parse
3230 * or_expression = and_expression { ( 'OR' | 'XOR' ) and_expression }
3331 * Goal:
3432 * make A < 1 OR A > 10 OR A = 5 OR ... work without parenthesis
3533 * AST:
3634 * A => A
3735 * A or B => binary_op(or, A, B)
38- * A or B xor C => binary_op(xor, binary (or, A, B), C)
36+ * A or B xor C => binary_op(xor, binary_op (or, A, B), C)
3937 */
4038bool ps_parse_or_expression (ps_compiler * compiler , ps_ast_block * block , ps_ast_node * * expression )
4139{
@@ -78,7 +76,7 @@ bool ps_parse_or_expression(ps_compiler *compiler, ps_ast_block *block, ps_ast_n
7876}
7977
8078/**
81- * Visit and expression:
79+ * Parse and expression:
8280 * relational_expression { 'AND' relational_expression }
8381 * Goal:
8482 * make A < 1 AND A > 10 AND B = 5 AND ... work without parenthesis
@@ -129,7 +127,7 @@ bool ps_parse_and_expression(ps_compiler *compiler, ps_ast_block *block, ps_ast_
129127}
130128
131129/**
132- * Visit relational expression:
130+ * Parse relational expression:
133131 * simple_expression '<' | '<=' | '>' | '>=' | '=' | '<>' simple_expression
134132 * AST:
135133 * A => A
@@ -172,7 +170,7 @@ bool ps_parse_relational_expression(ps_compiler *compiler, ps_ast_block *block,
172170}
173171
174172/**
175- * Visit simple expression:
173+ * Parse simple expression:
176174 * term [ '+' | '-' term ]*
177175 * NB: 'OR' | 'XOR' are accounted by or_expression
178176 * AST:
@@ -224,7 +222,7 @@ bool ps_parse_simple_expression(ps_compiler *compiler, ps_ast_block *block, ps_a
224222}
225223
226224/**
227- * Visit term:
225+ * Parse term:
228226 * factor [ '*' | '/' | 'DIV' | 'MOD' | 'AND' | 'SHL' | 'SHR' | 'AS' factor ]*
229227 */
230228bool ps_parse_term (ps_compiler * compiler , ps_ast_block * block , ps_ast_node * * expression )
@@ -315,22 +313,24 @@ bool ps_parse_factor_identifier_array(ps_compiler *compiler, ps_ast_block *block
315313}
316314
317315/**
318- * @brief Visit constant or variable reference or function call
316+ * @brief Parse constant or variable reference or function call
319317 * @details
320318 * Actual:
321319 * constant reference = identifier
320+ * variable reference = identifier
322321 * function call = identifier [ '(' [ expression [ ',' expression ]* ]')' ]
323322 * Next step:
324323 * vector access
325324 * variable reference = identifier [ '[' expression ']' ]
326325 * multi-dimensional arrays instead of vectors
327326 * variable reference = identifier [ '[' expression [ ',' expression ]* ']' ]
328327 */
329- bool ps_parse_factor_identifier (ps_compiler * compiler , ps_ast_block * block , const char * identifier ,
330- ps_ast_node * * factor )
328+ bool ps_parse_factor_identifier (ps_compiler * compiler , ps_ast_block * block , ps_ast_node * * factor )
331329{
332330 PARSE_BEGIN ("FACTOR" , "IDENTIFIER" );
333331
332+ ps_identifier identifier ;
333+ COPY_IDENTIFIER (identifier )
334334 ps_symbol * symbol = ps_compiler_find_symbol (compiler , block , identifier , false);
335335 if (symbol == NULL )
336336 RETURN_ERROR (PS_ERROR_SYMBOL_NOT_FOUND );
@@ -344,7 +344,7 @@ bool ps_parse_factor_identifier(ps_compiler *compiler, ps_ast_block *block, cons
344344 ps_symbol_get_kind_name (symbol -> kind ),
345345 ps_type_definition_get_name (symbol -> value -> type -> value -> data .t ));
346346 }
347- if (ps_value_is_array (symbol -> value ))
347+ isymbol (ps_value_is_array (symbol -> value ))
348348 {
349349 RETURN_ERROR (PS_ERROR_NOT_IMPLEMENTED )
350350 // if (!ps_parse_factor_identifier_array(compiler, block, symbol, factor))
@@ -372,7 +372,7 @@ bool ps_parse_factor_identifier(ps_compiler *compiler, ps_ast_block *block, cons
372372}
373373
374374/**
375- * @brief Visit factor
375+ * @brief Parse factor
376376 * @details
377377 * factor = '(' , expression , ')'
378378 * | variable_reference
@@ -388,7 +388,6 @@ bool ps_parse_factor(ps_compiler *compiler, ps_ast_block *block, ps_ast_node **e
388388 PARSE_BEGIN ("FACTOR" , "" );
389389
390390 ps_value factor_value = {.type = & ps_system_none , .data .v = NULL };
391- ps_identifier identifier ;
392391 ps_token_type unary_operator ;
393392
394393 switch (lexer -> current_token .type )
@@ -403,8 +402,7 @@ bool ps_parse_factor(ps_compiler *compiler, ps_ast_block *block, ps_ast_node **e
403402 break ;
404403 // *** Identifier: variable, constant, function ***
405404 case PS_TOKEN_IDENTIFIER :
406- COPY_IDENTIFIER (identifier )
407- if (!ps_parse_factor_identifier (compiler , block , identifier , expression ))
405+ if (!ps_parse_factor_identifier (compiler , block , expression ))
408406 TRACE_ERROR ("IDENTIFIER ")
409407 break ;
410408 // ***Literal values ***
@@ -457,12 +455,12 @@ bool ps_parse_factor(ps_compiler *compiler, ps_ast_block *block, ps_ast_node **e
457455 case PS_TOKEN_NOT :
458456 unary_operator = lexer -> current_token .type ;
459457 READ_NEXT_TOKEN
460- ps_ast_node * operand = NULL ;
461- if (!ps_parse_factor (compiler , block , & operand ))
458+ ps_ast_node * * operand = NULL ;
459+ if (!ps_parse_factor (compiler , block , operand ))
462460 TRACE_ERROR ("UNARY_MINUS_NOT" );
463- * expression = ps_ast_create_unary_operation ( start_line , start_column ,
464- ps_operator_unary_from_token ( lexer -> current_token . type ), & operand );
465- break ;
461+ ps_operator_unary unary_operator = ps_operator_unary_from_token ( lexer -> current_token . type );
462+ * expression = ps_ast_create_unary_operation ( start_line , start_column , unary_operator , operand );
463+ PARSE_END ( "OK UNARY" )
466464 default :
467465 RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
468466 }
@@ -562,7 +560,7 @@ bool ps_parse_function_call_power(ps_compiler *compiler, ps_ast_block *block, ps
562560}
563561
564562/**
565- * Visit system function call:
563+ * Parse system function call:
566564 * identifier [ '(' , expression | variable_reference [ ',' , expression | variable_reference ]* ')' ]
567565 */
568566bool ps_parse_function_call_system (ps_compiler * compiler , ps_ast_block * block , ps_ast_call * * call ,
@@ -574,7 +572,6 @@ bool ps_parse_function_call_system(ps_compiler *compiler, ps_ast_block *block, p
574572 ps_ast_node * args [2 ] = {NULL , NULL };
575573 ps_symbol * symbol = NULL ;
576574
577- // Handle specific function types with dedicated handlers
578575 if (function == & ps_system_function_random )
579576 {
580577 ps_ast_node * expression = NULL ;
@@ -601,6 +598,7 @@ bool ps_parse_function_call_system(ps_compiler *compiler, ps_ast_block *block, p
601598 n_args = -1 ;
602599 if (!ps_parse_function_call_low_high (compiler , block , & symbol ))
603600 TRACE_ERROR ("LOW_HIGH" )
601+ args [0 ] = symbol ;
604602 }
605603 else if (function == & ps_system_function_power )
606604 {
@@ -650,7 +648,7 @@ bool ps_parse_function_call_system(ps_compiler *compiler, ps_ast_block *block, p
650648}
651649
652650/**
653- * Visit system or user function call:
651+ * Parse system or user function call:
654652 * identifier [ '(' , expression | variable_reference [ ',' , expression | variable_reference ]* ')' ]
655653 */
656654bool ps_parse_function_call (ps_compiler * compiler , ps_ast_block * block , ps_ast_node * * expression , ps_symbol * function )
@@ -676,7 +674,7 @@ bool ps_parse_function_call(ps_compiler *compiler, ps_ast_block *block, ps_ast_n
676674}
677675
678676/**
679- * Visit constant expression:
677+ * Parse constant expression:
680678 * [ '-' ] INTEGER_VALUE
681679 * | UNSIGNED_VALUE
682680 * | CHAR_VALUE
0 commit comments