parser.nv
· 8.5 KiB · Text
Исходник
Playground
|================================|
|==| Constants. |==|
|================================|
|-----------------------|
| r0 <- 0, r0 | r0 <- 0 ,
| r0 <- 0 | ,
|-----------------------|
|-----------------------|
| r1 <- 0, r1 | r1 <- 0 ,
| r1 <- 0 | ,
|-----------------------|
|-------------------------------|
| r1 <- 1 | r1 ,
| r1 <- 2 | r1 <- 1, r1 <- 1 ,
| r1 <- 4 | r1 <- 2, r1 <- 2 ,
| r1 <- 8 | r1 <- 4, r1 <- 4 ,
| r1 <- 9 | r1 <- 8, r1 <- 1 ,
| r1 <- 10 | r1 <- 9, r1 <- 1 ,
| r1 <- 16 | r1 <- 8, r1 <- 8 ,
| r1 <- 32 | r1 <- 16, r1 <- 16 ,
| r1 <- 40 | r1 <- 32, r1 <- 8 ,
| r1 <- 44 | r1 <- 40, r1 <- 4 ,
|-------------------------------|
|===============================|
|==| Movement. |==|
|===============================|
|-----------------------------|
| r2 <- r0, r0 | r2, r2 <- r0 ,
| r2 <- r0 | ,
|-----------------------------|
|-------------------------------|
| r1 <- 1 | r1 ,
| r1 <- 2 | r1 <- 1, r1 <- 1 ,
| r1 <- 4 | r1 <- 2, r1 <- 2 ,
| r1 <- 8 | r1 <- 4, r1 <- 4 ,
| r1 <- 9 | r1 <- 8, r1 <- 1 ,
| r1 <- 10 | r1 <- 9, r1 <- 1 ,
| r1 <- 16 | r1 <- 8, r1 <- 8 ,
| r1 <- 32 | r1 <- 16, r1 <- 16 ,
| r1 <- 40 | r1 <- 32, r1 <- 8 ,
| r1 <- 44 | r1 <- 40, r1 <- 4 ,
|-------------------------------|
|--------------------------------|
| r1 = r2, r2 | r1, r2*, r1 = r2 ,
| r1 = r2 | r2 <- r2* ,
|--------------------------------|
|--------------------------------|
| r0 <- r0*, r0* | r0, r0 <- r0* ,
| r0 <- r0* | ,
|--------------------------------|
|--------------------------------|
| r2 <- r2*, r2* | r2, r2 <- r2* ,
| r2 <- r2* | ,
|--------------------------------|
|============================|
|==| Input. |==|
|============================|
|----------------------------------------------|
| go to the next character | @io-read ,
, , r0 <- 0 ,
, , r0 <- @io-read-in ,
|----------------------------------------------|
|--------------------------------------------------------|
| r0 <- @io-read-in, @io-read-in | r0, r0 <- @io-read-in ,
| r0 <- @io-read-in | ,
|--------------------------------------------------------|
|--------------------|
| @io-read-end | EOF ,
|--------------------|
|===============================|
|==| Equality. |==|
|===============================|
|-----------------------------------------|
| r0 == r1?, r0, r1 | r0*, r0 == r1? ,
|-----------------------------------------|
| r0 == r1?, r1 | r0 <- r0* ,
, , r1 <- 0 ,
, , r0 != r1 ,
|-----------------------------------------|
| r0 == r1?, r0 | r0 ,
, , r0 <- r0* ,
, , r0 != r1 ,
|-----------------------------------------|
| r0 == r1? | r0 <- r0* ,
, , r0 == r1 ,
|-----------------------------------------|
|--------------------------------|
| r0 <- r0*, r0* | r0, r0 <- r0* ,
| r0 <- r0* | ,
|--------------------------------|
|--------------------------------|
| r2 <- r2*, r2* | r2, r2 <- r2* ,
| r2 <- r2* | ,
|--------------------------------|
|==========================================|
|==| Whitespace handling. |==|
|==========================================|
|------------------------------|
| space?, r0 != r1 | ~space ,
| space?, r0 == r1 | space ,
|------------------------------|
| space? | r1 <- 32 ,
, , r0 == r1? ,
, , space? ,
|------------------------------|
|----------------------------|
| tab?, r0 != r1 | ~tab ,
| tab?, r0 == r1 | tab ,
|----------------------------|
| tab? | r1 <- 9 ,
, , r0 == r1? ,
, , tab? ,
|----------------------------|
|--------------------------------|
| newline?, r0 != r1 | ~newline ,
| newline?, r0 == r1 | newline ,
|--------------------------------|
| newline? | r1 <- 10 ,
, , r0 == r1? ,
, , newline? ,
|--------------------------------|
|---------------------------------------------------|
| whitespace?, space | whitespace ,
| whitespace?, tab | whitespace ,
| whitespace?, newline | whitespace ,
| whitespace?, ~space, ~tab, ~newline | ~whitespace ,
|---------------------------------------------------|
| whitespace? | space? ,
, , tab? ,
, , newline? ,
, , whitespace? ,
|---------------------------------------------------|
|-----------------------------------|
| whitespace, ~space | whitespace ,
| whitespace, ~tab | whitespace ,
| whitespace, ~newline | whitespace ,
|-----------------------------------|
|------------------------------------------|
| delimiter?, r0 == r1 | delimiter ,
| delimiter?, r0 != r1 | ~delimiter ,
|------------------------------------------|
| delimiter? | r1 = r2 ,
, , r0 == r1? ,
, , delimiter? ,
|------------------------------------------|
|------------------------------|
| comma?, r0 != r1 | ~comma ,
| comma?, r0 == r1 | comma ,
|------------------------------|
| comma? | r1 <- 44 ,
, , r0 == r1? ,
, , comma? ,
|------------------------------|
|------------------------------------------------------------------------------------------------|
| go to the next non-whitespace character, whitespace | go to the next non-whitespace character ,
| go to the next non-whitespace character, ~whitespace | ,
|------------------------------------------------------------------------------------------------|
| go to the next non-whitespace character | go to the next character ,
, , whitespace? ,
, , go to the next non-whitespace character ,
|------------------------------------------------------------------------------------------------|
|===================================|
|==| Main program. |==|
|===================================|
|-------------------------------------------------|
|| start, left ,
|-------------------------------------------------|
| start | go to the next non-whitespace character ,
, , store delimiter ,
, , parse ,
|-------------------------------------------------|
|-----------------------------------------------------------|
| store delimiter | r2 <- r0 ,
, , go to the next non-whitespace character ,
|-----------------------------------------------------------|
|-------------------------------------------------------------|
| parse, EOF | append token to side, stop ,
|-------------------------------------------------------------|
| parse, delimiter | append token to side ,
, , switch sides ,
, , go to the next non-whitespace character ,
, , parse ,
|-------------------------------------------------------------|
| parse, ~delimiter | comma? ,
, , parse ,
|-------------------------------------------------------------|
| parse, comma | append token to side ,
, , go to the next non-whitespace character ,
, , parse ,
|-------------------------------------------------------------|
| parse, ~comma | append character to token ,
, , go to the next non-whitespace character ,
, , parse ,
|-------------------------------------------------------------|
| parse | delimiter?, ,
, parse ,
|-------------------------------------------------------------|
1 | |================================| |
2 | |==| Constants. |==| |
3 | |================================| |
4 | |
5 | |-----------------------| |
6 | | r0 <- 0, r0 | r0 <- 0 , |
7 | | r0 <- 0 | , |
8 | |-----------------------| |
9 | |
10 | |-----------------------| |
11 | | r1 <- 0, r1 | r1 <- 0 , |
12 | | r1 <- 0 | , |
13 | |-----------------------| |
14 | |
15 | |-------------------------------| |
16 | | r1 <- 1 | r1 , |
17 | | r1 <- 2 | r1 <- 1, r1 <- 1 , |
18 | | r1 <- 4 | r1 <- 2, r1 <- 2 , |
19 | | r1 <- 8 | r1 <- 4, r1 <- 4 , |
20 | | r1 <- 9 | r1 <- 8, r1 <- 1 , |
21 | | r1 <- 10 | r1 <- 9, r1 <- 1 , |
22 | | r1 <- 16 | r1 <- 8, r1 <- 8 , |
23 | | r1 <- 32 | r1 <- 16, r1 <- 16 , |
24 | | r1 <- 40 | r1 <- 32, r1 <- 8 , |
25 | | r1 <- 44 | r1 <- 40, r1 <- 4 , |
26 | |-------------------------------| |
27 | |
28 | |
29 | |
30 | |
31 | |===============================| |
32 | |==| Movement. |==| |
33 | |===============================| |
34 | |
35 | |-----------------------------| |
36 | | r2 <- r0, r0 | r2, r2 <- r0 , |
37 | | r2 <- r0 | , |
38 | |-----------------------------| |
39 | |
40 | |-------------------------------| |
41 | | r1 <- 1 | r1 , |
42 | | r1 <- 2 | r1 <- 1, r1 <- 1 , |
43 | | r1 <- 4 | r1 <- 2, r1 <- 2 , |
44 | | r1 <- 8 | r1 <- 4, r1 <- 4 , |
45 | | r1 <- 9 | r1 <- 8, r1 <- 1 , |
46 | | r1 <- 10 | r1 <- 9, r1 <- 1 , |
47 | | r1 <- 16 | r1 <- 8, r1 <- 8 , |
48 | | r1 <- 32 | r1 <- 16, r1 <- 16 , |
49 | | r1 <- 40 | r1 <- 32, r1 <- 8 , |
50 | | r1 <- 44 | r1 <- 40, r1 <- 4 , |
51 | |-------------------------------| |
52 | |
53 | |--------------------------------| |
54 | | r1 = r2, r2 | r1, r2*, r1 = r2 , |
55 | | r1 = r2 | r2 <- r2* , |
56 | |--------------------------------| |
57 | |
58 | |--------------------------------| |
59 | | r0 <- r0*, r0* | r0, r0 <- r0* , |
60 | | r0 <- r0* | , |
61 | |--------------------------------| |
62 | |
63 | |--------------------------------| |
64 | | r2 <- r2*, r2* | r2, r2 <- r2* , |
65 | | r2 <- r2* | , |
66 | |--------------------------------| |
67 | |
68 | |
69 | |
70 | |
71 | |============================| |
72 | |==| Input. |==| |
73 | |============================| |
74 | |
75 | |----------------------------------------------| |
76 | | go to the next character | @io-read , |
77 | , , r0 <- 0 , |
78 | , , r0 <- @io-read-in , |
79 | |----------------------------------------------| |
80 | |
81 | |--------------------------------------------------------| |
82 | | r0 <- @io-read-in, @io-read-in | r0, r0 <- @io-read-in , |
83 | | r0 <- @io-read-in | , |
84 | |--------------------------------------------------------| |
85 | |
86 | |--------------------| |
87 | | @io-read-end | EOF , |
88 | |--------------------| |
89 | |
90 | |
91 | |
92 | |
93 | |===============================| |
94 | |==| Equality. |==| |
95 | |===============================| |
96 | |
97 | |-----------------------------------------| |
98 | | r0 == r1?, r0, r1 | r0*, r0 == r1? , |
99 | |-----------------------------------------| |
100 | | r0 == r1?, r1 | r0 <- r0* , |
101 | , , r1 <- 0 , |
102 | , , r0 != r1 , |
103 | |-----------------------------------------| |
104 | | r0 == r1?, r0 | r0 , |
105 | , , r0 <- r0* , |
106 | , , r0 != r1 , |
107 | |-----------------------------------------| |
108 | | r0 == r1? | r0 <- r0* , |
109 | , , r0 == r1 , |
110 | |-----------------------------------------| |
111 | |
112 | |--------------------------------| |
113 | | r0 <- r0*, r0* | r0, r0 <- r0* , |
114 | | r0 <- r0* | , |
115 | |--------------------------------| |
116 | |
117 | |--------------------------------| |
118 | | r2 <- r2*, r2* | r2, r2 <- r2* , |
119 | | r2 <- r2* | , |
120 | |--------------------------------| |
121 | |
122 | |
123 | |
124 | |
125 | |==========================================| |
126 | |==| Whitespace handling. |==| |
127 | |==========================================| |
128 | |
129 | |------------------------------| |
130 | | space?, r0 != r1 | ~space , |
131 | | space?, r0 == r1 | space , |
132 | |------------------------------| |
133 | | space? | r1 <- 32 , |
134 | , , r0 == r1? , |
135 | , , space? , |
136 | |------------------------------| |
137 | |
138 | |----------------------------| |
139 | | tab?, r0 != r1 | ~tab , |
140 | | tab?, r0 == r1 | tab , |
141 | |----------------------------| |
142 | | tab? | r1 <- 9 , |
143 | , , r0 == r1? , |
144 | , , tab? , |
145 | |----------------------------| |
146 | |
147 | |--------------------------------| |
148 | | newline?, r0 != r1 | ~newline , |
149 | | newline?, r0 == r1 | newline , |
150 | |--------------------------------| |
151 | | newline? | r1 <- 10 , |
152 | , , r0 == r1? , |
153 | , , newline? , |
154 | |--------------------------------| |
155 | |
156 | |---------------------------------------------------| |
157 | | whitespace?, space | whitespace , |
158 | | whitespace?, tab | whitespace , |
159 | | whitespace?, newline | whitespace , |
160 | | whitespace?, ~space, ~tab, ~newline | ~whitespace , |
161 | |---------------------------------------------------| |
162 | | whitespace? | space? , |
163 | , , tab? , |
164 | , , newline? , |
165 | , , whitespace? , |
166 | |---------------------------------------------------| |
167 | |
168 | |-----------------------------------| |
169 | | whitespace, ~space | whitespace , |
170 | | whitespace, ~tab | whitespace , |
171 | | whitespace, ~newline | whitespace , |
172 | |-----------------------------------| |
173 | |
174 | |------------------------------------------| |
175 | | delimiter?, r0 == r1 | delimiter , |
176 | | delimiter?, r0 != r1 | ~delimiter , |
177 | |------------------------------------------| |
178 | | delimiter? | r1 = r2 , |
179 | , , r0 == r1? , |
180 | , , delimiter? , |
181 | |------------------------------------------| |
182 | |
183 | |------------------------------| |
184 | | comma?, r0 != r1 | ~comma , |
185 | | comma?, r0 == r1 | comma , |
186 | |------------------------------| |
187 | | comma? | r1 <- 44 , |
188 | , , r0 == r1? , |
189 | , , comma? , |
190 | |------------------------------| |
191 | |
192 | |------------------------------------------------------------------------------------------------| |
193 | | go to the next non-whitespace character, whitespace | go to the next non-whitespace character , |
194 | | go to the next non-whitespace character, ~whitespace | , |
195 | |------------------------------------------------------------------------------------------------| |
196 | | go to the next non-whitespace character | go to the next character , |
197 | , , whitespace? , |
198 | , , go to the next non-whitespace character , |
199 | |------------------------------------------------------------------------------------------------| |
200 | |
201 | |
202 | |
203 | |
204 | |===================================| |
205 | |==| Main program. |==| |
206 | |===================================| |
207 | |
208 | |-------------------------------------------------| |
209 | || start, left , |
210 | |-------------------------------------------------| |
211 | | start | go to the next non-whitespace character , |
212 | , , store delimiter , |
213 | , , parse , |
214 | |-------------------------------------------------| |
215 | |
216 | |-----------------------------------------------------------| |
217 | | store delimiter | r2 <- r0 , |
218 | , , go to the next non-whitespace character , |
219 | |-----------------------------------------------------------| |
220 | |
221 | |-------------------------------------------------------------| |
222 | | parse, EOF | append token to side, stop , |
223 | |-------------------------------------------------------------| |
224 | | parse, delimiter | append token to side , |
225 | , , switch sides , |
226 | , , go to the next non-whitespace character , |
227 | , , parse , |
228 | |-------------------------------------------------------------| |
229 | | parse, ~delimiter | comma? , |
230 | , , parse , |
231 | |-------------------------------------------------------------| |
232 | | parse, comma | append token to side , |
233 | , , go to the next non-whitespace character , |
234 | , , parse , |
235 | |-------------------------------------------------------------| |
236 | | parse, ~comma | append character to token , |
237 | , , go to the next non-whitespace character , |
238 | , , parse , |
239 | |-------------------------------------------------------------| |
240 | | parse | delimiter?, , |
241 | , parse , |
242 | |-------------------------------------------------------------| |