separated into modules, added parser and lexer for miniImp

This commit is contained in:
elvis
2024-11-13 21:50:44 +01:00
parent 57e2613602
commit 0ff17560ee
24 changed files with 1408 additions and 51 deletions

5
lib/utility/dune Normal file
View File

@ -0,0 +1,5 @@
(library
(name utility)
(public_name utility))
(include_subdirs qualified)

13
lib/utility/utility.ml Normal file
View File

@ -0,0 +1,13 @@
let rec pow a = function
| 0 -> 1
| 1 -> a
| n ->
let b = pow a (n / 2) in
b * b * (if n mod 2 = 0 then 1 else a)
let rec powmod a d = function
| 0 -> 1
| 1 -> a mod d
| n ->
let b = (powmod a d (n / 2)) mod d in
(((b * b) mod d) * (if n mod 2 = 0 then 1 else a)) mod d

3
lib/utility/utility.mli Normal file
View File

@ -0,0 +1,3 @@
val pow : int -> int -> int
val powmod : int -> int -> int -> int