From ca3c313b0ed799595e2ac3cbf9f2ebe4f6fb5009 Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Wed, 27 Mar 2024 09:58:43 +0100 Subject: [PATCH] [grace] Cleaner semantics by introduction of a dummy variable --- grace/programs/functionestscope.grc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/grace/programs/functionestscope.grc b/grace/programs/functionestscope.grc index 70adf7d..0a6c823 100644 --- a/grace/programs/functionestscope.grc +++ b/grace/programs/functionestscope.grc @@ -1,28 +1,30 @@ $$ This program tests the scope implementation in recursive and nested functions. - It includes a function to test variable scope in a simple recursion (recursiveScopeCheck) - and another to test scope in nested function calls (nestedCheck). + + It includes a function (recursiveScopeCheck) to test variable scope in a simple + recursion and another one (nestedCheck) to test scope in nested function calls. $$ fun main() : nothing - var res :int; - fun recursiveScopeCheck(n:int):int - var localvar :int; + var res : int; + + fun recursiveScopeCheck(n : int) : int + var localvar : int; + var dummy : int; { localvar <- n; if n = 0 then return 0; - recursiveScopeCheck(n-1); + dummy <- recursiveScopeCheck(n-1); return localvar; } - - fun nestedCheck():nothing - var num: int; - fun nestedCheck2():nothing - fun nestedCheck3():nothing - fun nestedCheck4():nothing + fun nestedCheck() : nothing + var num : int; + fun nestedCheck2() : nothing + fun nestedCheck3() : nothing + fun nestedCheck4() : nothing { num <- 2; } @@ -41,7 +43,6 @@ fun main() : nothing writeString("Test 2 Success \n"); else writeString("Test 2 Error \n"); - }