From: Michael D. Lowis Date: Tue, 19 Jun 2018 18:58:00 +0000 (-0400) Subject: added parsing rule for function calls and stubbed out hooks for if/for/while/do-while... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=ef1d732cf7beb9e41d7b8646b4b50f1ecda64b8a;p=proto%2Fsclpl.git added parsing rule for function calls and stubbed out hooks for if/for/while/do-while statements --- diff --git a/example.src b/example.src index 269ce45..2a2416d 100644 --- a/example.src +++ b/example.src @@ -33,6 +33,9 @@ fun main() int { {123;} 123; (123); + foo(); + bar(1); + baz(1,2); return bar; } diff --git a/source/parser.c b/source/parser.c index 60f0feb..524df58 100644 --- a/source/parser.c +++ b/source/parser.c @@ -13,6 +13,7 @@ static AST* expression_block(Parser* p); static AST* statement(Parser* p); static AST* expression(Parser* p); static AST* definition(Parser* p, bool constant); +static AST* func_expr_list(Parser* p); static AST* const_expression(Parser* p); static AST* identifier(Parser* p); @@ -205,11 +206,17 @@ static AST* statement(Parser* p) { if (matches(p, '{')) { expression_block(p); } else { - if (accept(p, T_RETURN)) { + if (matches(p, T_LET) || matches(p, T_VAR)) { + definition(p, (peek(p)->type == T_LET)); + } else if (accept(p, T_RETURN)) { expression(p); expect(p, ';'); - } else if (matches(p, T_LET) || matches(p, T_VAR)) { - definition(p, (peek(p)->type == T_LET)); +// } else if (matches(p, T_IF)) { +// } else if (matches(p, T_WHILE)) { +// } else if (matches(p, T_FOR)) { +// } else if (matches(p, T_DO)) { +// } else if (matches(p, T_SWITCH)) { +// } else if (matches(p, T_MATCH)) { } else { expression(p); expect(p, ';'); @@ -225,6 +232,8 @@ static AST* expression(Parser* p) { expect(p, ')'); } else if (matches(p, T_ID)) { expr = identifier(p); + if (matches(p, '(')) + func_expr_list(p); } else { expr = literal(p); } @@ -237,12 +246,25 @@ static AST* definition(Parser* p, bool constant) { expect(p, T_ID); type_expression(p); expect(p, '='); - const_expression(p); + expression(p); expect(p, ';'); return NULL; } - +static AST* func_expr_list(Parser* p) { + expect(p, '('); + if (!matches(p, ')')) { + while (true) { + expression(p); + if (!matches(p, ')')) + expect(p, ','); + else + break; + } + } + expect(p, ')'); + return NULL; +}