on master help sign in
initial binop priority
dc16d35iko
@@ -5,3 +5,4 @@
5- [x] check if int fits in int or make it a float
5- [x] check if int fits in int or make it a float
6- [x] should `print-blok` have `do`-`end`? This is fucked.
6- [x] should `print-blok` have `do`-`end`? This is fucked.
7- [ ] binary operator priority
7- [ ] binary operator priority
8+- [ ] ^ should be higher priority than unary ops
desk/lib/bintree.hoonnew file+8
@@ -0,0 +1,8 @@
1+|%
2+++ bintree
3+ |$ [node leaf]
4+ $%
5+ [%node l=(bintree node leaf) n=node r=(bintree node leaf)]
6+ [%leaf leaf]
7+ ==
8+--
desk/lib/interlist.hoon+34−1
@@ -6,7 +6,24 @@
6 [%double =val =sep tail=(interlist sep val)]
6 [%double =val =sep tail=(interlist sep val)]
7 [%single =val]
7 [%single =val]
8 ==
8 ==
9+++ reverse
10+ |* l=(interlist)
11+ ^+ l
12+ =/ tmp=(unit _?>(?=(%double -.l) +>.l)) ~
13+ |-
14+ ^+ l
15+ ?- -.l
16+ %single
17+ ?~ tmp l [%double +.l u.tmp]
18+ %double
19+ %= $
20+ l +>+.l
21+ tmp
22+ ?~ tmp `[+>-.l [%single +<.l]]
23+ `[+>-.l [%double +<.l u.tmp]]
24+ ==
25+ ==
9−++ parse-interlist
26+++ parse
10 |* [s=rule v=rule]
27 |* [s=rule v=rule]
11 =/ val (rule-type v)
28 =/ val (rule-type v)
12 =/ sep (rule-type s)
29 =/ sep (rule-type s)
@@ -21,6 +38,22 @@
21 [[%double v last-sep acc] s]
38 [[%double v last-sep acc] s]
22 [%double v +.tail -.tail]
39 [%double v +.tail -.tail]
23 ;~(plug v (star ;~(plug s v)))
40 ;~(plug v (star ;~(plug s v)))
41+++ split-left-on
42+ |* [is-pivot=$-(* *) l=(interlist)]
43+ ^- (unit _[lhs=l pivot=+<.is-pivot rhs=l])
44+ ?- -.l
45+ %single ~
46+ %double
47+ ?: (is-pivot sep.l) `[[%single val.l] sep.l tail.l]
48+ =/ rest $(l tail.l)
49+ ?~ rest ~
50+ `[[%double val.l sep.l lhs.u.rest] pivot.u.rest rhs.u.rest]
51+ ==
52+++ split-right-on
53+ |* [is-pivot=$-(* *) l=(interlist * *)]
54+ ^- (unit _[lhs=l pivot=+<.is-pivot rhs=l])
55+ %+ bind (split-left-on is-pivot (reverse l))
56+ |* [a=(interlist * *) b=* c=(interlist * *)] [(reverse c) b (reverse a)]
24--
57--
25|%
58|%
26++ rule-type
59++ rule-type
desk/lib/lua/parser.hoon+60−8
@@ -1,6 +1,7 @@
1/- *lua
1/- *lua
2/+ st
2/+ st
3−/+ *interlist
3+/+ interlist
4+/+ *bintree
4=<
5=<
5apex
6apex
6|%
7|%
@@ -75,17 +76,64 @@ apex
75:: Parse expressions separated by binary operators
76:: Parse expressions separated by binary operators
76::
77::
77++ parse-expr-list
78++ parse-expr-list
78− %^ tnee %parse-expr-list (interlist binop expr)
79+ %^ tnee %parse-expr-list (interlist:interlist binop expr)
79− %+ parse-interlist (ifix [ws ws] parse-binop) parse-atomic-expr
80+ %+ parse:interlist (ifix [ws ws] parse-binop) parse-atomic-expr
80:: TODO: This is mock and should take operator priority into account.
81:: TODO: This is mock and should take operator priority into account.
81::
82::
82++ process-expr-list
83++ process-expr-list
84+ =<
83− |= l=(interlist binop expr)
85+ |= l=(interlist:interlist binop expr)
84 ^- expr
86 ^- expr
85− ?- -.l
87+ %- strip-tree
88+ %- (process-left-assoc ~[%or])
89+ %- (process-left-assoc ~[%and])
90+ %- (process-left-assoc ~[%lt %gt %lteq %gteq %neq %eq])
91+ %- (process-left-assoc ~[%bor])
92+ %- (process-left-assoc ~[%bxor])
93+ %- (process-left-assoc ~[%band])
94+ %- (process-left-assoc ~[%rshft %lshft])
95+ %- (process-right-assoc ~[%concat])
96+ %- (process-left-assoc ~[%add %sub])
97+ %- (process-left-assoc ~[%mul %div %int-div %mod])
98+ %- (process-left-assoc ~[%pow])
99+ [%leaf l]
100+ |%
101+ ++ strip-tree
102+ |= tree=(bintree binop (interlist:interlist binop expr))
103+ ^- expr
104+ ?- -.tree
86− %single val.l
105+ %leaf ?> ?=(%single +<.tree) +>.tree
87− %double [%binop val.l sep.l (process-expr-list tail.l)]
106+ %node [%binop $(tree l.tree) n.tree $(tree r.tree)]
88− ==
107+ ==
108+ ++ process-right-assoc
109+ |= ops=(lest binop)
110+ |= tree=(bintree binop (interlist:interlist binop expr))
111+ ^+ tree
112+ ?- -.tree
113+ %leaf
114+ =/ l +.tree
115+ |-
116+ =/ splitted (split-left-on:interlist |=(op=binop (elem op ops)) l)
117+ ?~ splitted [%leaf l]
118+ [%node $(l lhs.u.splitted) pivot.u.splitted $(l rhs.u.splitted)]
119+ %node
120+ [%node $(tree l.tree) n.tree $(tree r.tree)]
121+ ==
122+ ++ process-left-assoc
123+ |= ops=(lest binop)
124+ |= tree=(bintree binop (interlist:interlist binop expr))
125+ ^+ tree
126+ ?- -.tree
127+ %leaf
128+ =/ l +.tree
129+ |-
130+ =/ splitted (split-right-on:interlist |=(op=binop (elem op ops)) l)
131+ ?~ splitted [%leaf l]
132+ [%node $(l lhs.u.splitted) pivot.u.splitted $(l rhs.u.splitted)]
133+ %node
134+ [%node $(tree l.tree) n.tree $(tree r.tree)]
135+ ==
136+ --
89++ parse-expr
137++ parse-expr
90 %^ tnee %parse-expr expr
138 %^ tnee %parse-expr expr
91 %+ cook process-expr-list parse-expr-list
139 %+ cook process-expr-list parse-expr-list
@@ -893,4 +941,8 @@ apex
893 ^- ?
941 ^- ?
894 &(?=(~ body.blok) ?=(~ ret.blok))
942 &(?=(~ body.blok) ?=(~ ret.blok))
895++ max-int 9.223.372.036.854.775.807
943++ max-int 9.223.372.036.854.775.807
944+++ elem
945+ |= [nedl=* stak=(list *)]
946+ ^- ?
947+ ?=(^ (find ~[nedl] stak))
896--
948--
desk/lib/lua/printer.hoon−1
@@ -56,7 +56,6 @@ print
56 ==
56 ==
57:: string
57:: string
58::
58::
59−:: NOTE: does not handle escaping chars
60++ print-string
59++ print-string
61 |= =string
60 |= =string
62 %- zing
61 %- zing