-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNinaCompiler.cs
818 lines (799 loc) · 36.9 KB
/
NinaCompiler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
using System.Reflection;
namespace Nina;
static class NinaCompiler {
public static NinaExprTree resolve_expr(
List<NinaCodeBlock> _blocks,
ref int _i, HashSet<NinaWithStatementTypes> _withs,
NinaOperatorType? _ender_op1 = null,
NinaOperatorType? _ender_op2 = null) {
if (_blocks.Count == 0)
return new NinaExprTree(false);
string file = _blocks[0].file;
NinaExprTree? tree = null;
NinaExprTree? ptr = null;
NinaExprTree? buf = null;
NinaCodeBlock? buf_op = null;
int opLvMin = 2023;
int initI = ++ _i;
for (; _i <= _blocks.Count; ++ _i) {
NinaCodeBlock? v = _i < _blocks.Count ? _blocks[_i] : null;
bool isEof = _i == _blocks.Count;
bool isReturner = ! isEof
&& ((_ender_op1 != null || _ender_op2 != null)
? (v!.Value.type == NinaCodeBlockType.Operator
&& (v!.Value.val_op == _ender_op1
|| v!.Value.val_op == _ender_op2))
: (v!.Value.val_op == NinaOperatorType.Com
|| v!.Value.val_sy == NinaSymbolType.Sem)
);
bool isBeginner = _i == initI;
bool isEnd = isEof || isReturner;
bool isScoperL = ! isEof && v!.Value.val_sy == NinaSymbolType.CBraL
&& (isBeginner || _blocks[_i - 1].type == NinaCodeBlockType.Operator);
if (! isBeginner && v != null && v.Value.val_op_unary == true
&& _blocks[_i - 1].val_sy == NinaSymbolType.CBraR
&& NinaCodeBlockUtil.operators_vagues.ContainsValue(
(NinaOperatorType) v.Value.val_op !)) {
NinaCodeBlock nblock = v.Value;
nblock.val_op
= NinaCodeBlockUtil.operators_vagues
.First(a => a.Value == v.Value.val_op).Key;
nblock.val_op_unary = false;
nblock.val_op_lv
= NinaCodeBlockUtil.operatorsRank[(NinaOperatorType) nblock.val_op !];
v = nblock;
_blocks[_i] = (NinaCodeBlock) v !;
}
if (isBeginner && (isReturner || isEof))
return new NinaExprTree(false);
if (isEnd || v!.Value.type == NinaCodeBlockType.Operator || isScoperL) {
bool isBracket = ! isEof && ! isScoperL
&& (v!.Value.val_op == NinaOperatorType.BraL
|| v!.Value.val_op == NinaOperatorType.BraR
|| v!.Value.val_op == NinaOperatorType.MBraL
|| v!.Value.val_op == NinaOperatorType.MBraR);
bool isGrouperL = ! isEof && ! isScoperL
&& v!.Value.val_op == NinaOperatorType.BraL
&& (isBeginner || (
_blocks[_i - 1].type == NinaCodeBlockType.Operator
&& _blocks[_i - 1].val_op != NinaOperatorType.BraR
&& _blocks[_i - 1].val_op != NinaOperatorType.MBraR
));
bool isUnary = ! isEnd && ! isScoperL && v!.Value.val_op_unary == true;
int? currOpLv = ! isEnd && ! isScoperL ? (int) v!.Value.val_op_lv ! : null;
int? bufOpLv = buf_op != null && ! isScoperL ? buf_op.Value.val_op_lv : null;
if (buf == null && ! isUnary && ! isGrouperL && ! isScoperL) {
if (! isEof)
NinaError.error(
"无效的表达式.", 651968,
new NinaErrorPosition(
v!.Value.file, v!.Value.line,
v!.Value.col
)
);
if (buf_op != null)
NinaError.error(
"无效的表达式.", 328298,
new NinaErrorPosition(
buf_op.Value.file,
buf_op.Value.line, buf_op.Value.col
)
);
else
NinaError.error("莫名其妙的错误.", 425707);
}
if (isUnary) {
if (buf != null) {
NinaError.error(
"无效的单目运算符.", 355915,
new NinaErrorPosition(
v!.Value.file, v!.Value.line,
v!.Value.col
)
);
}
else {
buf = new NinaExprTree(true);
}
}
if (isGrouperL) {
buf = resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_ender_op1: NinaOperatorType.BraR
);
continue;
}
else if (isScoperL) {
buf = new NinaExprTree(
compile(
_file: file,
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_scope: NinaScopeType.Function,
_cscope: NinaScopeType.Function
)
);
continue;
}
else if (tree == null) {
if (buf_op != null) {
NinaError.error("无效的表达式.", 357258,
new NinaErrorPosition(
buf_op.Value.file,
buf_op.Value.line, buf_op.Value.col
)
);
}
else {
tree = buf;
ptr = tree;
}
}
else {
if (bufOpLv < opLvMin) {
NinaExprTree ntree = new NinaExprTree((NinaCodeBlock) buf_op !);
tree!.abdicate(ntree);
ntree.append(buf !);
ptr = ntree;
tree = ptr;
}
else {
NinaExprTree? p = ptr!.get();
bool isHandled = false;
do {
if (p!.boss == null
|| p.boss.block.val_op_lv < bufOpLv
|| (buf_op!.Value.val_op_unary == true
&& p.boss.block.val_op_unary == true)) {
NinaExprTree ntree
= new NinaExprTree((NinaCodeBlock) buf_op !);
p.abdicate(ntree);
ntree.append(buf !);
ptr = ntree;
if (p == tree)
tree = ptr;
isHandled = true;
break;
}
}
while ((p = p.boss) != null);
if (! isHandled) {
NinaError.error("莫名其妙的错误.", 669365);
}
}
}
if (! isEnd) {
if (buf_op != null && bufOpLv < opLvMin) {
opLvMin = (int) bufOpLv !;
}
buf_op = v;
if (isBracket) {
if (v!.Value.val_op == NinaOperatorType.BraL
|| v!.Value.val_op == NinaOperatorType.MBraL) {
buf = resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_ender_op1:
v!.Value.val_op == NinaOperatorType.BraL
? NinaOperatorType.BraR
: NinaOperatorType.MBraR
);
}
else if (v!.Value.val_op == NinaOperatorType.BraR
|| v!.Value.val_op == NinaOperatorType.MBraR) {
NinaError.error(
"不成对的括号.", 761864,
new NinaErrorPosition(
v!.Value.file,
v!.Value.line, v!.Value.col
)
);
}
}
else {
buf = null;
}
}
else if (isReturner) {
return tree ?? new NinaExprTree(false);
}
}
else {
if (buf != null) {
NinaError.error(
"无效的表达式.", 481044,
new NinaErrorPosition(v!.Value.file, v!.Value.line, v!.Value.col)
);
}
buf = new NinaExprTree((NinaCodeBlock) v !);
}
}
return tree ?? new NinaExprTree(false);
}
public static NinaASTBlockExpression compile(
string _file, List<NinaCodeBlock> _blocks,
ref int _i, HashSet<NinaWithStatementTypes> _withs,
NinaScopeType _scope = NinaScopeType.Root,
NinaScopeType _cscope = NinaScopeType.Root) {
NinaASTBlockExpression block = new NinaASTBlockExpression(
new NinaErrorPosition(
_file, - 2, - 2
)
);
if (_blocks.Count == 0)
return block;
bool allow_elseif = false;
List<(ANinaASTExpression, NinaASTBlockExpression)> buf_elses
= new List<(ANinaASTExpression, NinaASTBlockExpression)>();
for (++ _i; _i < _blocks.Count; ++ _i) {
NinaCodeBlock v = _blocks[_i];
if (v.val_sy == NinaSymbolType.CBraR) {
if (_scope == NinaScopeType.Root) {
NinaError.error(
"不成对的花括号.",
316852,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else {
return block;
}
}
else if (v.type == NinaCodeBlockType.Keyword) {
if (v.val_kw == NinaKeywordType.Var
|| v.val_kw == NinaKeywordType.Const) {
NinaASTVarStatement vars = new NinaASTVarStatement(
_isGlobal:
(_scope & NinaScopeType.Function) != NinaScopeType.Function,
_isConst: v.val_kw == NinaKeywordType.Const,
_pos: new NinaErrorPosition(
v.file, v.line, v.col
)
);
bool isRoot
= (_scope & NinaScopeType.Function) != NinaScopeType.Function;
if (_i + 1 <= _blocks.Count - 1
&& _blocks[_i + 1].val_sy != NinaSymbolType.Sem) {
do {
NinaExprTree expr = resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs
);
if (expr.type == NinaExprTreeType.Void || (
expr.type != NinaExprTreeType.Data
? (expr.block.val_op != NinaOperatorType.Equ
|| expr.l!.block.type != NinaCodeBlockType.Identifier)
: expr.block.type != NinaCodeBlockType.Identifier)) {
NinaError.error(
"无效的变量定义语句.",
845706,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else if (expr.type != NinaExprTreeType.Data) {
ANinaASTExpression? val
= expr.r!.compile(_withs) as ANinaASTExpression;
if (val == null) {
NinaError.error(
"无效的变量初始化表达式.",
123533,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else {
string id = NinaCompilerUtil.format_identifier(
expr.l!.block.code
);
vars.vars.list.Add(
(id, val)
);
}
}
else {
vars.vars.list.Add(
(
NinaCompilerUtil.format_identifier(expr.block.code),
null
)
);
}
}
while (_i < _blocks.Count
&& _blocks[_i].val_sy != NinaSymbolType.Sem);
}
else {
NinaError.error(
"变量定义语句不能为空.",
952990,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
block.stms.Add(vars);
}
else if (v.val_kw == NinaKeywordType.If
|| v.val_kw == NinaKeywordType.Else
|| v.val_kw == NinaKeywordType.Elseif
|| v.val_kw == NinaKeywordType.While) {
if (_i + 1 > _blocks.Count - 1) {
NinaError.error(
"无效的逻辑控制语句.",
611922,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
if (v.val_kw != NinaKeywordType.Else
&& _blocks[++ _i].val_op != NinaOperatorType.BraL) {
NinaError.error(
"无效的逻辑控制语句.",
390479,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
NinaExprTree? tree
= v.val_kw != NinaKeywordType.Else
? resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_ender_op1: NinaOperatorType.BraR
)
: null;
ANinaASTExpression? expr
= v.val_kw != NinaKeywordType.Else
? tree!.compile(_withs) as ANinaASTExpression
: null;
NinaCodeBlock? cBraL
= _i + 1 > _blocks.Count - 1
? null
: _blocks[++ _i];
if (cBraL == null
|| cBraL.Value.val_sy != NinaSymbolType.CBraL) {
NinaError.error(
"无效的逻辑控制语句.",
885155,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else if (v.val_kw != NinaKeywordType.Else && expr == null) {
NinaError.error(
"无效的逻辑控制语句.",
723745,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else {
NinaErrorPosition tmpPos
= new NinaErrorPosition(
v.file, v.line, v.col
);
NinaScopeType nscope;
if (v.val_kw == NinaKeywordType.If)
nscope = NinaScopeType.If;
else if (v.val_kw == NinaKeywordType.Else)
nscope = NinaScopeType.Else;
else if (v.val_kw == NinaKeywordType.Elseif)
nscope = NinaScopeType.Elseif;
else
nscope = NinaScopeType.While;
NinaASTBlockExpression body = compile(
_file: v.file,
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_scope: _scope | nscope,
_cscope: nscope
);
if (v.val_kw == NinaKeywordType.If) {
block.stms.Add(
new NinaASTIfStatement(
_expr: expr !,
_block: body,
tmpPos
)
);
allow_elseif = true;
}
else if (v.val_kw == NinaKeywordType.While) {
block.stms.Add(
new NinaASTWhileStatement(
_expr: expr !,
_block: body,
tmpPos
)
);
}
else {
if (block.stms.Count == 0) {
NinaError.error(
"无效的逻辑控制语句.",
898170,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
NinaASTIfStatement? main
= block.stms.Last() as NinaASTIfStatement;
if (main == null) {
NinaError.error(
"无效的逻辑控制语句.",
606056,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else if (v.val_kw == NinaKeywordType.Else) {
if (main.block_else != null) {
NinaError.error(
"没有主句的 else 从句.",
432612,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
buf_elses.Add(
(
new NinaASTIdentifierExpression(
NinaConstsProviderUtil.NINA_ID_PREFIX
+ "true",
tmpPos
),
body
)
);
main.block_else
= NinaCompilerUtil.resolve_elses(
buf_elses,
v
);
buf_elses.Clear();
allow_elseif = false;
}
else {
if (! allow_elseif) {
NinaError.error(
"没有主句的 elseif 从句.",
299924,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
buf_elses.Add(
(expr !, body)
);
}
}
}
}
else if (v.val_kw == NinaKeywordType.Return) {
ANinaASTExpression expr_raw = resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs
).compile(_withs);
ANinaASTCommonExpression expr
= expr_raw as ANinaASTCommonExpression
?? new NinaASTLiteralExpression(
expr_raw.pos
);
if (_i < _blocks.Count && _blocks[_i].val_sy != NinaSymbolType.Sem) {
NinaError.error(
"无效的 return 语句.", 916850,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else {
NinaASTWordStatement words = new NinaASTWordStatement(
_type: NinaKeywordType.Return,
_expr: expr,
_pos: expr.pos
);
if ((_scope & NinaScopeType.Function) != NinaScopeType.Function
|| (_scope & NinaScopeType.Try) == NinaScopeType.Try
|| (_scope & NinaScopeType.Catch) == NinaScopeType.Catch) {
words.annos.Add(NinaConstsProviderUtil.NINA_ANNO_SPECIALRETURN);
}
block.stms.Add(words);
}
}
else if (v.val_kw == NinaKeywordType.Break
|| v.val_kw == NinaKeywordType.Continue) {
if ((_i + 1 <= _blocks.Count - 1
&& _blocks[++ _i].val_sy != NinaSymbolType.Sem)
|| (_scope & NinaScopeType.While) != NinaScopeType.While) {
NinaError.error(
"无效的循环控制语句.", 327023,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else {
block.stms.Add(
new NinaASTWordStatement(
(NinaKeywordType) v.val_kw !,
new NinaErrorPosition(
v.file, v.line, v.col
)
)
);
}
}
else if (v.val_kw == NinaKeywordType.Func) {
if (_i + 3 > _blocks.Count() - 1) {
NinaError.error(
"无效的函数定义语法糖语句.",
894659,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
NinaCodeBlock name = _blocks[++ _i];
NinaCodeBlock braL = _blocks[++ _i];
if (name.type != NinaCodeBlockType.Identifier
|| braL.val_op != NinaOperatorType.BraL) {
NinaError.error(
"无效的函数定义语法糖语句.",
526905,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
NinaASTSuperListExpression plist = new NinaASTSuperListExpression(
new NinaErrorPosition(
braL.file, braL.line, braL.col
)
);
if (_i + 1 <= _blocks.Count - 1
&& _blocks[_i + 1].val_op != NinaOperatorType.BraR) {
bool comfortable = false;
do {
NinaExprTree expr = resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_ender_op1: NinaOperatorType.Com,
_ender_op2: NinaOperatorType.BraR
);
if (expr.type == NinaExprTreeType.Void || (
expr.type != NinaExprTreeType.Data
? (expr.block.val_op != NinaOperatorType.Equ
|| expr.l!.block.type != NinaCodeBlockType.Identifier)
: expr.block.type != NinaCodeBlockType.Identifier)) {
NinaError.error(
"无效的形参列表表达式.",
635117,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else if (expr.type != NinaExprTreeType.Data) {
ANinaASTExpression? val
= expr.r!.compile(_withs) as ANinaASTExpression;
if (val == null) {
NinaError.error(
"无效的形参初始化表达式.",
116820,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else {
plist.list.Add(
(
NinaCompilerUtil.format_identifier(
expr.l!.block.code
),
val
)
);
comfortable = true;
}
}
else {
if (comfortable) {
NinaError.error(
"无效的形参初始化表达式.",
535545,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
plist.list.Add(
(
NinaCompilerUtil.format_identifier(
expr.block.code
),
null
)
);
}
}
while (_i < _blocks.Count
&& _blocks[_i].val_op != NinaOperatorType.BraR);
}
else {
++ _i;
}
if (_i + 1 <= _blocks.Count - 1) {
NinaCodeBlock cBraL = _blocks[++ _i];
if (cBraL.val_sy != NinaSymbolType.CBraL) {
NinaError.error(
"无效的函数定义语法糖语句.",
985609,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
}
else {
NinaError.error(
"无效的函数定义语法糖语句.",
252671,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
NinaASTBlockExpression body = compile(
_file: v.file,
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_scope: NinaScopeType.Function,
_cscope: NinaScopeType.Function
);
string id = NinaCompilerUtil.format_identifier(name.code);
NinaErrorPosition tmpPos
= new NinaErrorPosition(
v.file, v.line, v.col
);
block.stms.Add(
new NinaASTVarStatement(
_isGlobal:
(_scope & NinaScopeType.Function)
!= NinaScopeType.Function,
_vars: new NinaASTSuperListExpression(
new List<(string, ANinaASTExpression?)> {
(
id,
new NinaASTBinaryExpression(
_type: NinaOperatorType.Arr,
_expr_l: plist,
_expr_r: body,
plist.pos
)
)
},
tmpPos
),
_pos: tmpPos
)
);
}
else if (v.val_kw == NinaKeywordType.Try
|| v.val_kw == NinaKeywordType.Catch) {
if (_i + 1 > _blocks.Count - 1
|| _blocks[++ _i].val_sy != NinaSymbolType.CBraL) {
NinaError.error(
"无效的异常捕获语句.",
352903,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
NinaASTBlockExpression body
= compile(
_file: v.file,
_blocks: _blocks,
_i: ref _i,
_withs: _withs,
_scope: _scope | NinaScopeType.Try,
_cscope: NinaScopeType.Try
);
if (v.val_kw == NinaKeywordType.Try) {
block.stms.Add(
new NinaASTTryStatement(
body, body.pos
)
);
}
else {
if (block.stms.Count == 0
|| block.stms.Last() is not NinaASTTryStatement main
|| main.block_catch != null) {
NinaError.error(
"无效的异常捕获语句.",
239021,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
else {
main.block_catch = body;
}
}
}
else if (v.val_kw == NinaKeywordType.With) {
if (_i > 0) {
NinaError.error(
"模块控制语句只能放在文件头.",
693031,
new NinaErrorPosition(
v.file, v.line, v.col
)
);
}
if (_i + 1 <= _blocks.Count - 1
&& _blocks[_i + 1].val_sy != NinaSymbolType.Sem) {
do {
NinaExprTree expr = resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs
);
if (expr.type != NinaExprTreeType.Data
|| expr.block.type != NinaCodeBlockType.String) {
NinaError.error(
"语法模块列表无效.",
803232,
new NinaErrorPosition(
expr.block.file, expr.block.line, expr.block.col
)
);
}
else if (! NinaCodeBlockUtil.withStatementTypes.ContainsKey(
expr.block.val_str !)) {
NinaError.error(
"不存在的无法模块名称.",
890213,
new NinaErrorPosition(
expr.block.file, expr.block.line, expr.block.col
)
);
}
else {
_withs.Add(
NinaCodeBlockUtil.withStatementTypes
[expr.block.val_str !]
);
}
}
while (_i < _blocks.Count
&& _blocks[_i].val_sy != NinaSymbolType.Sem);
}
else {
NinaError.error(
"语法模块控制语句不能为空.",
459021,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
}
else {
NinaError.error(
"莫名其妙的错误.",
284747,
new NinaErrorPosition(v.file, v.line, v.col)
);
}
}
else {
-- _i;
ANinaASTExpression? expr = resolve_expr(
_blocks: _blocks,
_i: ref _i,
_withs: _withs
).compile(_withs) as ANinaASTExpression;
if (expr == null) {}
else {
block.stms.Add(
new NinaASTExpressionStatement(
expr,
expr.pos
)
);
}
}
}
return block;
}
public static NinaASTBlockExpression compile(
string _file, List<NinaCodeBlock> _blocks) {
int i = - 1;
return compile(
_file: _file,
_blocks: _blocks,
_i: ref i,
_withs: new HashSet<NinaWithStatementTypes>()
);
}
}