Exemplo n.º 1
0
            parse, operations = parser(tokens, get_shift_reduce=True)

            if show_parsing:
                st.markdown('### Parsing')
                st.write([str(prod) + '\n' for prod in reversed(parse)])

            ast = evaluate_reverse_parse(parse, operations, tokens)
        except ParsingException as syntax_error:
            ast = None
            st.error(f"{syntax_error}")

        if ast is not None:
            formatter = FormatVisitor()
            errors = []
            context = Context()
            scope = Scope()

            collector = TypeCollector(context, errors)
            collector.visit(ast)
            builder = TypeBuilder(context, errors)
            builder.visit(ast)

            if show_ast:
                st.markdown('### Abstract Syntax Tree')
                st.text(formatter.visit(ast, 1))
            if show_context:
                st.markdown('### Context')
                st.text(builder.context)

            # Types Inference
            #######################################################
Exemplo n.º 2
0
 def visit(self, node: cool_ast.ProgramNode, scope: Scope = None):
     if scope is None:
         scope = Scope()
     for declaration in node.declarations:
         self.visit(declaration, scope.create_child())
     return scope