interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / node / gram.om

183 lines · 3133 bytes Raw Blame History
1note seed/node/gram.om -- the bounded repair grammar of the round40 protocol
2note (repair.py PATTERNS), shared by the tool adapter (seed/node/tool.om,
3note which checks a file) and the coding workflow (seed/node/code.om, whose
4note creator checks a proposed edit before granting it). Compiles as OM-1 and
5note OM-2; compose before its user. Lines are split at newline bytes only,
6note after the source is trimmed of ASCII white space (bytes 0..32).
7note Lines: fn calc x int to int | fn main to int | end | s = x | ret s |
8note ret (add|mul|sub) x int [1-6] | ret calc int \d{1,2} |
9note for i ulong [1-6] | s = add s int [1-6].
10text gcalc "fn calc x int to int"
11text gmain "fn main to int"
12text gend "end"
13text gradd "ret add x int "
14text grmul "ret mul x int "
15text grsub "ret sub x int "
16text grcal "ret calc int "
17text gsx "s = x"
18text gfor "for i ulong "
19text gsadd "s = add s int "
20text grets "ret s"
21
22note Grammar text k (0 calc, 1 main, 2 end, 3 s = x, 4 ret s, 5 ret calc
23note int, 6 ret add, 7 ret mul, 8 ret sub, 9 for, 10 s = add): its length.
24fn gr_tln k ulong to ulong
25if eq k 0
26ret len gcalc
27end
28if eq k 1
29ret len gmain
30end
31if eq k 2
32ret len gend
33end
34if eq k 3
35ret len gsx
36end
37if eq k 4
38ret len grets
39end
40if eq k 5
41ret len grcal
42end
43if le k 8
44ret len gradd
45end
46if eq k 9
47ret len gfor
48end
49ret len gsadd
50end
51
52note Byte i of grammar text k.
53fn gr_tch k ulong i ulong to uchar
54if eq k 0
55ret get gcalc i
56end
57if eq k 1
58ret get gmain i
59end
60if eq k 2
61ret get gend i
62end
63if eq k 3
64ret get gsx i
65end
66if eq k 4
67ret get grets i
68end
69if eq k 5
70ret get grcal i
71end
72if eq k 6
73ret get gradd i
74end
75if eq k 7
76ret get grmul i
77end
78if eq k 8
79ret get grsub i
80end
81if eq k 9
82ret get gfor i
83end
84ret get gsadd i
85end
86
87note Line s[a, e) is text k followed by one digit 1..6 when dg is 1, by one
88note or two digits when dg is 2, or exactly text k when dg is 0.
89fn gr_lin s view uchar 4096 a ulong e ulong k ulong dg ulong to bool
90n = gr_tln k
91if lt sub e a n
92ret false
93end
94for i ulong n
95if ne get s add a i gr_tch k i
96ret false
97end
98end
99r = sub sub e a n
100if eq dg 0
101ret eq r 0
102end
103if eq dg 1
104if ne r 1
105ret false
106end
107c = get s add a n
108ret and ge c 49 le c 54
109end
110if or eq r 0 gt r 2
111ret false
112end
113for j ulong r
114c = get s add add a n j
115if or lt c 48 gt c 57
116ret false
117end
118end
119ret true
120end
121
122note Line s[a, e) is in the grammar.
123fn gr_gram s view uchar 4096 a ulong e ulong to bool
124for k ulong 5
125if gr_lin s a e k 0
126ret true
127end
128end
129if gr_lin s a e 5 2
130ret true
131end
132for k2 ulong 5
133if gr_lin s a e add 6 k2 1
134ret true
135end
136end
137ret false
138end
139
140note The end of the line that starts at a (a newline or e).
141fn gr_eol b view uchar 4096 a ulong e ulong to ulong
142z = a
143for j ulong sub e a
144if eq get b z 10
145ret z
146end
147z = add z 1
148end
149ret z
150end
151
152note Every line of b[0, n), trimmed, is in the grammar (an empty source too).
153fn gr_src b view uchar 4096 n ulong to bool
154s = ulong 0
155for i ulong n
156if gt get b s 32
157break
158end
159s = add s 1
160end
161e = n
162for j ulong sub n s
163if gt get b sub e 1 32
164break
165end
166e = sub e 1
167end
168if ge s e
169ret true
170end
171a = s
172for it ulong add n 1
173if gt a e
174ret true
175end
176z = gr_eol b a e
177if not gr_gram b a z
178ret false
179end
180a = add z 1
181end
182ret true
183end