From 8179a3ce0e27e420a1d48a15b281d19147ff8879 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 7 Aug 2018 13:50:22 -0400 Subject: [PATCH] added support for nested functions to the grammar --- example.src | 19 +++++++++---------- source/parser.c | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) 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); } -- 2.54.0