-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
169 lines (120 loc) · 6.29 KB
/
Copy pathapp.py
File metadata and controls
169 lines (120 loc) · 6.29 KB
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
import re
with open('correct.java', 'w') as outf:
with open('input.java') as fref:
lines = fref.readlines()
sflag = 0
eflag = 0
count = 0
for line in lines:
flag = 0
count += 1
line2 = line.rstrip()
if line2 == '':
if len(lines) == count:
pass
else:
continue
if re.match('import [_a-zA-Z]+[._a-zA-Z*]+',line):
print('Java library or API included')
flag = 1
outf.write(line)
if re.match('class [a-zA-Z][a-zA-Z_0-9]+{',line):
print('Beginning of class declarations')
outf.write(line)
flag = 1
sflag = 1
line = line.strip()
if(sflag == 0):
print('***************ERROR : at line {}'.format(count))
print('***************Class declaration not begun correctly')
outf.write('class autoCreate {\n')
sflag = 1
if re.search('public',line):
print('***************ERROR : at line {}'.format(count))
print('***************Error: Variables Inside Class Must Be Private***',end=" ")
outf.write('private ')
elif re.search('private',line):
print('Private Acess Specified',end=" ")
outf.write('private ')
elif re.search('protected',line):
print('***************ERROR : at line {}'.format(count))
print('***************Error: Variables Inside Class Must Be Private***',end=" ")
outf.write('private ')
if re.search('static',line):
print('Static Declaration',end=" ")
outf.write('static ')
if re.search('final',line):
print('Constant Declaration',end=" ")
outf.write('final ')
line = line.replace('private','')
line = line.replace('public','')
line = line.replace('protected','')
line = line.replace('final','')
line = line.replace('static','')
line = line.strip()
if re.match('int [a-zA-Z_][a-zA-Z_0-9]*;',line):
print('Integer Variable Declared')
outf.write(re.match('int [a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('int ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line):
print('Multiple Integer Variables Declared')
outf.write(re.match('int ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('int [a-zA-Z_][a-zA-Z_0-9]*\[\];',line):
print('Integer Array Declared')
outf.write(re.match('int [a-zA-Z_][a-zA-Z_0-9]*\[\];',line).group(0) + '\n')
flag = 1
if re.match('float [a-zA-Z_][a-zA-Z_0-9]*;',line):
print('Floating Point Variable Declared')
outf.write(re.match('float [a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('float ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line):
print('Multiple Floating Point Variables Declared')
outf.write(re.match('float ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('float [a-zA-Z_][a-zA-Z_0-9]*\[\];',line):
print('Floating Point Array Declared')
outf.write(re.match('float [a-zA-Z_][a-zA-Z_0-9]*\[\];',line).group(0) + '\n')
flag = 1
if re.match('String [a-zA-Z_][a-zA-Z_0-9]*;',line):
print('String Variable Declared')
outf.write(re.match('String [a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('String ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line):
print('String Variables Declared')
outf.write(re.match('String ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('String [a-zA-Z_][a-zA-Z_0-9]*\[\];',line):
print('String Array Declared')
outf.write(re.match('String [a-zA-Z_][a-zA-Z_0-9]*\[\];',line).group(0) + '\n')
flag = 1
if re.match('char [a-zA-Z_][a-zA-Z_0-9]*;',line):
print('Character Variable Declared')
outf.write(re.match('char [a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('char ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line):
print('Multiple Character Variables Declared')
outf.write(re.match('char ([a-zA-Z_][a-zA-Z_0-9]*,)+[a-zA-Z_][a-zA-Z_0-9]*;',line).group(0) + '\n')
flag = 1
if re.match('char [a-zA-Z_][a-zA-Z_0-9]*\[\];',line):
print('Character Arary Declared')
outf.write(re.match('char [a-zA-Z_][a-zA-Z_0-9]*\[\];',line).group(0) + '\n')
flag = 1
if re.match('}', line):
print('End of class declaration')
outf.write(re.match('}', line).group(0) + '\n')
flag = 1
eflag = 1
break
if flag == 0 and len(lines) != count:
print('***************ERROR : at line {}'.format(count))
print('***************Semicolon missing')
key_list = ['public', 'private', 'static', 'protected', 'final']
for item in key_list:
line.replace(item,'')
outf.write(line + ';\n')
if len(lines) == count and eflag == 0:
print('***************ERROR')
print('***************Class declaration not closed')
outf.write('}\n')
break