grammar refactoring: build_visitor fixed & visitors tested

This commit is contained in:
ProgramSnail 2023-04-11 13:49:22 +03:00
parent 3c2d496a85
commit e4802896bd
35 changed files with 118128 additions and 91770 deletions

View file

@ -1,7 +1,5 @@
// "decl" is not required, but useful in module interface
decl sum ('A : #Add) : 'A -> 'A -> 'A
def sum : a b = a + b
def sum 'A : a b = a + b
decl fib : Int -> Int
def fib : n =
@ -16,25 +14,22 @@ def fact : n =
| n -> n * fact (n - 1)
decl find_prefix_hashes ('H : (#AccHash Char)) : String -> Array 'H
def find_prefix_hashes ('H : (#AccHash Char)) : str = {
def find_prefix_hashes 'H : str = {
var hashes = (Array 'H).new (str.size + 1)
; hashes.0 = 'H.of str.0
for i in 1..hashes.size do {
; hashes.i = hashes.(i - 1).clone
; hashes.i.append str.i
}
return hashes
; hashes.0 = 'H.of str.0
for i in 1..hashes.size do {
; hashes.i = hashes.(i - 1).clone
; hashes.i.append str.i
}
return hashes
}
// ?? other default constructor symbol (instead of placeholder _), etc. ??
// seporate first and last iteration of loop ?
// previous and next iterations ?
alias Hash = AccHash Char
decl find_substring : String -> String -> Array Index
def find_substring : str substr = {
alias Hash = AccHash Char
var result = (Array Index).empty
@ -64,7 +59,4 @@ decl mul : Int -> Int -> Int
def mul : x y = x * y
decl mul_10 : Int -> Int
def mul_10 = mul 10 // or argument can be used
// ?? is partial application feature needed ??
def mul_10 = mul 10