tr_lang/runtime/runtime.rs
1use crate::errwarn::Error;
2use crate::errwarn::ErrorGenerator;
3use crate::mem::{HashMemory, Map, Object, StackMemory};
4use crate::store::globarg::SUPRESS_WARN;
5use crate::token::{tokentypes::ParserTokenType as TokenType, ParserToken as Token};
6use crate::util::{get_lang, SupportedLanguage};
7use std::io::{self, prelude::*};
8
9pub struct Run {
10 program: Vec<Token>,
11 pub(crate) current: usize,
12}
13
14impl Run {
15 pub fn new(program: Vec<Token>) -> Self {
16 Self {
17 program,
18 current: 0,
19 }
20 }
21
22 pub fn run(
23 &mut self,
24 file: String,
25 mem: Option<(StackMemory, HashMemory)>,
26 repl: bool,
27 ) -> Result<(StackMemory, HashMemory), (StackMemory, HashMemory, Error)> {
28 let (mut stack, mut hashs) = if let Some((s, h)) = mem {
29 (s, h)
30 } else {
31 (StackMemory::new(), HashMemory::new())
32 };
33 // let mut warnings: Vec<Box<dyn FnOnce()>> = vec![]; // for later use
34 let mut current_namespace: Vec<String> = vec![];
35
36 while self.program.len() > self.current {
37 let tokenc = self.program.get(self.current).unwrap().clone();
38 let token = self.program.get_mut(self.current).unwrap();
39
40 match token.typ.clone() {
41 TokenType::InScopeParentL => {
42 stack.new_stack();
43
44 let tok = self.program.get(self.current + 1).unwrap();
45 match tok.typ {
46 TokenType::Identifier { ref id } => {
47 match hashs.get(id) {
48 Some(o) => stack.push(o.clone()),
49 None => return Err((stack, hashs.clone(), match get_lang() {
50 SupportedLanguage::Turkish => ErrorGenerator::error(
51 "BilinmeyenTanımlayıcı",
52 &format!(
53 "bilinmeyen değişken: `{}`, bu değişken bulunamamıştır",
54 tok.repr()
55 ),
56 tok.line,
57 tok.col,
58 tok.file.clone(),
59 {
60 let mut hashk = hashs.clone().into_keys();
61 hashk.sort();
62 let n = hashk.binary_search(id).unwrap_err();
63 if hashk.is_empty() {
64 None
65 } else {
66 Some(format!("`{}` demek mi istediniz?", hashk[n]))
67 }
68 }
69 ),
70 SupportedLanguage::English => ErrorGenerator::error(
71 "UnknownIdentifier",
72 &format!("unknown identifier: `{}`, this identifier could not be found", tok.repr()),
73 tok.line,
74 tok.col,
75 tok.file.clone(),
76 {
77 let mut hashk = hashs.clone().into_keys();
78 hashk.sort();
79 let n = hashk.binary_search(id).unwrap_err();
80 if hashk.is_empty() {
81 None
82 } else {
83 Some(format!("maybe you meant {}?", hashk[n]))
84 }
85 },
86 ),
87 })),
88 }
89 }
90 _ => return Err((stack, hashs, match get_lang() {
91 SupportedLanguage::Turkish => ErrorGenerator::error(
92 "BeklenmedikSimge",
93 &format!(
94 "tanımlayıcı beklenmişti ancak `{}` bulundu",
95 tok.repr()
96 ),
97 tokenc.line,
98 tokenc.col,
99 tokenc.file,
100 None,
101 ),
102 SupportedLanguage::English => ErrorGenerator::error(
103 "UnexpectedToken",
104 &format!(
105 "expected identifier, but found `{}`",
106 tok.repr()
107 ),
108 tokenc.line,
109 tokenc.col,
110 tokenc.file,
111 None,
112 ),
113 },
114 )),
115 }
116
117 self.current += 2;
118
119 let mut latest_id = None;
120 while self.program.len() > self.current {
121 let c = self.program.get(self.current).unwrap().clone();
122
123 match c.typ {
124 TokenType::İkiNokta => {
125 let a = match stack.pop() {
126 Some(a) => a,
127 None => return Err((stack, hashs, match get_lang() {
128 SupportedLanguage::Turkish => {
129 ErrorGenerator::error(
130 "KümedeYeterliDeğişkenYok",
131 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
132 tokenc.line,
133 tokenc.col,
134 tokenc.file,
135 None,
136 )
137 }
138 SupportedLanguage::English => {
139 ErrorGenerator::error(
140 "NotEnoughVarsInStack",
141 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
142 tokenc.line,
143 tokenc.col,
144 tokenc.file,
145 None,
146 )
147 }
148 })),
149 };
150 match a {
151 Object::Harita(map) => {
152 let tok = self.program.get(self.current + 1).unwrap();
153 match tok.typ {
154 TokenType::Identifier { ref id } => {
155 let o = match map.map.get(id) {
156 Some(o) => o.clone(),
157 None => return Err((stack, hashs.clone(), match get_lang() {
158 SupportedLanguage::Turkish => ErrorGenerator::error(
159 "BilinmeyenTanımlayıcı",
160 &format!(
161 "bilinmeyen değişken: `{}`, bu değişken bulunamamıştır",
162 tok.repr()
163 ),
164 tok.line,
165 tok.col,
166 tok.file.clone(),
167 {
168 let mut hashk: Vec<_> = map.map.clone().into_keys().collect();
169 hashk.sort();
170 let n = hashk.binary_search(id).unwrap_err();
171 if hashk.is_empty() {
172 None
173 } else {
174 Some(format!("`{}` demek mi istediniz?", hashk[n]))
175 }
176 }
177 ),
178 SupportedLanguage::English => ErrorGenerator::error(
179 "UnknownIdentifier",
180 &format!(
181 "unknown identifier: `{}`, this identifier could not be found",
182 tok.repr()
183 ),
184 tok.line,
185 tok.col,
186 tok.file.clone(),
187 {
188 let mut hashk: Vec<_> = map.map.clone().into_keys().collect();
189 hashk.sort();
190 let n = hashk.binary_search(id).unwrap_err();
191 if hashk.is_empty() {
192 None
193 } else {
194 Some(format!("maybe you meant {}?", hashk[n]))
195 }
196 },
197 ),
198 })),
199 };
200 latest_id = Some(id);
201 stack.push(o);
202 self.current += 2;
203 },
204 TokenType::Çarpı => {
205 for (k, v) in map.map.iter() {
206 hashs.insert(k.clone(), v.clone());
207 }
208 let next = match self.program.get(self.current + 2) {
209 Some(t) => t,
210 None => return Err((
211 stack,
212 hashs,
213 match get_lang() {
214 SupportedLanguage::Turkish => ErrorGenerator::error(
215 "BeklenmedikSimge",
216 &format!(
217 "`)` beklenmişti ancak birşey bulunamadı",
218 ),
219 tokenc.line,
220 tokenc.col,
221 tokenc.file,
222 None,
223 ),
224 SupportedLanguage::English => ErrorGenerator::error(
225 "UnexpectedToken",
226 &format!(
227 "expected `)`, but found nothing",
228 ),
229 tokenc.line,
230 tokenc.col,
231 tokenc.file,
232 None,
233 ),
234 },
235 )),
236 };
237 match next.typ {
238 TokenType::InScopeParentR => {
239 self.current += 3;
240 break;
241 },
242 _ => return Err((
243 stack,
244 hashs,
245 match get_lang() {
246 SupportedLanguage::Turkish => ErrorGenerator::error(
247 "BeklenmedikSimge",
248 &format!(
249 "`)` beklenmişti ancak `{}` bulundu",
250 next.repr()
251 ),
252 tokenc.line,
253 tokenc.col,
254 tokenc.file,
255 None,
256 ),
257 SupportedLanguage::English => ErrorGenerator::error(
258 "UnexpectedToken",
259 &format!(
260 "expected `)`, but found `{}`",
261 next.repr()
262 ),
263 tokenc.line,
264 tokenc.col,
265 tokenc.file,
266 None,
267 ),
268 },
269 )),
270 }
271 },
272 _ => return Err((
273 stack,
274 hashs,
275 match get_lang() {
276 SupportedLanguage::Turkish => ErrorGenerator::error(
277 "BeklenmedikSimge",
278 &format!(
279 "`)` beklenmişti ancak `{}` bulundu",
280 tok.repr()
281 ),
282 tokenc.line,
283 tokenc.col,
284 tokenc.file,
285 None,
286 ),
287 SupportedLanguage::English => ErrorGenerator::error(
288 "UnexpectedToken",
289 &format!(
290 "expected `)`, but found `{}`",
291 tok.repr()
292 ),
293 tokenc.line,
294 tokenc.col,
295 tokenc.file,
296 None,
297 ),
298 },
299 )),
300 }
301 }
302 b => return Err((
303 stack,
304 hashs,
305 match get_lang() {
306 SupportedLanguage::Turkish => ErrorGenerator::error(
307 "BeklenmedikTip",
308 &format!("harita beklenmişti ancak `{:?}` bulundu", b),
309 tokenc.line,
310 tokenc.col,
311 tokenc.file,
312 None,
313 ),
314 SupportedLanguage::English => ErrorGenerator::error(
315 "UnexpectedType",
316 &format!("expected map but found `{:?}`", b),
317 tokenc.line,
318 tokenc.col,
319 tokenc.file,
320 None,
321 ),
322 },
323 )),
324 }
325 }
326 TokenType::InScopeParentR => {
327 self.current += 1;
328 if let Some(id) = latest_id {
329 hashs.insert(id.clone(), stack.pop().unwrap());
330 } else { unreachable!() }
331 break;
332 }
333 _ => todo!(),
334 }
335 }
336 stack.del_stack();
337 }
338 TokenType::InScopeParentR => {},
339 TokenType::İkiNokta => {
340 let a = match stack.pop() {
341 Some(a) => a,
342 None => return Err((stack, hashs, match get_lang() {
343 SupportedLanguage::Turkish => {
344 ErrorGenerator::error(
345 "KümedeYeterliDeğişkenYok",
346 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
347 tokenc.line,
348 tokenc.col,
349 tokenc.file,
350 None,
351 )
352 }
353 SupportedLanguage::English => {
354 ErrorGenerator::error(
355 "NotEnoughVarsInStack",
356 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
357 tokenc.line,
358 tokenc.col,
359 tokenc.file,
360 None,
361 )
362 }
363 })),
364 };
365 match a {
366 Object::Harita(map) => {
367 let id = self.program.get(self.current + 1).unwrap();
368 match id.typ.clone() {
369 TokenType::Identifier { id: ident } => {
370 let o = match map.map.get(&ident) {
371 Some(o) => o,
372 None => return Err((stack, hashs.clone(), match get_lang() {
373 SupportedLanguage::Turkish => ErrorGenerator::error(
374 "BilinmeyenTanımlayıcı",
375 &format!(
376 "bilinmeyen değişken: `{}`, bu değişken bulunamamıştır",
377 tokenc.repr()
378 ),
379 tokenc.line,
380 tokenc.col,
381 tokenc.file,
382 {
383 let mut hashk = hashs.clone().into_keys();
384 hashk.sort();
385 let n = hashk.binary_search(&ident).unwrap_err();
386 if hashk.is_empty() {
387 None
388 } else {
389 Some(format!("`{}` demek mi istediniz?", hashk[n]))
390 }
391 }
392 ),
393 SupportedLanguage::English => ErrorGenerator::error(
394 "UnknownIdentifier",
395 &format!("unknown identifier: `{}`, this identifier could not be found", tokenc.repr()),
396 tokenc.line,
397 tokenc.col,
398 tokenc.file,
399 {
400 let mut hashk = hashs.clone().into_keys();
401 hashk.sort();
402 let n = hashk.binary_search(&ident).unwrap_err();
403 if hashk.is_empty() {
404 None
405 } else {
406 Some(format!("maybe you meant {}?", hashk[n]))
407 }
408 },
409 ),
410 })),
411 };
412 match o {
413 Object::Hiç
414 | Object::Bool(_)
415 | Object::Sayı(_)
416 | Object::Yazı(_)
417 | Object::Liste(_)
418 | Object::Harita(_) => {
419 stack.push(o.clone());
420 self.current += 2;
421 }
422 Object::İşlev(tp) => {
423 let işlev = self.program.get(*tp).unwrap();
424 match işlev.typ {
425 TokenType::İşlev { sonloc: tpi } => {
426 let loc = match tpi {
427 Some(i) => i,
428 None => unreachable!(),
429 };
430 let işlevson =
431 self.program.get_mut(loc).unwrap();
432 match &mut işlevson.typ {
433 TokenType::İşlevSonlandır {
434 tp: ref mut tps,
435 } => {
436 tps.push(self.current + 1);
437 }
438 _ => unreachable!(),
439 }
440 self.current = *tp + 2;
441 }
442 _ => unreachable!(),
443 }
444 stack.new_stack();
445 hashs.new_hash();
446 }
447 }
448 }
449 _ => {
450 return Err((
451 stack,
452 hashs,
453 match get_lang() {
454 SupportedLanguage::Turkish => ErrorGenerator::error(
455 "BeklenmedikSimge",
456 &format!(
457 "tanımlayıcı beklenmişti ancak `{}` bulundu",
458 id.repr()
459 ),
460 tokenc.line,
461 tokenc.col,
462 tokenc.file,
463 None,
464 ),
465 SupportedLanguage::English => ErrorGenerator::error(
466 "UnexpectedToken",
467 &format!(
468 "expected identifier, but found `{}`",
469 id.repr()
470 ),
471 tokenc.line,
472 tokenc.col,
473 tokenc.file,
474 None,
475 ),
476 },
477 ))
478 }
479 }
480 }
481 b => {
482 return Err((
483 stack,
484 hashs,
485 match get_lang() {
486 SupportedLanguage::Turkish => ErrorGenerator::error(
487 "BeklenmedikTip",
488 &format!("harita beklenmişti ancak `{:?}` bulundu", b),
489 tokenc.line,
490 tokenc.col,
491 tokenc.file,
492 None,
493 ),
494 SupportedLanguage::English => ErrorGenerator::error(
495 "UnexpectedType",
496 &format!("expected map but found `{:?}`", b),
497 tokenc.line,
498 tokenc.col,
499 tokenc.file,
500 None,
501 ),
502 },
503 ))
504 }
505 }
506 }
507 TokenType::BlokSonlandır => {
508 let mut map = Map::new();
509 if let Some(last_ele) = stack.pop() {
510 stack.push_ret(last_ele);
511 }
512 stack.del_stack();
513 let fhash = hashs.del_hash().unwrap();
514 for (k, v) in fhash.into_iter() {
515 map.map.insert(k, v);
516 }
517 hashs.insert(current_namespace.pop().unwrap(), Object::Harita(map));
518 self.current += 1;
519 }
520 TokenType::Blok => {
521 stack.new_stack();
522 hashs.new_hash();
523 let id = self.program.get(self.current + 1).unwrap();
524 match id.typ.clone() {
525 TokenType::Identifier { id: ident } => {
526 current_namespace.push(ident);
527 }
528 _ => {
529 return Err((
530 stack,
531 hashs,
532 match get_lang() {
533 SupportedLanguage::Turkish => ErrorGenerator::error(
534 "BeklenmedikSimge",
535 &format!(
536 "tanımlayıcı beklenmişti ancak `{}` bulundu",
537 id.repr()
538 ),
539 tokenc.line,
540 tokenc.col,
541 tokenc.file,
542 None,
543 ),
544 SupportedLanguage::English => ErrorGenerator::error(
545 "UnexpectedToken",
546 &format!("expected identifier, but found `{}`", id.repr()),
547 tokenc.line,
548 tokenc.col,
549 tokenc.file,
550 None,
551 ),
552 },
553 ))
554 }
555 }
556 self.current += 2;
557 }
558 TokenType::Hiç => {
559 stack.push(Object::Hiç);
560 self.current += 1;
561 }
562 TokenType::ParenL => unreachable!(),
563 TokenType::Ver { tp } => {
564 let a = match stack.pop() {
565 Some(a) => a,
566 None => return Err((stack, hashs, match get_lang() {
567 SupportedLanguage::Turkish => {
568 ErrorGenerator::error(
569 "KümedeYeterliDeğişkenYok",
570 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
571 tokenc.line,
572 tokenc.col,
573 tokenc.file,
574 None,
575 )
576 }
577 SupportedLanguage::English => {
578 ErrorGenerator::error(
579 "NotEnoughVarsInStack",
580 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
581 tokenc.line,
582 tokenc.col,
583 tokenc.file,
584 None,
585 )
586 }
587 })),
588 };
589 stack.push_ret(a);
590 if let Some(i) = tp {
591 match self.program.get_mut(i).unwrap().typ {
592 TokenType::İşlevSonlandır { ref mut tp } => {
593 if let Some(u) = tp.pop() {
594 self.current = u;
595 }
596 }
597 _ => unreachable!(),
598 };
599 self.current += 1;
600 stack.del_stack();
601 hashs.del_hash();
602 } // error
603 }
604 TokenType::İşlev { sonloc } => {
605 let id = self.program.get(self.current + 1).unwrap();
606 match id.typ.clone() {
607 TokenType::Identifier { id: ident } => {
608 hashs.insert(ident, Object::İşlev(self.current));
609 }
610 _ => {
611 return Err((
612 stack,
613 hashs,
614 match get_lang() {
615 SupportedLanguage::Turkish => ErrorGenerator::error(
616 "BeklenmedikSimge",
617 &format!(
618 "tanımlayıcı beklenmişti ancak `{}` bulundu",
619 id.repr()
620 ),
621 tokenc.line,
622 tokenc.col,
623 tokenc.file,
624 None,
625 ),
626 SupportedLanguage::English => ErrorGenerator::error(
627 "UnexpectedToken",
628 &format!("expected identifier, but found `{}`", id.repr()),
629 tokenc.line,
630 tokenc.col,
631 tokenc.file,
632 None,
633 ),
634 },
635 ))
636 }
637 }
638 let loc = match sonloc {
639 Some(a) => a,
640 None => unreachable!(),
641 };
642 match self.program.get_mut(loc).unwrap().typ {
643 TokenType::İşlevSonlandır { ref mut tp } => {
644 tp.push(loc);
645 }
646 _ => unreachable!(),
647 }
648 self.current = loc + 1;
649 }
650 TokenType::İşlevSonlandır { .. } => {
651 let loc = match token.typ {
652 TokenType::İşlevSonlandır { ref mut tp } => tp.pop().unwrap(), // Safe to unwrap
653 _ => unreachable!(),
654 };
655 self.current = loc;
656 self.current += 1;
657 stack.del_stack();
658 hashs.del_hash();
659 }
660 TokenType::De => {
661 print!(
662 "{:?}",
663 match stack.pop() {
664 Some(a) => a,
665 None =>
666 return Err((
667 stack,
668 hashs,
669 match get_lang() {
670 SupportedLanguage::Turkish => {
671 ErrorGenerator::error(
672 "KümedeYeterliDeğişkenYok",
673 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
674 tokenc.line,
675 tokenc.col,
676 tokenc.file,
677 None,
678 )
679 }
680 SupportedLanguage::English => {
681 ErrorGenerator::error(
682 "NotEnoughVarsInStack",
683 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
684 tokenc.line,
685 tokenc.col,
686 tokenc.file,
687 None,
688 )
689 }
690 }
691 )),
692 }
693 );
694 io::stdout().flush().unwrap();
695 self.current += 1;
696 }
697 TokenType::Artı => {
698 let b = match stack.pop() {
699 Some(a) => a,
700 None => return Err((stack, hashs, match get_lang() {
701 SupportedLanguage::Turkish => {
702 ErrorGenerator::error(
703 "KümedeYeterliDeğişkenYok",
704 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
705 tokenc.line,
706 tokenc.col,
707 tokenc.file,
708 None,
709 )
710 }
711 SupportedLanguage::English => {
712 ErrorGenerator::error(
713 "NotEnoughVarsInStack",
714 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
715 tokenc.line,
716 tokenc.col,
717 tokenc.file,
718 None,
719 )
720 }
721 })),
722 };
723 let a = match stack.pop() {
724 Some(a) => a,
725 None => return Err((stack, hashs, match get_lang() {
726 SupportedLanguage::Turkish => {
727 ErrorGenerator::error(
728 "KümedeYeterliDeğişkenYok",
729 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
730 tokenc.line,
731 tokenc.col,
732 tokenc.file,
733 None,
734 )
735 }
736 SupportedLanguage::English => {
737 ErrorGenerator::error(
738 "NotEnoughVarsInStack",
739 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
740 tokenc.line,
741 tokenc.col,
742 tokenc.file,
743 None,
744 )
745 }
746 })),
747 };
748 stack.push(match a.ekle(b) {
749 Ok(a) => a,
750 Err(e) => return Err((stack, hashs, e)),
751 });
752 self.current += 1;
753 }
754 TokenType::ArtıArtı => {
755 let a = match stack.pop() {
756 Some(a) => a,
757 None => return Err((stack, hashs, match get_lang() {
758 SupportedLanguage::Turkish => {
759 ErrorGenerator::error(
760 "KümedeYeterliDeğişkenYok",
761 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
762 tokenc.line,
763 tokenc.col,
764 tokenc.file,
765 None,
766 )
767 }
768 SupportedLanguage::English => {
769 ErrorGenerator::error(
770 "NotEnoughVarsInStack",
771 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
772 tokenc.line,
773 tokenc.col,
774 tokenc.file,
775 None,
776 )
777 }
778 })),
779 };
780 stack.push(match a.ekle(Object::Sayı(1.0)) {
781 Ok(a) => a,
782 Err(e) => return Err((stack, hashs, e)),
783 });
784 self.current += 1;
785 }
786 TokenType::Eksi => {
787 let a = match stack.pop() {
788 Some(a) => a,
789 None => return Err((stack, hashs, match get_lang() {
790 SupportedLanguage::Turkish => {
791 ErrorGenerator::error(
792 "KümedeYeterliDeğişkenYok",
793 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
794 tokenc.line,
795 tokenc.col,
796 tokenc.file,
797 None,
798 )
799 }
800 SupportedLanguage::English => {
801 ErrorGenerator::error(
802 "NotEnoughVarsInStack",
803 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
804 tokenc.line,
805 tokenc.col,
806 tokenc.file,
807 None,
808 )
809 }
810 })),
811 };
812 let b = match stack.pop() {
813 Some(a) => a,
814 None => return Err((stack, hashs, match get_lang() {
815 SupportedLanguage::Turkish => {
816 ErrorGenerator::error(
817 "KümedeYeterliDeğişkenYok",
818 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
819 tokenc.line,
820 tokenc.col,
821 tokenc.file,
822 None,
823 )
824 }
825 SupportedLanguage::English => {
826 ErrorGenerator::error(
827 "NotEnoughVarsInStack",
828 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
829 tokenc.line,
830 tokenc.col,
831 tokenc.file,
832 None,
833 )
834 }
835 })),
836 };
837 stack.push(match b.çıkar(a) {
838 Ok(a) => a,
839 Err(e) => return Err((stack, hashs, e)),
840 });
841 self.current += 1;
842 }
843 TokenType::EksiEksi => {
844 let a = match stack.pop() {
845 Some(a) => a,
846 None => return Err((stack, hashs, match get_lang() {
847 SupportedLanguage::Turkish => {
848 ErrorGenerator::error(
849 "KümedeYeterliDeğişkenYok",
850 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
851 tokenc.line,
852 tokenc.col,
853 tokenc.file,
854 None,
855 )
856 }
857 SupportedLanguage::English => {
858 ErrorGenerator::error(
859 "NotEnoughVarsInStack",
860 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
861 tokenc.line,
862 tokenc.col,
863 tokenc.file,
864 None,
865 )
866 }
867 })),
868 };
869 stack.push(match a.çıkar(Object::Sayı(1.0)) {
870 Ok(a) => a,
871 Err(e) => return Err((stack, hashs, e)),
872 });
873 self.current += 1;
874 }
875 TokenType::Çarpı => {
876 let b = match stack.pop() {
877 Some(a) => a,
878 None => return Err((stack, hashs, match get_lang() {
879 SupportedLanguage::Turkish => {
880 ErrorGenerator::error(
881 "KümedeYeterliDeğişkenYok",
882 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
883 tokenc.line,
884 tokenc.col,
885 tokenc.file,
886 None,
887 )
888 }
889 SupportedLanguage::English => {
890 ErrorGenerator::error(
891 "NotEnoughVarsInStack",
892 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
893 tokenc.line,
894 tokenc.col,
895 tokenc.file,
896 None,
897 )
898 }
899 })),
900 };
901 let a = match stack.pop() {
902 Some(a) => a,
903 None => return Err((stack, hashs, match get_lang() {
904 SupportedLanguage::Turkish => {
905 ErrorGenerator::error(
906 "KümedeYeterliDeğişkenYok",
907 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
908 tokenc.line,
909 tokenc.col,
910 tokenc.file,
911 None,
912 )
913 }
914 SupportedLanguage::English => {
915 ErrorGenerator::error(
916 "NotEnoughVarsInStack",
917 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
918 tokenc.line,
919 tokenc.col,
920 tokenc.file,
921 None,
922 )
923 }
924 })),
925 };
926 stack.push(match a.çarp(b) {
927 Ok(a) => a,
928 Err(e) => return Err((stack, hashs, e)),
929 });
930 self.current += 1;
931 }
932 TokenType::Bölü => {
933 let a = match stack.pop() {
934 Some(a) => a,
935 None => return Err((stack, hashs, match get_lang() {
936 SupportedLanguage::Turkish => {
937 ErrorGenerator::error(
938 "KümedeYeterliDeğişkenYok",
939 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
940 tokenc.line,
941 tokenc.col,
942 tokenc.file,
943 None,
944 )
945 }
946 SupportedLanguage::English => {
947 ErrorGenerator::error(
948 "NotEnoughVarsInStack",
949 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
950 tokenc.line,
951 tokenc.col,
952 tokenc.file,
953 None,
954 )
955 }
956 })),
957 };
958 let b = match stack.pop() {
959 Some(a) => a,
960 None => return Err((stack, hashs, match get_lang() {
961 SupportedLanguage::Turkish => {
962 ErrorGenerator::error(
963 "KümedeYeterliDeğişkenYok",
964 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
965 tokenc.line,
966 tokenc.col,
967 tokenc.file,
968 None,
969 )
970 }
971 SupportedLanguage::English => {
972 ErrorGenerator::error(
973 "NotEnoughVarsInStack",
974 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
975 tokenc.line,
976 tokenc.col,
977 tokenc.file,
978 None,
979 )
980 }
981 })),
982 };
983 stack.push(match b.böl(a) {
984 Ok(a) => a,
985 Err(e) => return Err((stack, hashs, e)),
986 });
987 self.current += 1;
988 }
989 TokenType::Sayı { val } => {
990 let n = Object::Sayı(val);
991 stack.push(n);
992 self.current += 1;
993 }
994 TokenType::Yazı { val } => {
995 let s = Object::Yazı(val);
996 stack.push(s);
997 self.current += 1;
998 }
999 TokenType::Bool { val } => {
1000 let b = Object::Bool(val);
1001 stack.push(b);
1002 self.current += 1;
1003 }
1004 TokenType::İse(yoksa) | TokenType::İken(yoksa) => {
1005 if let Some(tp) = yoksa {
1006 let a = match stack.pop() {
1007 Some(a) => a,
1008 None => return Err((stack, hashs, match get_lang() {
1009 SupportedLanguage::Turkish => {
1010 ErrorGenerator::error(
1011 "KümedeYeterliDeğişkenYok",
1012 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1013 tokenc.line,
1014 tokenc.col,
1015 tokenc.file,
1016 None,
1017 )
1018 }
1019 SupportedLanguage::English => {
1020 ErrorGenerator::error(
1021 "NotEnoughVarsInStack",
1022 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1023 tokenc.line,
1024 tokenc.col,
1025 tokenc.file,
1026 None,
1027 )
1028 }
1029 })),
1030 };
1031 match a {
1032 Object::Bool(b) => {
1033 if b {
1034 self.current += 1;
1035 } else {
1036 self.current = tp;
1037 }
1038 }
1039 _ => {
1040 let b = match stack.pop() {
1041 Some(a) => a,
1042 None => return Err((stack, hashs, match get_lang() {
1043 SupportedLanguage::Turkish => {
1044 ErrorGenerator::error(
1045 "KümedeYeterliDeğişkenYok",
1046 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1047 tokenc.line,
1048 tokenc.col,
1049 tokenc.file,
1050 None,
1051 )
1052 }
1053 SupportedLanguage::English => {
1054 ErrorGenerator::error(
1055 "NotEnoughVarsInStack",
1056 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1057 tokenc.line,
1058 tokenc.col,
1059 tokenc.file,
1060 None,
1061 )
1062 }
1063 })),
1064 };
1065 match b.eşittir(a) {
1066 Ok(Object::Bool(true)) => self.current += 1,
1067 Ok(Object::Bool(false)) => self.current = tp,
1068 Ok(_) => unreachable!(),
1069 Err(e) => return Err((stack, hashs, e)),
1070 }
1071 }
1072 }
1073 } else {
1074 unreachable!()
1075 }
1076 }
1077 TokenType::Kopya => {
1078 let last = match stack.pop() {
1079 Some(a) => a,
1080 None => return Err((stack, hashs, match get_lang() {
1081 SupportedLanguage::Turkish => {
1082 ErrorGenerator::error(
1083 "KümedeYeterliDeğişkenYok",
1084 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1085 tokenc.line,
1086 tokenc.col,
1087 tokenc.file,
1088 None,
1089 )
1090 }
1091 SupportedLanguage::English => {
1092 ErrorGenerator::error(
1093 "NotEnoughVarsInStack",
1094 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1095 tokenc.line,
1096 tokenc.col,
1097 tokenc.file,
1098 None,
1099 )
1100 }
1101 })),
1102 };
1103 stack.push(last.clone());
1104 stack.push(last);
1105 self.current += 1;
1106 }
1107 TokenType::Büyüktür => {
1108 let a = match stack.pop() {
1109 Some(a) => a,
1110 None => return Err((stack, hashs, match get_lang() {
1111 SupportedLanguage::Turkish => {
1112 ErrorGenerator::error(
1113 "KümedeYeterliDeğişkenYok",
1114 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1115 tokenc.line,
1116 tokenc.col,
1117 tokenc.file,
1118 None,
1119 )
1120 }
1121 SupportedLanguage::English => {
1122 ErrorGenerator::error(
1123 "NotEnoughVarsInStack",
1124 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1125 tokenc.line,
1126 tokenc.col,
1127 tokenc.file,
1128 None,
1129 )
1130 }
1131 })),
1132 };
1133 let b = match stack.pop() {
1134 Some(a) => a,
1135 None => return Err((stack, hashs, match get_lang() {
1136 SupportedLanguage::Turkish => {
1137 ErrorGenerator::error(
1138 "KümedeYeterliDeğişkenYok",
1139 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1140 tokenc.line,
1141 tokenc.col,
1142 tokenc.file,
1143 None,
1144 )
1145 }
1146 SupportedLanguage::English => {
1147 ErrorGenerator::error(
1148 "NotEnoughVarsInStack",
1149 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1150 tokenc.line,
1151 tokenc.col,
1152 tokenc.file,
1153 None,
1154 )
1155 }
1156 })),
1157 };
1158 stack.push(match b.büyüktür(a) {
1159 Ok(a) => a,
1160 Err(e) => return Err((stack, hashs, e)),
1161 });
1162 self.current += 1;
1163 }
1164 TokenType::BüyükEşittir => {
1165 let a = match stack.pop() {
1166 Some(a) => a,
1167 None => return Err((stack, hashs, match get_lang() {
1168 SupportedLanguage::Turkish => {
1169 ErrorGenerator::error(
1170 "KümedeYeterliDeğişkenYok",
1171 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1172 tokenc.line,
1173 tokenc.col,
1174 tokenc.file,
1175 None,
1176 )
1177 }
1178 SupportedLanguage::English => {
1179 ErrorGenerator::error(
1180 "NotEnoughVarsInStack",
1181 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1182 tokenc.line,
1183 tokenc.col,
1184 tokenc.file,
1185 None,
1186 )
1187 }
1188 })),
1189 };
1190 let b = match stack.pop() {
1191 Some(a) => a,
1192 None => return Err((stack, hashs, match get_lang() {
1193 SupportedLanguage::Turkish => {
1194 ErrorGenerator::error(
1195 "KümedeYeterliDeğişkenYok",
1196 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1197 tokenc.line,
1198 tokenc.col,
1199 tokenc.file,
1200 None,
1201 )
1202 }
1203 SupportedLanguage::English => {
1204 ErrorGenerator::error(
1205 "NotEnoughVarsInStack",
1206 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1207 tokenc.line,
1208 tokenc.col,
1209 tokenc.file,
1210 None,
1211 )
1212 }
1213 })),
1214 };
1215 stack.push(match b.büyük_eşittir(a) {
1216 Ok(a) => a,
1217 Err(e) => return Err((stack, hashs, e)),
1218 });
1219 self.current += 1;
1220 }
1221 TokenType::Küçüktür => {
1222 let a = match stack.pop() {
1223 Some(a) => a,
1224 None => return Err((stack, hashs, match get_lang() {
1225 SupportedLanguage::Turkish => {
1226 ErrorGenerator::error(
1227 "KümedeYeterliDeğişkenYok",
1228 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1229 tokenc.line,
1230 tokenc.col,
1231 tokenc.file,
1232 None,
1233 )
1234 }
1235 SupportedLanguage::English => {
1236 ErrorGenerator::error(
1237 "NotEnoughVarsInStack",
1238 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1239 tokenc.line,
1240 tokenc.col,
1241 tokenc.file,
1242 None,
1243 )
1244 }
1245 })),
1246 };
1247 let b = match stack.pop() {
1248 Some(a) => a,
1249 None => return Err((stack, hashs, match get_lang() {
1250 SupportedLanguage::Turkish => {
1251 ErrorGenerator::error(
1252 "KümedeYeterliDeğişkenYok",
1253 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1254 tokenc.line,
1255 tokenc.col,
1256 tokenc.file,
1257 None,
1258 )
1259 }
1260 SupportedLanguage::English => {
1261 ErrorGenerator::error(
1262 "NotEnoughVarsInStack",
1263 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1264 tokenc.line,
1265 tokenc.col,
1266 tokenc.file,
1267 None,
1268 )
1269 }
1270 })),
1271 };
1272 stack.push(match b.küçüktür(a) {
1273 Ok(a) => a,
1274 Err(e) => return Err((stack, hashs, e)),
1275 });
1276 self.current += 1;
1277 }
1278 TokenType::KüçükEşittir => {
1279 let a = match stack.pop() {
1280 Some(a) => a,
1281 None => return Err((stack, hashs, match get_lang() {
1282 SupportedLanguage::Turkish => {
1283 ErrorGenerator::error(
1284 "KümedeYeterliDeğişkenYok",
1285 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1286 tokenc.line,
1287 tokenc.col,
1288 tokenc.file,
1289 None,
1290 )
1291 }
1292 SupportedLanguage::English => {
1293 ErrorGenerator::error(
1294 "NotEnoughVarsInStack",
1295 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1296 tokenc.line,
1297 tokenc.col,
1298 tokenc.file,
1299 None,
1300 )
1301 }
1302 })),
1303 };
1304 let b = match stack.pop() {
1305 Some(a) => a,
1306 None => return Err((stack, hashs, match get_lang() {
1307 SupportedLanguage::Turkish => {
1308 ErrorGenerator::error(
1309 "KümedeYeterliDeğişkenYok",
1310 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1311 tokenc.line,
1312 tokenc.col,
1313 tokenc.file,
1314 None,
1315 )
1316 }
1317 SupportedLanguage::English => {
1318 ErrorGenerator::error(
1319 "NotEnoughVarsInStack",
1320 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1321 tokenc.line,
1322 tokenc.col,
1323 tokenc.file,
1324 None,
1325 )
1326 }
1327 })),
1328 };
1329 stack.push(match b.küçük_eşittir(a) {
1330 Ok(a) => a,
1331 Err(e) => return Err((stack, hashs, e)),
1332 });
1333 self.current += 1;
1334 }
1335 TokenType::Eşittir => {
1336 let a = match stack.pop() {
1337 Some(a) => a,
1338 None => return Err((stack, hashs, match get_lang() {
1339 SupportedLanguage::Turkish => {
1340 ErrorGenerator::error(
1341 "KümedeYeterliDeğişkenYok",
1342 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1343 tokenc.line,
1344 tokenc.col,
1345 tokenc.file,
1346 None,
1347 )
1348 }
1349 SupportedLanguage::English => {
1350 ErrorGenerator::error(
1351 "NotEnoughVarsInStack",
1352 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1353 tokenc.line,
1354 tokenc.col,
1355 tokenc.file,
1356 None,
1357 )
1358 }
1359 })),
1360 };
1361 let b = match stack.pop() {
1362 Some(a) => a,
1363 None => return Err((stack, hashs, match get_lang() {
1364 SupportedLanguage::Turkish => {
1365 ErrorGenerator::error(
1366 "KümedeYeterliDeğişkenYok",
1367 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1368 tokenc.line,
1369 tokenc.col,
1370 tokenc.file,
1371 None,
1372 )
1373 }
1374 SupportedLanguage::English => {
1375 ErrorGenerator::error(
1376 "NotEnoughVarsInStack",
1377 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1378 tokenc.line,
1379 tokenc.col,
1380 tokenc.file,
1381 None,
1382 )
1383 }
1384 })),
1385 };
1386 stack.push(match b.eşittir(a) {
1387 Ok(a) => a,
1388 Err(e) => return Err((stack, hashs, e)),
1389 });
1390 self.current += 1;
1391 }
1392 TokenType::EşitDeğildir => {
1393 let a = match stack.pop() {
1394 Some(a) => a,
1395 None => return Err((stack, hashs, match get_lang() {
1396 SupportedLanguage::Turkish => {
1397 ErrorGenerator::error(
1398 "KümedeYeterliDeğişkenYok",
1399 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1400 tokenc.line,
1401 tokenc.col,
1402 tokenc.file,
1403 None,
1404 )
1405 }
1406 SupportedLanguage::English => {
1407 ErrorGenerator::error(
1408 "NotEnoughVarsInStack",
1409 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1410 tokenc.line,
1411 tokenc.col,
1412 tokenc.file,
1413 None,
1414 )
1415 }
1416 })),
1417 };
1418 let b = match stack.pop() {
1419 Some(a) => a,
1420 None => return Err((stack, hashs, match get_lang() {
1421 SupportedLanguage::Turkish => {
1422 ErrorGenerator::error(
1423 "KümedeYeterliDeğişkenYok",
1424 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1425 tokenc.line,
1426 tokenc.col,
1427 tokenc.file,
1428 None,
1429 )
1430 }
1431 SupportedLanguage::English => {
1432 ErrorGenerator::error(
1433 "NotEnoughVarsInStack",
1434 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1435 tokenc.line,
1436 tokenc.col,
1437 tokenc.file,
1438 None,
1439 )
1440 }
1441 })),
1442 };
1443 stack.push(match b.eşit_değildir(a) {
1444 Ok(a) => a,
1445 Err(e) => return Err((stack, hashs, e)),
1446 });
1447 self.current += 1;
1448 }
1449 TokenType::Değildir => {
1450 let a = match stack.pop() {
1451 Some(a) => a,
1452 None => return Err((stack, hashs, match get_lang() {
1453 SupportedLanguage::Turkish => {
1454 ErrorGenerator::error(
1455 "KümedeYeterliDeğişkenYok",
1456 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1457 tokenc.line,
1458 tokenc.col,
1459 tokenc.file,
1460 None,
1461 )
1462 }
1463 SupportedLanguage::English => {
1464 ErrorGenerator::error(
1465 "NotEnoughVarsInStack",
1466 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1467 tokenc.line,
1468 tokenc.col,
1469 tokenc.file,
1470 None,
1471 )
1472 }
1473 })),
1474 };
1475 stack.push(match a.değildir() {
1476 Ok(a) => a,
1477 Err(e) => return Err((stack, hashs, e)),
1478 });
1479 self.current += 1;
1480 }
1481 TokenType::Son { tp } => {
1482 self.current = tp;
1483 }
1484 TokenType::Yoksa(yoksa) => {
1485 if let Some(tp) = yoksa {
1486 self.current = tp;
1487 } else {
1488 unreachable!()
1489 }
1490 }
1491 TokenType::Modulo => {
1492 let a = match stack.pop() {
1493 Some(a) => a,
1494 None => return Err((stack, hashs, match get_lang() {
1495 SupportedLanguage::Turkish => {
1496 ErrorGenerator::error(
1497 "KümedeYeterliDeğişkenYok",
1498 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1499 tokenc.line,
1500 tokenc.col,
1501 tokenc.file,
1502 None,
1503 )
1504 }
1505 SupportedLanguage::English => {
1506 ErrorGenerator::error(
1507 "NotEnoughVarsInStack",
1508 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1509 tokenc.line,
1510 tokenc.col,
1511 tokenc.file,
1512 None,
1513 )
1514 }
1515 })),
1516 };
1517 let b = match stack.pop() {
1518 Some(a) => a,
1519 None => return Err((stack, hashs, match get_lang() {
1520 SupportedLanguage::Turkish => {
1521 ErrorGenerator::error(
1522 "KümedeYeterliDeğişkenYok",
1523 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1524 tokenc.line,
1525 tokenc.col,
1526 tokenc.file,
1527 None,
1528 )
1529 }
1530 SupportedLanguage::English => {
1531 ErrorGenerator::error(
1532 "NotEnoughVarsInStack",
1533 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1534 tokenc.line,
1535 tokenc.col,
1536 tokenc.file,
1537 None,
1538 )
1539 }
1540 })),
1541 };
1542 stack.push(match b.modulo(a) {
1543 Ok(a) => a,
1544 Err(e) => return Err((stack, hashs, e)),
1545 });
1546 self.current += 1;
1547 }
1548 TokenType::Takas => {
1549 let a = match stack.pop() {
1550 Some(a) => a,
1551 None => return Err((stack, hashs, match get_lang() {
1552 SupportedLanguage::Turkish => {
1553 ErrorGenerator::error(
1554 "KümedeYeterliDeğişkenYok",
1555 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1556 tokenc.line,
1557 tokenc.col,
1558 tokenc.file,
1559 None,
1560 )
1561 }
1562 SupportedLanguage::English => {
1563 ErrorGenerator::error(
1564 "NotEnoughVarsInStack",
1565 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1566 tokenc.line,
1567 tokenc.col,
1568 tokenc.file,
1569 None,
1570 )
1571 }
1572 })),
1573 };
1574 let b = match stack.pop() {
1575 Some(a) => a,
1576 None => return Err((stack, hashs, match get_lang() {
1577 SupportedLanguage::Turkish => {
1578 ErrorGenerator::error(
1579 "KümedeYeterliDeğişkenYok",
1580 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1581 tokenc.line,
1582 tokenc.col,
1583 tokenc.file,
1584 None,
1585 )
1586 }
1587 SupportedLanguage::English => {
1588 ErrorGenerator::error(
1589 "NotEnoughVarsInStack",
1590 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1591 tokenc.line,
1592 tokenc.col,
1593 tokenc.file,
1594 None,
1595 )
1596 }
1597 })),
1598 };
1599 stack.push(a);
1600 stack.push(b);
1601 self.current += 1;
1602 }
1603 TokenType::Döndür => {
1604 let a = match stack.pop() {
1605 Some(a) => a,
1606 None => return Err((stack, hashs, match get_lang() {
1607 SupportedLanguage::Turkish => {
1608 ErrorGenerator::error(
1609 "KümedeYeterliDeğişkenYok",
1610 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1611 tokenc.line,
1612 tokenc.col,
1613 tokenc.file,
1614 None,
1615 )
1616 }
1617 SupportedLanguage::English => {
1618 ErrorGenerator::error(
1619 "NotEnoughVarsInStack",
1620 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1621 tokenc.line,
1622 tokenc.col,
1623 tokenc.file,
1624 None,
1625 )
1626 }
1627 })),
1628 };
1629 let b = match stack.pop() {
1630 Some(a) => a,
1631 None => return Err((stack, hashs, match get_lang() {
1632 SupportedLanguage::Turkish => {
1633 ErrorGenerator::error(
1634 "KümedeYeterliDeğişkenYok",
1635 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1636 tokenc.line,
1637 tokenc.col,
1638 tokenc.file,
1639 None,
1640 )
1641 }
1642 SupportedLanguage::English => {
1643 ErrorGenerator::error(
1644 "NotEnoughVarsInStack",
1645 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1646 tokenc.line,
1647 tokenc.col,
1648 tokenc.file,
1649 None,
1650 )
1651 }
1652 })),
1653 };
1654 let c = match stack.pop() {
1655 Some(a) => a,
1656 None => return Err((stack, hashs, match get_lang() {
1657 SupportedLanguage::Turkish => {
1658 ErrorGenerator::error(
1659 "KümedeYeterliDeğişkenYok",
1660 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1661 tokenc.line,
1662 tokenc.col,
1663 tokenc.file,
1664 None,
1665 )
1666 }
1667 SupportedLanguage::English => {
1668 ErrorGenerator::error(
1669 "NotEnoughVarsInStack",
1670 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1671 tokenc.line,
1672 tokenc.col,
1673 tokenc.file,
1674 None,
1675 )
1676 }
1677 })),
1678 };
1679 stack.push(a);
1680 stack.push(b);
1681 stack.push(c);
1682 self.current += 1;
1683 }
1684 TokenType::At => {
1685 match stack.pop() {
1686 Some(a) => a,
1687 None => return Err((stack, hashs, match get_lang() {
1688 SupportedLanguage::Turkish => {
1689 ErrorGenerator::error(
1690 "KümedeYeterliDeğişkenYok",
1691 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1692 tokenc.line,
1693 tokenc.col,
1694 tokenc.file,
1695 None,
1696 )
1697 }
1698 SupportedLanguage::English => {
1699 ErrorGenerator::error(
1700 "NotEnoughVarsInStack",
1701 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1702 tokenc.line,
1703 tokenc.col,
1704 tokenc.file,
1705 None,
1706 )
1707 }
1708 })),
1709 };
1710 self.current += 1;
1711 }
1712 TokenType::Üst => {
1713 let a = match stack.pop() {
1714 Some(a) => a,
1715 None => return Err((stack, hashs, match get_lang() {
1716 SupportedLanguage::Turkish => {
1717 ErrorGenerator::error(
1718 "KümedeYeterliDeğişkenYok",
1719 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1720 tokenc.line,
1721 tokenc.col,
1722 tokenc.file,
1723 None,
1724 )
1725 }
1726 SupportedLanguage::English => {
1727 ErrorGenerator::error(
1728 "NotEnoughVarsInStack",
1729 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1730 tokenc.line,
1731 tokenc.col,
1732 tokenc.file,
1733 None,
1734 )
1735 }
1736 })),
1737 };
1738 let b = match stack.pop() {
1739 Some(a) => a,
1740 None => return Err((stack, hashs, match get_lang() {
1741 SupportedLanguage::Turkish => {
1742 ErrorGenerator::error(
1743 "KümedeYeterliDeğişkenYok",
1744 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` anahtar kelimesi uygulanamamıştır", tokenc.repr()),
1745 tokenc.line,
1746 tokenc.col,
1747 tokenc.file,
1748 None,
1749 )
1750 }
1751 SupportedLanguage::English => {
1752 ErrorGenerator::error(
1753 "NotEnoughVarsInStack",
1754 &format!("because there weren't enough variables in the stack, the keyword `{}` couldn't be used", tokenc.repr()),
1755 tokenc.line,
1756 tokenc.col,
1757 tokenc.file,
1758 None,
1759 )
1760 }
1761 })),
1762 };
1763 stack.push(b.clone());
1764 stack.push(a);
1765 stack.push(b);
1766 self.current += 1;
1767 }
1768 TokenType::Girdi => {
1769 let mut buf = String::new();
1770 io::stdin().read_line(&mut buf).unwrap();
1771 stack.push(Object::Yazı(buf.trim_end().to_string()));
1772 self.current += 1;
1773 }
1774 TokenType::İkiNoktaNokta | TokenType::EOF => self.current += 1,
1775 TokenType::Identifier { id } => match hashs.clone().get_mut(&id) {
1776 Some(val) => match val {
1777 Object::Hiç
1778 | Object::Bool(_)
1779 | Object::Sayı(_)
1780 | Object::Yazı(_)
1781 | Object::Liste(_)
1782 | Object::Harita(_) => {
1783 stack.push(val.clone());
1784 self.current += 1;
1785 }
1786 Object::İşlev(tp) => {
1787 let işlev = self.program.get(*tp).unwrap();
1788 match işlev.typ {
1789 TokenType::İşlev { sonloc: tpi } => {
1790 let loc = match tpi {
1791 Some(i) => i,
1792 None => unreachable!(),
1793 };
1794 let işlevson = self.program.get_mut(loc).unwrap();
1795 match &mut işlevson.typ {
1796 TokenType::İşlevSonlandır { tp: ref mut tps } => {
1797 tps.push(self.current);
1798 }
1799 _ => unreachable!(),
1800 }
1801 self.current = *tp + 2;
1802 }
1803 _ => unreachable!(),
1804 }
1805 stack.new_stack();
1806 hashs.new_hash();
1807 }
1808 },
1809 None => {
1810 return Err((stack, hashs.clone(), match get_lang() {
1811 SupportedLanguage::Turkish => {
1812 ErrorGenerator::error(
1813 "BilinmeyenTanımlayıcı",
1814 &format!(
1815 "bilinmeyen değişken: `{}`, bu değişken bulunamamıştır",
1816 tokenc.repr()
1817 ),
1818 tokenc.line,
1819 tokenc.col,
1820 tokenc.file,
1821 {
1822 let mut hashk = hashs.clone().into_keys();
1823 hashk.sort();
1824 let n = hashk.binary_search(&id).unwrap_err();
1825 if hashk.is_empty() {
1826 None
1827 } else {
1828 Some(format!("`{}` demek mi istediniz?", hashk[n]))
1829 }
1830 }
1831 )
1832 }
1833 SupportedLanguage::English => {
1834 ErrorGenerator::error(
1835 "UnknownIdentifier",
1836 &format!("unknown identifier: `{}`, this identifier could not be found", tokenc.repr()),
1837 tokenc.line,
1838 tokenc.col,
1839 tokenc.file,
1840 {
1841 let mut hashk = hashs.clone().into_keys();
1842 hashk.sort();
1843 let n = hashk.binary_search(&id).unwrap_err();
1844 if hashk.is_empty() {
1845 None
1846 } else {
1847 Some(format!("maybe you meant {}?", hashk[n]))
1848 }
1849 },
1850 )
1851 }
1852 }));
1853 }
1854 },
1855 TokenType::Koy => {
1856 let a = match stack.pop() {
1857 Some(a) => a,
1858 None => return Err((stack, hashs, match get_lang() {
1859 SupportedLanguage::Turkish => {
1860 ErrorGenerator::error(
1861 "KümedeYeterliDeğişkenYok",
1862 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1863 tokenc.line,
1864 tokenc.col,
1865 tokenc.file,
1866 None,
1867 )
1868 }
1869 SupportedLanguage::English => {
1870 ErrorGenerator::error(
1871 "NotEnoughVarsInStack",
1872 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1873 tokenc.line,
1874 tokenc.col,
1875 tokenc.file,
1876 None,
1877 )
1878 }
1879 })),
1880 };
1881 let id = self.program.get(self.current + 1).unwrap();
1882 hashs.insert(
1883 match id.typ.clone() {
1884 TokenType::Identifier { id: i } => i,
1885 t => {
1886 return Err((
1887 stack,
1888 hashs,
1889 match get_lang() {
1890 SupportedLanguage::Turkish => ErrorGenerator::error(
1891 "BeklenmedikSimge",
1892 &format!(
1893 "Tanımlayıcı simgesi beklenmişti ancak {:?} bulundu",
1894 t
1895 ),
1896 tokenc.line,
1897 tokenc.col,
1898 tokenc.file,
1899 None,
1900 ),
1901 SupportedLanguage::English => ErrorGenerator::error(
1902 "UnexpectedToken",
1903 &format!("expected Identifier but found {:?}", t),
1904 tokenc.line,
1905 tokenc.col,
1906 tokenc.file,
1907 None,
1908 ),
1909 },
1910 ))
1911 }
1912 },
1913 a,
1914 );
1915 self.current += 2;
1916 }
1917 TokenType::Ve => {
1918 let a = match stack.pop() {
1919 Some(a) => a,
1920 None => return Err((stack, hashs, match get_lang() {
1921 SupportedLanguage::Turkish => {
1922 ErrorGenerator::error(
1923 "KümedeYeterliDeğişkenYok",
1924 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1925 tokenc.line,
1926 tokenc.col,
1927 tokenc.file,
1928 None,
1929 )
1930 }
1931 SupportedLanguage::English => {
1932 ErrorGenerator::error(
1933 "NotEnoughVarsInStack",
1934 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1935 tokenc.line,
1936 tokenc.col,
1937 tokenc.file,
1938 None,
1939 )
1940 }
1941 })),
1942 };
1943 let b = match stack.pop() {
1944 Some(a) => a,
1945 None => return Err((stack, hashs, match get_lang() {
1946 SupportedLanguage::Turkish => {
1947 ErrorGenerator::error(
1948 "KümedeYeterliDeğişkenYok",
1949 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1950 tokenc.line,
1951 tokenc.col,
1952 tokenc.file,
1953 None,
1954 )
1955 }
1956 SupportedLanguage::English => {
1957 ErrorGenerator::error(
1958 "NotEnoughVarsInStack",
1959 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1960 tokenc.line,
1961 tokenc.col,
1962 tokenc.file,
1963 None,
1964 )
1965 }
1966 })),
1967 };
1968 stack.push(
1969 match b.ve(a, tokenc.line, tokenc.col, tokenc.file.clone()) {
1970 Ok(a) => a,
1971 Err(e) => return Err((stack, hashs, e)),
1972 },
1973 );
1974 self.current += 1;
1975 }
1976 TokenType::Veya => {
1977 let a = match stack.pop() {
1978 Some(a) => a,
1979 None => return Err((stack, hashs, match get_lang() {
1980 SupportedLanguage::Turkish => {
1981 ErrorGenerator::error(
1982 "KümedeYeterliDeğişkenYok",
1983 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
1984 tokenc.line,
1985 tokenc.col,
1986 tokenc.file,
1987 None,
1988 )
1989 }
1990 SupportedLanguage::English => {
1991 ErrorGenerator::error(
1992 "NotEnoughVarsInStack",
1993 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
1994 tokenc.line,
1995 tokenc.col,
1996 tokenc.file,
1997 None,
1998 )
1999 }
2000 })),
2001 };
2002 let b = match stack.pop() {
2003 Some(a) => a,
2004 None => return Err((stack, hashs, match get_lang() {
2005 SupportedLanguage::Turkish => {
2006 ErrorGenerator::error(
2007 "KümedeYeterliDeğişkenYok",
2008 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
2009 tokenc.line,
2010 tokenc.col,
2011 tokenc.file,
2012 None,
2013 )
2014 }
2015 SupportedLanguage::English => {
2016 ErrorGenerator::error(
2017 "NotEnoughVarsInStack",
2018 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
2019 tokenc.line,
2020 tokenc.col,
2021 tokenc.file,
2022 None,
2023 )
2024 }
2025 })),
2026 };
2027 stack.push(
2028 match b.veya(a, tokenc.line, tokenc.col, tokenc.file.clone()) {
2029 Ok(a) => a,
2030 Err(e) => return Err((stack, hashs, e)),
2031 },
2032 );
2033 self.current += 1;
2034 }
2035 TokenType::Tipinde => {
2036 let a = match stack.pop() {
2037 Some(a) => a,
2038 None => return Err((stack, hashs, match get_lang() {
2039 SupportedLanguage::Turkish => {
2040 ErrorGenerator::error(
2041 "KümedeYeterliDeğişkenYok",
2042 &format!("kümede yeterli değişken bulunmadığından dolayı `{}` operatörü uygulanamamıştır", tokenc.repr()),
2043 tokenc.line,
2044 tokenc.col,
2045 tokenc.file,
2046 None,
2047 )
2048 }
2049 SupportedLanguage::English => {
2050 ErrorGenerator::error(
2051 "NotEnoughVarsInStack",
2052 &format!("because there weren't enough variables in the stack, the operator `{}` couldn't be used", tokenc.repr()),
2053 tokenc.line,
2054 tokenc.col,
2055 tokenc.file,
2056 None,
2057 )
2058 }
2059 })),
2060 };
2061 self.current += 1;
2062 let b = self.program.get_mut(self.current).unwrap();
2063 match &b.typ {
2064 TokenType::Identifier { id } => {
2065 stack.push(
2066 match a.dönüştür(id.clone(), b.line, b.col, b.file.clone()) {
2067 Ok(a) => a,
2068 Err(e) => return Err((stack, hashs, e)),
2069 },
2070 );
2071 }
2072 _ => {
2073 return Err((
2074 stack,
2075 hashs,
2076 match get_lang() {
2077 SupportedLanguage::Turkish => ErrorGenerator::error(
2078 "BeklenmedikSimge",
2079 &format!(
2080 "tanımlayıcı beklenmişti ancak `{}` bulundu",
2081 b.repr()
2082 ),
2083 tokenc.line,
2084 tokenc.col,
2085 tokenc.file,
2086 None,
2087 ),
2088 SupportedLanguage::English => ErrorGenerator::error(
2089 "UnexpectedToken",
2090 &format!("expected identifier, but found `{}`", b.repr()),
2091 tokenc.line,
2092 tokenc.col,
2093 tokenc.file,
2094 None,
2095 ),
2096 },
2097 ))
2098 }
2099 };
2100 self.current += 1;
2101 }
2102 }
2103 }
2104
2105 if stack.len() > 0 && !unsafe { SUPRESS_WARN } && !repl {
2106 match get_lang() {
2107 SupportedLanguage::Turkish => {
2108 ErrorGenerator::warning(
2109 "KümeBoşDeğil",
2110 "küme boş değil, eğer nedeninden şüphe ediyorsanız kodunuzu kontrol etmeniz önerilir",
2111 0,
2112 0,
2113 file
2114 )();
2115 print!(" kümede kalan değişkenler({:?}) [", stack.len());
2116 for (i, o) in stack.iter_vec().iter().rev().take(3).rev().enumerate() {
2117 let o = match o {
2118 Object::Yazı(s) => format!("{:?}", s),
2119 Object::Hiç
2120 | Object::Bool(_)
2121 | Object::Sayı(_)
2122 | Object::Liste(_)
2123 | Object::Harita(_) => format!("{:?}", o),
2124 Object::İşlev(_) => unreachable!(),
2125 };
2126 if i > 0 {
2127 print!(", {}", o);
2128 } else {
2129 if stack.len() > 3 {
2130 print!("... {}", o);
2131 } else {
2132 print!("{}", o);
2133 }
2134 }
2135 }
2136 println!("]");
2137 }
2138 SupportedLanguage::English => {
2139 ErrorGenerator::warning(
2140 "StackNotEmpty",
2141 "stack is not empty, if you aren't sure about why, you might want to take a look at you code",
2142 0,
2143 0,
2144 file
2145 )();
2146 print!(" variables left in the stack({:?}) [", stack.len());
2147 for (i, o) in stack.iter_vec().iter().rev().take(3).rev().enumerate() {
2148 let o = match o {
2149 Object::Yazı(s) => format!("{:?}", s),
2150 Object::Hiç
2151 | Object::Bool(_)
2152 | Object::Sayı(_)
2153 | Object::Liste(_)
2154 | Object::Harita(_) => format!("{:?}", o),
2155 Object::İşlev(_) => unreachable!(),
2156 };
2157 if i > 0 {
2158 print!(", {}", o);
2159 } else {
2160 if stack.len() > 3 {
2161 print!("...{}", o);
2162 } else {
2163 print!("{}", o);
2164 }
2165 }
2166 }
2167 println!("]");
2168 }
2169 }
2170 }
2171 Ok((stack, hashs))
2172 }
2173}