-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreplace.py
28 lines (28 loc) · 994 Bytes
/
replace.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
import re
import fileinput
i = 0
# for line in fileinput.input('mylexer.l', inplace=True):
for line in fileinput.input('myparser.y', inplace=True):
# for line in [
# 'ellipsis {yylval.ntnode = new node("ELLIPSIS"); return ELLIPSIS;}'
# ]:
try:
v = re.search(r'//printf("\d+ ")', '$$ = new node();')
# v = re.search(r'\$\$ = new node\(\);', '$$ = new node();')
# v = re.search('return (\w+);', line).group(1)
# re.sub(r'reserve\(([A-Z]+)', 'reserve\(' + v, line)
i += 1
print(
re.sub(r'//printf("\d+ ")',
'', line),
end='')
# print(
# re.sub(r'\$\$ = new node\(\);',
# f'$$ = new node();\n\t\tprintf("{i} ");', line),
# end='')
# print(
# re.sub('return \w+;', 'printf("' + v + '");\treturn ' + v + ';',
# line),
# end='')
except AttributeError:
print(line, end='')