Skip to content

Commit

Permalink
[grace] Cleaner semantics by introduction of a dummy variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kostis committed Mar 27, 2024
1 parent 7413404 commit ca3c313
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions grace/programs/functionestscope.grc
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -41,7 +43,6 @@ fun main() : nothing
writeString("Test 2 Success \n");
else
writeString("Test 2 Error \n");

}


Expand Down

0 comments on commit ca3c313

Please sign in to comment.