-
Notifications
You must be signed in to change notification settings - Fork 0
/
myproj.py
114 lines (86 loc) · 1.8 KB
/
myproj.py
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
import ply.lex as lex
tokens = (
'STRING',
'newline',
'tab',
'space',
'arrayeach',
'puts',
'tag',
'endingtag',
'identifier',
'number',
'EQUAL',
'operator',
'leftbrace',
'rightbrace',
'COMMA'
)
t_ignore = ' \t\v\r\n' # shortcut for whitespace
def t_STRING(t):
r'"[^"]*"'
t.value = t.value[1:-1] # drop "surrounding quotes"
return t
def t_newline(t):
r'\n'
return t
def t_tab(t):
r'\s\s\s\s'
return t
def t_space(t):
r'\s'
return t
def t_arrayeach(t):
r'[A-Za-z][A-Za-z_]*\.each'
return t
def t_puts(t):
r'puts'
return t
def t_tag(t):
r'do'
return t
def t_endingtag(t):
r'end'
return t
def t_identifier(t):
r'[A-Za-z][A-Za-z_]*'
return t
def t_number(t):
r'[0-9]+'
return t
def t_EQUAL(t):
r'='
return t
def t_operator(t):
r'[<|>*/|==|=|!=|+|-]'
return t
def t_leftbrace(t):
r'\['
return t
def t_rightbrace(t):
r'\]'
return t
def t_COMMA(t):
r','
return t
# def t_WORD(t):
# r'[^ <>\n]+'
# return t
def t_error(t):
pass
def fileread():
with open('iterator.txt', 'r') as f:
read_data = f.read()
f.closed
return read_data
def main():
data=fileread()
print data
iteratorlex = lex.lex()
iteratorlex.input(data)
while True:
tok = iteratorlex.token()
if not tok: break
print tok
if __name__ == "__main__":
main()