21
21
22
22
@app .route ('/' )
23
23
def home ():
24
+ global intent
25
+ intent = []
24
26
return render_template ('compiler.html' )
27
+
25
28
26
29
27
30
@app .route ('/print/name' , methods = ['POST' , 'GET' ])
@@ -64,6 +67,7 @@ def get_names():
64
67
intent .append (b [0 ]['intent' ])
65
68
else :
66
69
intent .append (b [0 ]['intent' ])
70
+ print ('user said:' , command )
67
71
print (intent )
68
72
69
73
while intent [0 ]== 'python' :
@@ -129,7 +133,7 @@ def get_names():
129
133
print(ans)"""
130
134
131
135
elif intent [- 1 ]== 'arith_multiplication' :
132
- to_send = """def mult (a,b):
136
+ to_send = """def multi (a,b):
133
137
return a*b
134
138
x=int(input())
135
139
y=int(input())
@@ -268,7 +272,7 @@ def get_names():
268
272
int main() {
269
273
int x,y;
270
274
cin>>x>>y;
271
- cout<<"Product is: "<< x*y <<endl;
275
+ cout<<"Product is: "<< x*y << endl;
272
276
return 0;
273
277
}"""
274
278
@@ -277,7 +281,7 @@ def get_names():
277
281
using namespace std;
278
282
int main() {
279
283
int x,y;
280
- cout<<"Quotient is: "<< x/y <<endl;
284
+ cout<<"Quotient is: "<< x/y << endl;
281
285
return 0;
282
286
}"""
283
287
@@ -370,7 +374,7 @@ def get_names():
370
374
371
375
########################################################PHP#########################################################################################################################
372
376
while intent [0 ]== 'php' :
373
- if intent == 'for_loop' :
377
+ if intent [ - 1 ] == 'for_loop' :
374
378
to_send = """for ($x = a; $x <= b; $x++) {
375
379
//enter your code
376
380
} """
@@ -529,7 +533,155 @@ def get_names():
529
533
c += 1
530
534
return json .dumps ({"response" : to_send }), 200
531
535
536
+ ######################################################## SWIFT #########################################################################################################################
537
+
538
+ while intent [0 ]== 'swift' :
539
+ if intent [- 1 ]== 'for_loop' :
540
+ to_send = """for i in a...b {
541
+ //enter your code here
542
+ } """
543
+
544
+ elif intent [- 1 ]== 'print' :
545
+ to_send = """ print(//enter your code) """
546
+
547
+ elif intent [- 1 ]== 'nested_for' :
548
+ to_send = """for i in a...b {
549
+ for j in a...b{
550
+ //enter your code here
551
+ }
552
+ }"""
553
+
554
+ elif intent [- 1 ]== 'if_condition' :
555
+ to_send = """let a = 10
556
+ if a < b {
557
+ //enter your code
558
+ }
559
+ //print("This statement is always executed.")"""
560
+
561
+ elif intent [- 1 ]== 'nested_if' :
562
+ to_send = """let a = 10
563
+ if a > b {
564
+ if a > b {
565
+ //enter your code
566
+ }
567
+ }
568
+ //print("This statement is always executed.")
569
+ """
570
+
571
+ elif intent [- 1 ]== 'else_if' :
572
+ to_send = """let a = 10
573
+ if a > b {
574
+ //enter your code
575
+ } else if a > b {
576
+ //enter your code
577
+ }
578
+ //print("This statement is always executed.")
579
+ """
580
+
581
+ elif intent [- 1 ]== 'else_condition' :
582
+ to_send = """let a = 10
583
+ if a > b {
584
+ //enter your code
585
+ }
586
+ else {
587
+ //enter your code
588
+ }"""
589
+
590
+ elif intent [- 1 ]== 'while_loop' :
591
+ to_send = """while a <= b {
592
+ //enter your code
593
+ }"""
532
594
595
+ elif intent [- 1 ]== 'exit_loop' :
596
+ to_send = """if a > b {
597
+ break
598
+ }"""
599
+
600
+ elif intent [- 1 ]== 'do_while_loop' :
601
+ to_send = """repeat {
602
+ var i = 1
603
+ //enter your code here.
604
+ i = i + 1
605
+ } while a < b"""
606
+
607
+ elif intent [- 1 ]== 'init_string' :
608
+ to_send = """var your_string = 'change it here' """
609
+
610
+ elif intent [- 1 ]== 'init_int' :
611
+ to_send = """var your_integer = 0 """
612
+
613
+ elif intent [- 1 ]== 'init_char' :
614
+ to_send = """var your_char = 'C' """
615
+
616
+ elif intent [- 1 ]== 'init_float' :
617
+ to_send = """var your_float = 0.00 """
618
+
619
+ elif intent [- 1 ]== 'arith_addition' :
620
+ to_send = """func add(a: Int , b: Int) -> Int {
621
+ let sum = a + b
622
+ return sum
623
+ }
624
+ print("sum is" , add(a: 2, b: 4), separator: " ")"""
625
+
626
+ elif intent [- 1 ]== 'arith_subtraction' :
627
+ to_send = """func sub(a: Int , b: Int) -> Int {
628
+ let diff = a - b
629
+ return diff
630
+ }
631
+ print("diff is" , sub(a: 10, b: 4), separator: " ")"""
632
+
633
+ elif intent [- 1 ]== 'arith_multiplication' :
634
+ to_send = """func multi(a: Int , b: Int) -> Int {
635
+ let prod = a * b
636
+ return prod
637
+ }
638
+ print("product is" , multi(a: 2, b: 4), separator: " ")"""
639
+
640
+ elif intent [- 1 ]== 'arith_division' :
641
+ to_send = """func divi(a: Int , b: Int) -> Int {
642
+ let diff = a / b
643
+ return diff
644
+ }
645
+ print("quotient is" , divi(a: 19, b: 4), separator: " ")"""
646
+
647
+ elif intent [- 1 ]== 'arith_remainder' :
648
+ to_send = """func modu(a: Int , b: Int) -> Int {
649
+ let mod = a % b
650
+ return mod
651
+ }
652
+ print("reminder is" , modu(a: 18, b: 4), separator: " ")"""
653
+
654
+ elif intent [- 1 ]== 'def_function' :
655
+ to_send = """func your_func_name(a: Int , b: Int) -> String {
656
+ //enter your code
657
+ if a > b{
658
+ The_final_output = "Edit this function"
659
+ }
660
+ return The_final_output
661
+ }
662
+ print("output:" , your_func_name(a: 18, b: 4), separator: " ")"""
663
+
664
+
665
+ elif intent [- 1 ]== 'create_array' :
666
+ to_send = """var your_array = [1,2,3,4,5,6]
667
+ print(your_array)"""
668
+
669
+ elif intent [- 1 ]== 'switch_condition' :
670
+ to_send = """let someCharacter: Character = "z" // or someinteger: Int = 2
671
+ switch someCharacter {
672
+ case "a": // case 1:
673
+ // enter your code
674
+ case "z": // case 2:
675
+ // enter your code
676
+ default:
677
+ // default reply
678
+ }"""
679
+
680
+ else :
681
+ to_send = """running swift"""
682
+
683
+ c += 1
684
+ return json .dumps ({"response" : to_send }), 200
533
685
534
686
c += 1
535
687
return json .dumps ({"response" : ' ' }), 200
@@ -538,7 +690,7 @@ def get_names():
538
690
if __name__ == '__main__' :
539
691
c = 1
540
692
intent = []
541
- webbrowser .open ('http://127.0.0.1:5000/ ' )
693
+ webbrowser .open ('http://127.0.0.1:5000' )
542
694
app .run (debug = False )
543
695
544
696
0 commit comments