Package dk.brics.string.grammar

Examples of dk.brics.string.grammar.Grammar


        if (log.isDebugEnabled()) {
            log.debug(g.toDot(nodes));
        }
        log.info("Transforming into grammar...");
        FlowGraph2Grammar f2g = new FlowGraph2Grammar(g);
        Grammar r = f2g.convert();
        Set<Nonterminal> hs_nt = new HashSet<Nonterminal>();
        for (Node hn : nodes) {
            hs_nt.add(f2g.getNonterminal(hn));
        }
        if (log.isDebugEnabled()) {
            log.debug(r.toString() + "Hotspots: " + hs_nt);
        }

        // Approximate grammar
        log.info("Cutting operation cycles...");
        r.approximateOperationCycles();
        log.info("Performing regular approximation...");
        r.approximateNonLinear(hs_nt);
        if (log.isDebugEnabled()) {
            log.debug(r.toString() + "Hotspots: " + hs_nt);
        }
        log.info("Converting to MLFA...");

        Grammar2MLFA gm = new Grammar2MLFA(r);
        MLFA mlfa = gm.convert();
View Full Code Here


     * Constructs grammar for the flow graph.
     *
     * @see #getNonterminal(Node)
     */
    public Grammar convert() {
        final Grammar r = new Grammar();
        node2nt = new ArrayList<Nonterminal>();
        for (Node node : g.getNodes()) {
            Nonterminal n = r.addNonterminal();
            n.setTaint(node.isTaint());
            node2nt.add(n);
        }
        g.visitNodes(new NodeVisitor() {

            public void visitAssignmentNode(AssignmentNode n) {
                for (Node m : n.getArg().getDefs()) {
                    r.addUnitProduction(getNonterminal(n), getNonterminal(m));
                }
            }

            public void visitConcatenationNode(ConcatenationNode n) {
                for (Node m1 : n.getArg1().getDefs()) {
                    for (Node m2 : n.getArg2().getDefs()) {
                        r.addPairProduction(getNonterminal(n), getNonterminal(m1), getNonterminal(m2));
                    }
                }
            }

            public void visitInitializationNode(InitializationNode n) {
                r.addAutomatonProduction(getNonterminal(n), n.getReg());
            }

            public void visitUnaryNode(UnaryNode n) {
                for (Node m : n.getArg().getDefs()) {
                    r.addUnaryProduction(getNonterminal(n), n.getOp(), getNonterminal(m));
                }
            }

            public void visitBinaryNode(BinaryNode n) {
                for (Node m1 : n.getArg1().getDefs()) {
                    for (Node m2 : n.getArg2().getDefs()) {
                        r.addBinaryProduction(getNonterminal(n), n.getOp(), getNonterminal(m1), getNonterminal(m2));
                    }
                }
            }
        });
        return r;
View Full Code Here

TOP

Related Classes of dk.brics.string.grammar.Grammar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.