Compare commits

...

4 Commits

  1. 2
      lib.py
  2. 4
      lib/kokoro.klambda
  3. 2
      lib/lists.klambda
  4. 4
      lib/string.klambda
  5. 17
      main.py
  6. 3
      readme.txt
  7. 4
      test.klambda

@ -65,7 +65,7 @@ def execute(program):
return subs return subs
elif ctx[0] == _ident("miracle"): elif ctx[0] == _ident("miracle"):
return _box(eval(_destr(subs[1]))[_destr(subs[2])](*[(i if type(i) == type([]) else i[1]) for i in _fixarr(subs[3])])) return _box(getattr(eval(_destr(subs[1])), _destr(subs[2]))(*[(i if type(i) == type([]) else i[1]) for i in _fixarr(subs[3])]))
elif ctx[0] == _ident("def"): elif ctx[0] == _ident("def"):
ids[ctx[1]] = subs[2] ids[ctx[1]] = subs[2]
return ids[ctx[1]] return ids[ctx[1]]

@ -1,10 +1,10 @@
(def spit (lambda (cunny) (def spit (lambda (cunny)
(miracle (miracle
"__builtins__" "print" (id cunny)))) "__import__('builtins')" "print" (id cunny))))
(def input (lambda () (def input (lambda ()
(miracle (miracle
"__builtins__" "input" ("")))) "__import__('builtins')" "input" (""))))
(def thesis (lambda () (def thesis (lambda ()
(spit (spit
("this language belongs to makise kurisu. there are many like it, but this one is hers.")))) ("this language belongs to makise kurisu. there are many like it, but this one is hers."))))

@ -1,6 +1,6 @@
(def length (lambda (cunny) (def length (lambda (cunny)
(miracle (miracle
"__builtins__" "len" (cunny)))) "__import__('builtins')" "len" (cunny))))
(def append (lambda (item, victim) (def append (lambda (item, victim)
(insert (length victim) item victim))) (insert (length victim) item victim)))

@ -1,3 +1,3 @@
(def str2lst (lambda (l) (def str2lst (lambda (s)
(miracle (miracle
"__builtins__" "list" (l)))) "__import__('builtins')" "list" (s))))

@ -6,10 +6,9 @@ def isnum(n):
except: except:
return False return False
return True return True
reps = ["(", ")", "\"", ","]
f = open(sys.argv[1]).read()
def expand(file, path): def preprocess(filename):
def expand(file, path):
working_directory = pathlib.Path(path).parent.resolve() working_directory = pathlib.Path(path).parent.resolve()
tmp = file.replace("\\\n", "").split("\n") tmp = file.replace("\\\n", "").split("\n")
defs = {} defs = {}
@ -41,12 +40,12 @@ def expand(file, path):
#print(i, "\nsep") #print(i, "\nsep")
return (defs, "\n".join(tmp)) return (defs, "\n".join(tmp))
f = expand(f, sys.argv[1])[1] f = open(filename).read()
f = expand(f, sys.argv[1])[1]
f = f.replace(" ", " RDANEELOLIVAW ") # spacer
f = f.replace(" ", " RDANEELOLIVAW ") # spacer for r in ["(", ")", "\"", ","]: f = f.replace(r, " "+r+" ")
for r in reps: f = f.replace(r, " "+r+" ") return f.split()
f = f.split()
def tokenize(f): def tokenize(f):
toks = [] toks = []
@ -125,7 +124,7 @@ def structurize(program):
#print(tokenize(f)) #print(tokenize(f))
#print(lex(tokenize(f)), "\n") #print(lex(tokenize(f)), "\n")
program = structurize(lex(tokenize(f))) program = structurize(lex(tokenize(preprocess(sys.argv[1]))))
#lib.execute(structurize(lex(tokenize(f)))) #lib.execute(structurize(lex(tokenize(f))))
#print(program) #print(program)

@ -8,11 +8,12 @@ standard library.
syntax: syntax:
a program is a series of functions executed using one environment -- that is, sharing a program is a series of functions executed using one environment -- that is, sharing
defined variables and functions. some defined variables and functions.
these functions are executed homoiconic objects made up of language types: these functions are executed homoiconic objects made up of language types:
- list, `()` and everything inside. items are delimited by whitespace. - list, `()` and everything inside. items are delimited by whitespace.
- string, everything between `"` double quotes - string, everything between `"` double quotes
- number, everything capable of being represented as a decimal float value - number, everything capable of being represented as a decimal float value
- lambda, an anonymous expression containing the args and procedure
- identifier, everything else - identifier, everything else
lists starting with defined function identifiers are executed with the rest of the list lists starting with defined function identifiers are executed with the rest of the list
as parameters, i.e. (spit "hello~" (+ 9000 1)). runs `spit` using "hello" and (+ 9000 1). as parameters, i.e. (spit "hello~" (+ 9000 1)). runs `spit` using "hello" and (+ 9000 1).

@ -19,7 +19,7 @@ INCLUDE:./lib/aids.klambda
(id spit (cond (% i 15) (cond (% i 5) (cond (% i 3) i "fizz") "buzz") "fizzbuzz"))) (id spit (cond (% i 15) (cond (% i 5) (cond (% i 3) i "fizz") "buzz") "fizzbuzz")))
(def moeblob ("moe" "moe~" "kyun!!")) (def moeblob ("moe" "moe~" "kyun!!"))
(loop 0 (- (length moeblob) 1) (each moeblob
(id spit (at i moeblob))) (id spit item))
(thesis) (thesis)
Loading…
Cancel
Save