Skip to content

Commit

Permalink
simplify adverb parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
hoosierEE committed Jul 25, 2024
1 parent a4d027c commit 616b7b8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
__pycache__/
*.pyc

*.i
*.ii
*.gpu
Expand All @@ -8,7 +10,6 @@ __pycache__/

*.o

tests/doctest.h
# tests/doctest.h
a.out

.DS_Store
23 changes: 23 additions & 0 deletions examples/coltim-nn.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mmu:(+/*)\: / matrix-mul
sig:{1%1+`exp@-x} / sigmoid
infer:{sig mmu[x;y]} / feed foward/run model

train:{[in;out;w]
l:infer\[in;w] / feed forward
f:(out-),{mmu[;+x]}'|1_w / error calculations
ld:{z*y x}\[*|l;f;|l*1-l] / calculate deltas
w+{mmu[+x;y]}'[(,in),-1_l;|ld]} / update weights

in:-8?+2\!16 / input data
out:8?2 / output data

init:{x#1-(*/x)?2f} / initialize weights
iw:init'(4 10;10 4;4 4;4 5;5) / initialize layers

w:10000 train[in;out;]/iw / train model

in!out,'infer/[in;w] / model output

in2:+2\!16 / full set of possible input
round:{(_0.5+x*1000)%1000} / round output for display purposes
+(+2\!16)#0.0+0n^(in!out),'in2!round infer/[in2;w]
2 changes: 1 addition & 1 deletion prototype/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def loop(i=0) -> int|None:#return index of error-causing token (if any), else No
while n in ADVERB: k,i,n = Ast(n,k),i+1,nn(i)
if s:
debug('adverb')
if str(s[-1].name)[0] in ASSIGN+VERB+OPAREN: s.append(Op(k,1))
if not noun(str(s[-1].name)): s.append(Op(k,1))
else: d.append(Ast(s.pop().name)); s.append(Op(k,2))
else: s.append(Op(k,1))
if s[-1].arity==2: pad(n)
Expand Down
6 changes: 6 additions & 0 deletions prototype/dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .Ast import Ast
from .Builtin import *
from .Scanner import Scan
from .Parser import Parse
from .Semantic import *
from .Eval import Eval

0 comments on commit 616b7b8

Please sign in to comment.