-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin_out.py
More file actions
executable file
·138 lines (113 loc) · 3.32 KB
/
in_out.py
File metadata and controls
executable file
·138 lines (113 loc) · 3.32 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
from functions import *
import re
import os
def vaild_next_char(i,n):
if(i == n-1):
return 0
else:
return 1
def classify(list_of_okens):
return type
def get_tokens(line):
state="start"
tokens = []
token=""
i=0
char=line[i]
no_valid_token = 0
while(1):
if(state=="start"):
if (char==' '):
i=i+1
char = line[i]
continue
if isLetter(char):
state="letter"
elif isNumber(char):
state = "number"
elif isSpecial(char):
state = "special"
elif char=='{':
state = "comment"
else:
no_valid_token = 1
if state =="letter":
while isLetter(char) or isNumber(char):
token += char
if (vaild_next_char(i, len(line))):
i = i + 1
char = line[i]
#no_valid_token = 0
else:
no_valid_token=1
break
state = "acceptance"
if state == "number":
while isNumber(char):
token += char
if (vaild_next_char(i, len(line))):
i = i + 1
char = line[i]
#no_valid_token = 0
else:
no_valid_token=1
break
state = "acceptance"
if state == "special":
if char==':' :
while isSpecial(char):
token += char
if (vaild_next_char(i, len(line))):
i = i + 1
char = line[i]
#no_valid_token = 0
else:
no_valid_token = 1
break
state = "acceptance"
else :
token += char
if (vaild_next_char(i, len(line))):
i = i + 1
char = line[i]
else:
no_valid_token = 1
break
state = "acceptance"
if state == "comment":
while (char != '}'):
if (vaild_next_char(i, len(line))):
i = i + 1
char = line[i]
else:
no_valid_token=1
break
state = "start"
if (vaild_next_char(i, len(line))):
i = i + 1
char = line[i]
if (state=="acceptance"):
state = "start"
tokens.append(token)
token=""
if ( no_valid_token and(not (vaild_next_char(i, len(line))))):
break
return tokens
def read_lines(filename):
tokens=[]
in_file = open(filename, "r")
lines = in_file.readlines()
for line in lines:
tokens+= get_tokens(line)
in_file.close()
return tokens
def main():
list = read_lines('testCase.txt')
text_file = open("Output.txt", "w")
for item in list:
print(item)
text_file.write(item)
text_file.write("\n")
text_file.close()
if __name__ == "__main__":
main()