interpeter.py (2793B)
1 # Author : Amit Dutta <amitdutta4255@gmail.com> 2 # Date : 06 Feb 2026 3 # Repo : https://github.com/notamitgamer/bsc 4 # License : MIT License (See the LICENSE file for details) 5 # Copyright (c) 2026 Amit Dutta 6 7 import sys 8 import os 9 import subprocess 10 import re 11 12 # Set the absolute path to your GCC compiler based on your system logs 13 COMPILER_PATH = r"G:\bsc\MinGW64\bin\gcc.exe" 14 15 def run_universal_compiler(): 16 if len(sys.argv) < 2: 17 print("Usage: python emojic.py <file.c>") 18 sys.exit(1) 19 20 source_path = sys.argv[1] 21 if not os.path.exists(source_path): 22 print(f"File not found: {source_path}") 23 sys.exit(1) 24 25 with open(source_path, 'r', encoding='utf-8') as f: 26 content = f.read() 27 28 mapping = {} 29 # Extract emoji mappings from #define statements 30 define_pattern = re.compile(r'#define\s+(\S+)\s+(.+)') 31 32 lines = content.splitlines() 33 code_lines = [] 34 35 for line in lines: 36 match = define_pattern.match(line.strip()) 37 if match: 38 emoji_key = match.group(1) 39 c_value = match.group(2).strip() 40 mapping[emoji_key] = c_value 41 else: 42 code_lines.append(line) 43 44 translated_code = "\n".join(code_lines) 45 46 # Sort keys by length descending to replace multi-emoji tokens correctly 47 sorted_keys = sorted(mapping.keys(), key=len, reverse=True) 48 49 for key in sorted_keys: 50 translated_code = translated_code.replace(key, mapping[key]) 51 52 # Ensure standard header is present if logic needs it 53 header = "#include <stdio.h>\n" 54 if "#include" not in translated_code: 55 translated_code = header + translated_code 56 57 temp_file = "output_target.c" 58 with open(temp_file, "w", encoding="utf-8") as f: 59 f.write(translated_code) 60 61 exe_name = source_path.rsplit('.', 1)[0] + ".exe" 62 compile_cmd = [COMPILER_PATH, temp_file, "-o", exe_name] 63 64 try: 65 # Use shell=True for better command resolution on Windows 66 result = subprocess.run(compile_cmd, capture_output=True, text=True, shell=(os.name == 'nt')) 67 68 if result.returncode == 0: 69 print(f"Compilation Successful: {exe_name}") 70 run_cmd = [f".\\{exe_name}"] if os.name == 'nt' else [f"./{exe_name}"] 71 subprocess.run(run_cmd, shell=(os.name == 'nt')) 72 else: 73 print("Compilation Error:") 74 print(result.stderr) 75 76 except FileNotFoundError: 77 print(f"Error: Compiler '{COMPILER_PATH}' not found.") 78 print("Please ensure GCC is installed and added to your PATH,") 79 print("or edit COMPILER_PATH in this script to point to your gcc.exe.") 80 81 if os.path.exists(temp_file): 82 os.remove(temp_file) 83 84 if __name__ == "__main__": 85 run_universal_compiler()