def semantic_checks(tree): semdata = SemData() semdata.variable_def = [] semdata.parameters = {} semdata.funcs = {} visit_tree(tree, before_fun, after_fun, semdata) return semdata
def main(): while True: command = input() task = command.split(' ')[0] if (task == "-h" or task == "--help"): print( "usage: main.py [-h] [--who | -f FILE]\n-h, --help show this help message and exit\n --who print out student IDs and NAMEs of authors\n -f FILE, --file FILE filename to process" ) break elif (task == "--who"): print("Evgeniia Onosovskaia, 281251") elif ((task == "-f" or task == "--file") and len(command.split(' ')) == 2): file_name = command.split(' ')[1] ast_tree = tree_generation.parse_result(file_name) semdata = SemData() local_vars = [] semdata.in_function = None # semantics_check.semantic_checks(ast_tree, semdata) # tree_print.treeprint(ast_tree) run_program(ast_tree, semdata, local_vars) else: print("Incorrect command, please try again!")
group.add_argument('--who', action='store_true', help='who wrote this') group.add_argument('-f', '--file', help='filename to process') ns = arg_parser.parse_args() outformat = "unicode" if ns.treetype: outformat = ns.treetype if ns.who == True: # identify who wrote this print('246258 Joonas Jäppinen') print('262767 Pino Surace') elif ns.file is None: # user didn't provide input filename arg_parser.print_help() else: data = codecs.open(ns.file, encoding='utf-8').read() ast_tree = parser.parse(data, lexer=popl_lex.lexer, debug=False) if ns.tree == True: treeprint(ast_tree, outformat) semdata = SemData() check_semantics(ast_tree, semdata) if semdata.errors: print("Semantic errors:") for err in semdata.errors: print(err) else: print("Semantics ok, running:") run_program(ast_tree, semdata)
value1 = node.child_coord2.value[0] value2 = node.child_coord2.value[2] value = [val1, val2, value1, value2] return value else: print("Error, unknown node of type " + nodetype) return None if __name__ == "__main__": import argparse, codecs arg_parser = argparse.ArgumentParser() arg_parser.add_argument('-f', '--file', help='filename to process') ns = arg_parser.parse_args() if ns.file is None: arg_parser.print_help() else: data = codecs.open(ns.file, encoding='utf-8').read() ast_tree = parser.parse(data, lexer=lexer.lexer, debug=False) semdata = SemData() semdata.in_function = None semantics_check.semantic_checks(ast_tree, semdata) tree_print.treeprint(ast_tree) print("Semantics ok.") run_program(ast_tree, semdata) semantics_check.print_symbol_table(semdata, "Symbol table") print("Program finished.")
import tree_generation import tree_print parser = tree_generation.parser if __name__ == "__main__": import argparse, codecs arg_parser = argparse.ArgumentParser() arg_parser.add_argument('-f', '--file', help='filename to process') ns = arg_parser.parse_args() if ns.file is None: arg_parser.print_help() else: data = codecs.open(ns.file, encoding='utf-8').read() ast_tree = parser.parse(data, lexer=tokenizer.lexer, debug=False) ast_tree.children_definitions.reverse() tree_print.treeprint(ast_tree) semdata = SemData() semdata.in_function = None semdata.symtbl = {} create_scope(semdata, "global") semdata.symtbl["global"]["declared"] = set() semdata.symtbl["global"]["functions"] = dict() semantic_checks(ast_tree, semdata) print("Semantics ok:")