-
Notifications
You must be signed in to change notification settings - Fork 0
/
EBIGU.py
53 lines (46 loc) · 1.65 KB
/
EBIGU.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
import sys
import traceback
from translatorche import translate
from parserche import parse
# TODO print doesn't work when you have initiated pygame in EBIGU (and you don't have errors)...
# Importing some modules so that when the interpreter is compiled to exe
# they are packed as well
import pygame
import pygame.locals
import random
import os
import re
if __name__ == '__main__':
# Spit an error if no EBIGU scrupt is supplied
if len(sys.argv) < 2:
print('Please suppy an EBIGU script to interpret!')
input()
else:
# Opening the file from the argument supplied
with open(sys.argv[1], 'r') as f:
# Save the source code as string
source = f.read()
# Parse the source code
source, funcs_found = parse(source)
# Translate the source code
source = translate(source)
if len(sys.argv) > 2:
# Write the python code to file if such file is specified
with open(sys.argv[2], 'w') as f:
f.write(source)
os._exit(1)
else:
# Execute the result
try:
exec(source)
except:
print('------------ FUNCS FOUND --------------')
print(funcs_found)
print('------------ TRANSLATION --------------')
source_lines = source.splitlines()
for line in range(len(source_lines)):
print(f'{line + 1}: {source_lines[line]}')
print('------------ END --------------')
print(traceback.format_exc())
# Keep console open if no pygame or error
input()