kvs/kvs_build.py
2026-05-02 23:04:46 +03:00

52 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Главный сборочный скрипт КВС
Последовательно запускает все этапы компиляции
"""
import sys
import subprocess
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Использование: python kvs_build.py <файл.квс>")
sys.exit(1)
source_file = sys.argv[1]
if not source_file.endswith('.квс'):
print("Ошибка: файл должен иметь расширение .квс")
sys.exit(1)
base_name = source_file[:-4]
tokens_file = base_name + ".токены"
ast_file = base_name + ".аст"
pass1_file = base_name + ".проход1"
csv_file = base_name + ".csv"
elf_file = base_name + ".elf"
stages = [
("kvs_lexer.py", [source_file, tokens_file], "Лексический анализ"),
("kvs_parser.py", [tokens_file, ast_file], "Парсинг"),
("kvs_pass1.py", [ast_file, pass1_file], "Первый проход"),
("kvs_pass2.py", [ast_file, pass1_file, csv_file], "Второй проход и генерация CSV"),
("kvs_builder.py", [csv_file, pass1_file, elf_file], "Сборка ELF"),
]
for script, args, description in stages:
print(f"\n=== {description} ===")
cmd = [sys.executable, script] + args
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print(f"ОШИБКА на этапе '{description}':")
print(result.stderr)
sys.exit(1)
print(result.stdout)
print(f"\n=== Компиляция успешно завершена ===")
print(f"Исполняемый файл: {elf_file}")
print(f"Запустить: ./{elf_file}")