From: Michael D. Lowis Date: Tue, 7 Aug 2018 17:50:22 +0000 (-0400) Subject: added support for nested functions to the grammar X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8179a3ce0e27e420a1d48a15b281d19147ff8879;p=proto%2Fsclpl.git added support for nested functions to the grammar --- diff --git a/example.src b/example.src index b05e693..02b3cf1 100644 --- a/example.src +++ b/example.src @@ -35,15 +35,14 @@ fun main(args string[]) int { foo() bar(1) baz(1,2) -# if (123) {} -# if 123 {} -# if (123) {} else {} -# if (123) {} else if (123) {} -# if (123) {} else if (123) {} else {} -# if 123 {} else if 123 {} else {} -# -# fun main(args string[]) int { -# 123 -# } + if (123) {} + if 123 {} + if (123) {} else {} + if (123) {} else if (123) {} + if (123) {} else if (123) {} else {} + if 123 {} else if 123 {} else {} + fun main(args string[]) int { + 123 + } } diff --git a/source/parser.c b/source/parser.c index 2225da0..98ef30f 100644 --- a/source/parser.c +++ b/source/parser.c @@ -230,6 +230,8 @@ static AST* expression_block(Parser* p) { while (!matches(p, '}')) { if (matches(p, T_LET) || matches(p, T_VAR)) { definition(p); + } else if (matches(p, T_FUN)) { + func_definition(p); } else { expression(p); }