-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.php
274 lines (207 loc) · 7.11 KB
/
backend.php
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
<?php
$return_type='int';
$variable_type='int';
if (isset($_POST['submit']))
{
$error = array();//Declare An Array to store any error message
if (empty($_POST['funcname']))
{ //if no name has been supplied
$error[] = 'Please enter a function name! ';//add to array "error"
}
else
{
if(conv_check($_POST['funcname'],1) && conv_check($_POST['funcname'],2) ) //conv_check (string , 1 ) will check for naming convention of Function name
{
$funcname = $_POST['funcname']; //else assign it a variable
}
else
{
$error[] = 'The function name you entered doesn\'t follow the C or Java Function Naming Convention ';
}
}
if (empty($_POST['classname']))
{//if no name has been supplied
$error[] = 'Please enter a class name! ';//add to array "error"
}
else
{
if(conv_check($_POST['classname'],2)) //conv_check (string , 1 ) will check for naming convention of class name for java
{
$classname = $_POST['classname']; //else assign it a variable
}
//
else
{
$error[] = 'The function name you entered doesn\'t follow the Java Class Naming Convention ';
}
}
if (empty($_POST['noofargs']))
{//if no name has been supplied
$error[] = 'Please enter number of arguments ';//add to array "error"
}
else
{
$noofargs = $_POST['noofargs']; //else assign it a variable
//echo $noofargs;
}
$varnames = array(); // array to hold arguments
$dimensions = array(); // array to hold dimensions
$arglistC=array(); //array to hold arg list elemnts
$arglistJ=array(); //array to hold list of Java
for($x=1; $x<=$noofargs; $x++)
{
$varname = 'var'.$x;
$dim = 'dim'.$x;
if (empty($_POST[$varname]))
{//if no name has been supplied
$error[] = 'Please enter a variable name for variable !';//add to array "error"
}
else
{
if(conv_check($_POST[$varname],1) && conv_check($_POST[$varname],2) ) //conv_check (string , 1/2 ) will check for naming convention of name for C and Java
{
$varnames[$x] = $_POST[$varname]; //else assign it a variable
}
//
else
{
$error[] = 'The variable name you entered doesn\'t follow the Java Class Naming Convention ';
}
}
if (empty($_POST[$dim]))
{//if no name has been supplied
$error[] = 'Please enter a dimension for the variable '.$x;//add to array "error"
}
else
{
$indexof_= strpos($_POST[$dim],'_'); //extracting dimension which is in the form f i_1 , where 1 is the dimension.
$indexof_ = $indexof_ + 1;
$extdim =substr($_POST[$dim],$indexof_, $length = 1);
$dimensions[$x] = $extdim; //else assign it a variable
}
//echo $x;
$synC='syntaxC'.$x;
$synJ='syntaxJ'.$x;
if($dimensions[$x]== "0")
{
$arglistC[$x] = $variable_type.' '.$varnames[$x];
$arglistJ[$x] = $variable_type.' '.$varnames[$x];
}
else
{
$arglistC[$x] = $_POST[$synC];
$arglistJ[$x]=$_POST[$synJ];
}
/* else if($dimensions[$x] == "1")
{
$syntaxC=$_POST[$synC];
$syntaxJ=$_POST[$synJ];
switch ($syntaxC)
{
case "arr1":
$arglistC[$x]=$variable_type.' '.$varnames[$x].'[]';
break;
case "ptr1":
$arglistC[$x]=$variable_type.' *'.$varnames[$x];
break;
}
switch ($syntaxJ)
{
case "jarr1":
$arglistJ[$x]=$variable_type.'[] '.$varnames[$x];
break;
case "jlist1":
$arglistJ[$x]='ArrayList '.$varnames[$x].'<'.$variable_type.'>';
break;
case "jset1":
$arglistJ[$x]='Set '.$varnames[$x].'<'.$variable_type.'<';
break;
}
}
else if($dimensions[$x] == "2")
{
$syntaxC=$_POST[$synC];
$syntaxJ=$_POST[$synJ];
switch ($syntaxC)
{
case "arr2":
$arglistC[$x]=$variable_type.' '.$varnames[$x].'[][]';
break;
case "ptr2":
$arglistC[$x]=$variable_type.' **'.$varnames[$x];
break;
case "ptr12":
$arglistC[$x]=$variable_type.' *'.$varnames[$x].'[]';
break;
}
switch ($syntaxJ)
{
case "jarr2":
$arglistJ[$x]=$variable_type.'[][] '.$varnames[$x];
break;
case "jlist2":
$arglistJ[$x]='ArrayList '.$varnames[$x].'<'.$variable_type.'>';
break;
case "jset2":
$arglistJ[$x]='Set '.$varnames[$x].'<'.$variable_type.'>'; // various forms can be updated here
break;
}
}*/
}
//echo $arglistC[1];
create_stringC($funcname,$classname,$noofargs,$arglistC,$return_type);
create_stringJava($funcname,$classname,$noofargs,$arglistJ,$return_type);
echo '<div class="errormsgbox"> <ol>';
foreach ($error as $key => $values)
{
echo ' <li>'.$values.'</li>';
}
echo '</ol></div>';
}
function conv_check($name , $opt)
{
switch ($opt)
{
case "1":
if(preg_match("/^[A-Za-z_][A-Za-z_0-9]*$/", $name)) //matching convention for variable name in C
return TRUE;
else
return FALSE;
break;
case "2":
if(preg_match("/(^[a-zA-Z][a-zA-Z0-9_]*)|(^[_][a-zA-Z0-9_]+)$/", $name)) //matching convention for variable name in Java
return TRUE;
else
return FALSE;
break;
default:
echo "Wrong Input";
return FALSE;
}
}
function create_stringC($funcname,$classname,$noofargs,$arglistC,$return_type)
{
//for C language
$argumentlistC = '';
for($x = $noofargs; $x>=2 ; $x--)
$argumentlistC = ' ,'.$arglistC[$x].$argumentlistC;
$argumentlistC = $arglistC[1].$argumentlistC;
$CCode = $return_type.' '.$funcname.'('.$argumentlistC.')'."{<br>".'//write your code here'."<br><br>".'}';
echo $CCode;
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
}
function create_stringJava($funcname,$classname,$noofargs,$arglistJ,$return_type)
{
//for C language
$argumentlistJ = '';
for($x = $noofargs ; $x>=2 ; $x--)
$argumentlistJ = ' ,'.$arglistJ[$x].$argumentlistJ;
$argumentlistJ = $arglistJ[1].$argumentlistJ;
$JavaCode = 'public class '.$classname.'{'."<br>"." ".'public '.$return_type.' '.$funcname.'('.$argumentlistJ.')'."{<br>".'//write your code here'."<br><br>"." ".'}'."<br>".'}';
echo $JavaCode;
}
?>