2023-10-24 12:40:15 -07:00
|
|
|
#! /usr/bin/python
|
2023-10-12 22:46:37 -07:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2023-10-13 00:15:31 -07:00
|
|
|
from codegen_message import *
|
|
|
|
from parser import *
|
2023-10-12 22:46:37 -07:00
|
|
|
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
sys.exit("Takes name of file.")
|
|
|
|
|
|
|
|
filename = sys.argv[1]
|
|
|
|
|
2023-10-13 15:04:25 -07:00
|
|
|
ast = None
|
2023-10-12 22:46:37 -07:00
|
|
|
with open(filename, mode='r') as f:
|
|
|
|
filedata = f.read()
|
|
|
|
lexemes = lexer(filedata)
|
|
|
|
|
|
|
|
parser = Parser(lexemes)
|
2023-10-12 23:14:25 -07:00
|
|
|
ast = parser.parse()
|
|
|
|
type_check(ast)
|
2023-10-13 00:15:31 -07:00
|
|
|
|
2023-10-13 15:04:25 -07:00
|
|
|
|
|
|
|
with open(filename + '.h', mode='w') as f:
|
|
|
|
f.write(generate_message_header(ast))
|
|
|
|
with open(filename + '.cpp', mode='w') as f:
|
|
|
|
f.write(generate_message_impl(filename, ast))
|
2023-10-12 22:46:37 -07:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|