1414#include "ps_token.h"
1515
1616/**
17- * Parse program parameters (identifiers in parentheses)
17+ * Parse/skip program parameters
18+ * [ '(' [ IDENTIFIER [ ',' IDENTIFIER ]* ] ')']
1819 */
19- static ps_ast_node * ps_parse_program_parameters (ps_compiler * compiler )
20+ static bool ps_parse_program_parameters (ps_compiler * compiler )
2021{
2122 PARSE_BEGIN ("PROGRAM" , "PARAMETERS" )
2223
2324 // Empty list?
2425 if (lexer -> current_token .type == PS_TOKEN_LEFT_PARENTHESIS )
2526 {
26- READ_NEXT_TOKEN
27+ READ_NEXT_TOKEN ( false )
2728 if (lexer -> current_token .type == PS_TOKEN_RIGHT_PARENTHESIS )
2829 {
29- READ_NEXT_TOKEN
30+ READ_NEXT_TOKEN ( false )
3031 PARSE_END ("OK" )
3132 }
3233 }
3334 bool loop = true;
3435 do
3536 {
3637 EXPECT_TOKEN (PS_TOKEN_IDENTIFIER )
37- READ_NEXT_TOKEN
38+ READ_NEXT_TOKEN ( false )
3839 switch (lexer - > current_token .type )
3940 {
4041 case PS_TOKEN_COMMA :
41- READ_NEXT_TOKEN
42+ READ_NEXT_TOKEN ( false )
4243 break ;
4344 case PS_TOKEN_RIGHT_PARENTHESIS :
44- READ_NEXT_TOKEN
45+ READ_NEXT_TOKEN ( false )
4546 loop = false;
4647 break ;
4748 default :
@@ -55,11 +56,11 @@ static ps_ast_node *ps_parse_program_parameters(ps_compiler *compiler)
5556/**
5657 * Parse program declaration:
5758 * PROGRAM IDENTIFIER [ '(' [ IDENTIFIER [ ',' IDENTIFIER ]* ] ')'] ';'
58- * identifiers are ignored
59+ * BLOCK '.'
5960 */
6061ps_ast_node * ps_parse_program (ps_compiler * compiler )
6162{
62- PARSE_BEGIN ( "PROGRAM" , "" )
63+ PARSE_BEGIN_AST ( ps_ast_block , "PROGRAM" , "" )
6364 uint16_t line = lexer -> buffer -> current_line ;
6465 uint16_t column = lexer -> buffer -> current_column ;
6566
@@ -68,21 +69,22 @@ ps_ast_node *ps_parse_program(ps_compiler *compiler)
6869
6970 // 'PROGRAM'
7071 EXPECT_TOKEN (PS_TOKEN_PROGRAM )
71- READ_NEXT_TOKEN
72+ READ_NEXT_TOKEN ( NULL )
7273
7374 // IDENTIFIER
7475 EXPECT_TOKEN (PS_TOKEN_IDENTIFIER )
7576 COPY_IDENTIFIER (identifier )
76- READ_NEXT_TOKEN
77+ READ_NEXT_TOKEN ( NULL )
7778
7879 // Skip optional parameters enclosed in parentheses
79- ps_parse_program_parameters (compiler );
80- if (compiler -> error != PS_ERROR_NONE )
80+ if (!ps_parse_program_parameters (compiler ))
8181 TRACE_ERROR ("PARAMETERS ")
82+
83+ // ;
8284 EXPECT_TOKEN (PS_TOKEN_SEMI_COLON )
83- READ_NEXT_TOKEN
85+ READ_NEXT_TOKEN ( NULL )
8486
85- // Register program in symbol table and visit its block
87+ // Register program in symbol table of new environment
8688 if (!ps_compiler_enter_environment (compiler , identifier ))
8789 TRACE_ERROR ("ENTER ENVIRONMENT ")
8890 symbol_program = ps_symbol_alloc (PS_SYMBOL_KIND_PROGRAM , identifier , NULL );
@@ -115,7 +117,7 @@ ps_ast_node *ps_parse_program(ps_compiler *compiler)
115117}
116118
117119/**
118- * Parse uses clause (module names after USES)
120+ * Parse/skip uses clause (module names after USES)
119121 */
120122static ps_ast_node * ps_parse_uses_clause (ps_compiler * compiler )
121123{
@@ -126,14 +128,14 @@ static ps_ast_node *ps_parse_uses_clause(ps_compiler *compiler)
126128 {
127129 if (lexer -> current_token .type != PS_TOKEN_IDENTIFIER )
128130 RETURN_ERROR (PS_ERROR_EXPECTED_IDENTIFIER )
129- READ_NEXT_TOKEN
131+ READ_NEXT_TOKEN ( NULL )
130132 switch (lexer -> current_token .type )
131133 {
132134 case PS_TOKEN_COMMA :
133- READ_NEXT_TOKEN
135+ READ_NEXT_TOKEN ( NULL )
134136 break ;
135137 case PS_TOKEN_SEMI_COLON :
136- READ_NEXT_TOKEN
138+ READ_NEXT_TOKEN ( NULL )
137139 loop = false;
138140 break ;
139141 default :
@@ -146,11 +148,11 @@ static ps_ast_node *ps_parse_uses_clause(ps_compiler *compiler)
146148
147149ps_ast_node * ps_parse_uses (ps_compiler * compiler )
148150{
149- PARSE_BEGIN ( "USES" , "" )
151+ PARSE_BEGIN_AST ( ps_ast_node , "USES" , "" )
150152
151153 if (lexer -> current_token .type == PS_TOKEN_USES )
152154 {
153- READ_NEXT_TOKEN
155+ READ_NEXT_TOKEN ( NULL )
154156 ast = ps_parse_uses_clause (compiler );
155157 if (NULL == ast )
156158 TRACE_ERROR ("USES CLAUSE" )
0 commit comments