コード例 #1
0
    def parse(self, expression):

        self.expression = expression
        syntactic = Syntax(self.expression)

        # try:
        self.ast = syntactic.parse()

        # except ValueError:
        # print("erro!")

        # try:
        return self.evaluate(self.ast)
コード例 #2
0
    if args.source:
        abs_file_path = os.path.join(script_dir, args.source)

        with open(abs_file_path) as src:
            source_code = src.read()

    elif args.cmd:
        source_code = args.cmd

    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')

        lexer = Lexer(source_code)
        syntax = Syntax(lexer)

        parse_tree = syntax.parse()

        print(1, parse_tree.declarator)
        print(2, parse_tree.declarator.identifier)
        print(3, parse_tree.next)
        print(parse_tree.next.next)
        print(parse_tree.next.next.next)
        # for node in parse_tree:
        #     print(node)

        Node.proccess_traversal_semantics(parse_tree)
        Node.symtable.show()

        for error in w:
            print(f'{error.category.__name__}: {error.message}')