From 1946b457577c5c3ffb1690b766049797bcaa8bc3 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Wed, 23 May 2018 21:24:15 -0400 Subject: [PATCH] Add another test case - define recursive function --- tiger/src/exe/tiger_tests.ml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tiger/src/exe/tiger_tests.ml b/tiger/src/exe/tiger_tests.ml index 3e97eec..64eb01b 100644 --- a/tiger/src/exe/tiger_tests.ml +++ b/tiger/src/exe/tiger_tests.ml @@ -94,6 +94,38 @@ let test_03 = in ("test_03", code, tokens) +let test_04 = + let name = "define a recursive function" in + let code = + " \ + /* "^name^" */ \ + let \ + \ + /* calculate n! */ \ + function nfactor(n: int): int = \ + if n = 0 \ + then 1 \ + else n * nfactor(n-1) \ + \ + in \ + nfactor(10) \ + end \ + " + in + let tokens = + let open Tiger.Parser.Token in + [ LET; + FUNCTION; ID "nfactor"; LPAREN; ID "n"; COLON; ID "int"; RPAREN; COLON; ID "int"; EQ; + IF; ID "n"; EQ; INT 0; + THEN; INT 1; + ELSE; ID "n"; TIMES; ID "nfactor"; LPAREN; ID "n"; MINUS; INT 1; RPAREN; + IN; + ID "nfactor"; LPAREN; INT 10; RPAREN; + END + ] + in + (name, code, tokens) + let tokens_of_code code = let lexbuf = Lexing.from_string code in let rec tokens () = @@ -107,6 +139,7 @@ let tests = [ test_01 ; test_02 ; test_03 + ; test_04 ] let () = -- 2.20.1