99#include "ps_executable.h"
1010#include "ps_memory.h"
1111#include "ps_parse.h"
12+ #include "ps_parse_expression.h"
1213#include "ps_parse_statement.h"
1314#include "ps_system.h"
1415#include "ps_token.h"
2021static bool ps_parse_program_parameters (ps_compiler * compiler , ps_ast_block * block )
2122{
2223 PARSE_BEGIN ("PROGRAM" , "PARAMETERS" )
24+ (void )start_line ;
25+ (void )start_column ;
2326
2427 // Empty list?
2528 if (lexer -> current_token .type == PS_TOKEN_LEFT_PARENTHESIS )
@@ -64,8 +67,6 @@ bool ps_parse_program(ps_compiler *compiler, ps_ast_block *block)
6467
6568 ps_identifier identifier = {0 };
6669 ps_symbol * symbol_program = NULL ;
67- uint16_t start_line = lexer -> start_line ;
68- uint16_t start_column = lexer -> start_column ;
6970
7071 // 'PROGRAM'
7172 EXPECT_TOKEN (PS_TOKEN_PROGRAM )
@@ -121,6 +122,8 @@ bool ps_parse_uses(ps_compiler *compiler, ps_ast_block *block)
121122{
122123 (void )block ;
123124 PARSE_BEGIN ("USES" , "" )
125+ (void )start_line ;
126+ (void )start_column ;
124127
125128 if (lexer -> current_token .type == PS_TOKEN_USES )
126129 {
@@ -164,6 +167,8 @@ bool ps_parse_uses(ps_compiler *compiler, ps_ast_block *block)
164167bool ps_parse_block (ps_compiler * compiler , ps_ast_block * block )
165168{
166169 PARSE_BEGIN ("BLOCK" , "" )
170+ (void )start_line ;
171+ (void )start_column ;
167172
168173 bool loop = true;
169174 do
@@ -211,8 +216,10 @@ bool ps_parse_block(ps_compiler *compiler, ps_ast_block *block)
211216 }
212217 } while (loop );
213218
214- if (!ps_parse_compound_statement (compiler , block ))
219+ ps_ast_statement_list * statement_list = NULL ;
220+ if (!ps_parse_compound_statement (compiler , block , & statement_list ))
215221 TRACE_ERROR ("COMPOUND" )
222+ block -> statement_list = statement_list ;
216223
217224 PARSE_END ("OK" )
218225}
@@ -226,7 +233,8 @@ bool ps_parse_block(ps_compiler *compiler, ps_ast_block *block)
226233 * Const
227234 * Foo = 42;
228235 * Bar = -3.14;
229- * Baz = True;
236+ * Baz = -Bar;
237+ * Flag = True;
230238 * Hello = 'Hello, World!';
231239 * ImageWidth = 320;
232240 * ImageHeight = 200;
@@ -239,16 +247,15 @@ bool ps_parse_block(ps_compiler *compiler, ps_ast_block *block)
239247 * IDENTIFIER '=' IDENTIFIER | CONSTANT_EXPRESSION ';'
240248 * Examples:
241249 * Const
242- * ImageWidth = 320;
243- * ImageHeight = 200;
244- * ImageDepth = 8;
245250 * ImagePixels = ImageWidth * ImageHeight;
246- * ImageSize = (ImagePixels * ImageDepth) div 8 ;
251+ * ImageSize = (ImagePixels * ImageDepth) div ImageDepth ;
247252 * Not implemented yet in lexer:
248253 * Lines = 'First line' #10 'Second line' #10 'Third line';
249254 */
250255bool ps_parse_const (ps_compiler * compiler , ps_ast_block * block )
251256{
257+ // NB: adds symbols to current block symbol table, does not produce any AST nodes
258+
252259 PARSE_BEGIN ("CONST" , "" )
253260
254261 ps_identifier identifier ;
@@ -293,11 +300,13 @@ bool ps_parse_const(ps_compiler *compiler, ps_ast_block *block)
293300 */
294301bool ps_parse_type (ps_compiler * compiler , ps_ast_block * block )
295302{
303+ // NB: adds symbols to current block symbol table, does not produce any AST nodes
304+
296305 PARSE_BEGIN ("TYPE" , "" );
297306
298- // RETURN_ERROR(PS_ERROR_NOT_IMPLEMENTED)
299307 EXPECT_TOKEN (PS_TOKEN_TYPE );
300308 READ_NEXT_TOKEN
309+
301310 if (lexer -> current_token .type != PS_TOKEN_IDENTIFIER )
302311 RETURN_ERROR (PS_ERROR_UNEXPECTED_TOKEN )
303312 do
0 commit comments