-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFirst.py
More file actions
51 lines (40 loc) · 1.16 KB
/
Copy pathFirst.py
File metadata and controls
51 lines (40 loc) · 1.16 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
keywords=["if", "while", "for", "int", "char", "string"]
operators=["=", "+", "-", "%", "/", "*"]
delimiters=[";", ",", " ", "(", ")", "=", "+", "-", "%", "/", "*", ">", "<", ">=", "==", "<=" ]
Keywordtoken=[]
IdentifierToken=[]
OperatorToken=[]
DelimiterToken=[]
str = input("Enter string")
first = 0
last = 0
TokenVar = 0
for i in range(0, len(str), 1):
if str[i] in delimiters:
if str[i] in operators:
'''Do Nothing'''
else:
DelimiterToken.append(str[i])
print("Encounterd", str[i])
last = i
print(str[first:last])
if str[first:last] in keywords:
if str[first:last] in Keywordtoken:
'''Do nothing'''
first=i+1
else:
Keywordtoken. append(str[first:last])
first = i + 1
else:
if str[first:last].isdigit():
'''Do nothing'''
first=i+len(str[first:last])
else:
IdentifierToken.append(str[first:last])
first = i + 1
if str[i] in operators:
OperatorToken.append(str[i])
print(OperatorToken)
print(Keywordtoken)
print(IdentifierToken)
print(DelimiterToken)