-
Notifications
You must be signed in to change notification settings - Fork 0
/
minetime.py
executable file
·41 lines (36 loc) · 949 Bytes
/
minetime.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
#!/usr/bin/env python
import yaccing as yacc
import sys
from lexing import Mtlex
from traverse import *
from preprocess import *
def main(argv):
inputfile = argv[1]
filename = inputfile.split(".")[0]
source = open(inputfile).read()
# generate the parser
parser = yacc.getyacc()
# generate the Lexer to be used with parser
m = Mtlex()
m.build()
# preprocessing step
preprocessor = Processor()
source = preprocessor.preprocess(source)
tree = parser.parse(source, lexer=m.lexer)
firstline = '''import logging
import os
import sys
from pymclevel import mclevel
from pymclevel.box import BoundingBox
'''
lastline = '''
if __name__ == '__main__':
main()
'''
result = Traverse(tree).getpython()
code = firstline + "\n" + result + "\n" + lastline + "\n"
outputfile = filename + ".py"
output = open(outputfile, 'w')
output.write(code)
if __name__ == '__main__':
main(sys.argv)