Examples of NonTerminal


Examples of beaver.spec.NonTerminal

        lookaheads.add(sym.id);
        return false;
      }
      else
      {
        NonTerminal nt = (NonTerminal) sym;
        lookaheads.add(nt.first_set);
        if (!nt.is_nullable)
          return false;
      }
    }
View Full Code Here

Examples of beaver.spec.NonTerminal

          continue;

        GrammarSymbol sym = conf.getSymbolAfterDot();
        if (sym instanceof NonTerminal)
        {
          NonTerminal nt = (NonTerminal) sym;
          for (Production rule = nt.definitions.start(); rule != null; rule = rule.next_definition)
          {
            Configuration new_conf = conf_set_factory.addConfiguration(rule, 0);
            if (new_conf.addLookaheads(conf))
            {
View Full Code Here

Examples of dk.brics.string.grammar.Nonterminal

        MLFA mlfa = gm.convert();

        propagateTaint(r);

        for (Node n : nodes) {
            Nonterminal nt = f2g.getNonterminal(n);
            MLFAStatePair sp = gm.getMLFAStatePair(nt);
            if (nt.isTaint()) {
                sp.setTaint(true);
            }
        }
        log.debug(mlfa.toString());

        // Make map
        map = new HashMap<ValueBox, MLFAStatePair>();
        for (ValueBox box : hotspots) {
            Node n = m3.get(m2.get(m1.get(box)));
            if (n != null) {
                Nonterminal nt = f2g.getNonterminal(n);
                MLFAStatePair sp = gm.getMLFAStatePair(nt);
                map.put(box, sp);
            }
        }
        tostring_map = new HashMap<SootClass, MLFAStatePair>();
        Map<SootClass, StringStatement> tostring_hotspot_map = jt.getToStringHotspotMap();
        for (Map.Entry<SootClass, StringStatement> tse : tostring_hotspot_map.entrySet()) {
            SootClass tsc = tse.getKey();
            StringStatement ss = tse.getValue();
            Node n = m3.get(m2.get(ss));
            if (n != null) {
                Nonterminal nt = f2g.getNonterminal(n);
                MLFAStatePair sp = gm.getMLFAStatePair(nt);
                tostring_map.put(tsc, sp);
            }
        }
        sourcefile_map = jt.getSourceFileMap();
View Full Code Here

Examples of dk.brics.string.grammar.Nonterminal

     */
    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

Examples of eas.math.fundamentalAlgorithms.graphBased.algorithms.type0grammars.Nonterminal

        if (dia.getDirectory() == null || dia.getFile() == null) {
            env.getSimTime().timeTerminate();
            System.exit(0);
        }
       
        grammar = new Grammar(new File(dia.getDirectory() + File.separator + dia.getFile()), new Nonterminal(new StringBuffer("S")));
       
        env.addAgent(
                new GrammarAgent(
                        env.getFirstFreeID(),
                        env,
View Full Code Here

Examples of eas.math.fundamentalAlgorithms.graphBased.algorithms.type0grammars.Nonterminal

    public static void main(String[] args) {
        eas.math.fundamentalAlgorithms.graphBased.algorithms.type0grammars.Grammar g = new eas.math.fundamentalAlgorithms.graphBased.algorithms.type0grammars.Grammar();
       
        g.addRule(new Rule(
                new Word(new Symbol[] {new Nonterminal(new StringBuffer("S"))}),
                new Word(new Symbol[] {
                        new Nonterminal(new StringBuffer("a")),
                        new Nonterminal(new StringBuffer("S")),
                        new Terminal(new StringBuffer("b"))})));

        g.addRule(new Rule(
                new Word(new Symbol[] {new Nonterminal(new StringBuffer("S"))}),
                new Word(new Symbol[] {
                        new Nonterminal(new StringBuffer("S")),
                        new Terminal(new StringBuffer("S"))})));

        g.addRule(new Rule(
                new Word(new Symbol[] {new Nonterminal(new StringBuffer("S"))}),
                new Word(new Symbol[] {new Terminal(new StringBuffer("a")), new Terminal(new StringBuffer("b"))})));

        CtxtFreeGrammar g2 = new CtxtFreeGrammar(g);
       
        try {
View Full Code Here

Examples of eas.math.fundamentalAlgorithms.graphBased.algorithms.type0grammars.Nonterminal

       
        return "";
    }

    public Grammar generateType3Grammar() {
        Grammar g = new Grammar(new Nonterminal(new StringBuffer(this.initialState)));

        LinkedList<String> reachableStates = new LinkedList<>(this.getAllReachableStates());
       
        Collections.sort(reachableStates);
       
        for (String fromState : reachableStates) {
            for (Transition targetTransition : this.getTransitionsFrom(fromState)) {
                String toState = targetTransition.getDestination();
                String symbol = targetTransition.getLabel();
               
                g.addRule(new Rule(
                        new Word(new Symbol[] {new Nonterminal(new StringBuffer(fromState))}),
                        new Word(new Symbol[] {
                                new Terminal(new StringBuffer(symbol)),
                                new Nonterminal(new StringBuffer(toState))})));
            }
           
            if (this.finalStates.contains(fromState)) {
                g.addRule(new Rule(
                        new Word(new Symbol[] {new Nonterminal(new StringBuffer(fromState))}),
                        new Word(new Symbol[] {})));
            }
        }
       
        return g;
View Full Code Here

Examples of net.sourceforge.chaperon.model.symbol.Nonterminal

    assertNotEquals("Test if symbols are not equal", a2, b);
    assertEquals("Test if hashcodes are equals", a.hashCode(), a2.hashCode());
    assertTrue("Test if hashcodes are no equal", a2.hashCode()!=b.hashCode());

    // Test for nonterminals
    Nonterminal A = new Nonterminal("A");
    Nonterminal B = new Nonterminal("B");

    assertEquals("Test if symbol names are equal", "A", A.getName());
    assertEquals("Test if symbol names are equal", "B", B.getName());

    assertEquals("Test if symbols are equal", A, A);
    assertNotEquals("Test if symbols are not equal", A, B);
    assertEquals("Test if hashcodes are equals", A.hashCode(), A.hashCode());

    Nonterminal A2 = new Nonterminal("A");

    assertEquals("Test if symbols are equal", A, A2);
    assertNotEquals("Test if symbols are not equal", A2, B);
    assertEquals("Test if hashcodes are equal", A.hashCode(), A2.hashCode());
    assertTrue("Test if hashcodes are no equal", A2.hashCode()!=B.hashCode());

    // Test for emptylist symbols
    EmptyList emptylist = new EmptyList();
    EmptyList emptylist2 = new EmptyList();

    assertEquals("Test if symbols are equal", emptylist, emptylist);
    assertEquals("Test if symbols are equal", emptylist, emptylist2);

    // Composite tests
    Terminal a3 = new Terminal("A");
    Nonterminal A3 = new Nonterminal("a");

    assertNotEquals("Test if symbols are not equal", a3, A);
    assertNotEquals("Test if symbols are not equal", a, A3);
    assertNotEquals("Test if symbols are not equal", a, emptylist);
    assertNotEquals("Test if symbols are not equal", A, emptylist);
    assertTrue("Test if hashcodes are no equal", a.hashCode()!=emptylist.hashCode());
    assertTrue("Test if hashcodes are no equal", A.hashCode()!=emptylist.hashCode());

    try
    {
      Terminal a4 = new Terminal(null);
      fail("Test if exception occurs");
    }
    catch (Exception e) {}

    try
    {
      Nonterminal A4 = new Nonterminal(null);
      fail("Test if exception occurs");
    }
    catch (Exception e) {}

    try
    {
      Terminal a4 = new Terminal("");
      fail("Test if exception occurs");
    }
    catch (Exception e) {}

    try
    {
      Nonterminal A4 = new Nonterminal("");
      fail("Test if exception occurs");
    }
    catch (Exception e) {}
  }
View Full Code Here

Examples of net.sourceforge.chaperon.model.symbol.Nonterminal

        state = STATE_ERROR;
      }
      else if ((localName.equals(STARTSYMBOL_ELEMENT)) && (state==STATE_GRAMMAR))
      {
        stack.push(new Nonterminal(atts.getValue(SYMBOL_ATTRIBUTE)));

        state = STATE_START;
      }
      else if ((localName.equals(ASSOCIATIVITY_ELEMENT)) && (state==STATE_GRAMMAR))
      {
View Full Code Here

Examples of net.sourceforge.chaperon.model.symbol.Nonterminal

        state = STATE_PRODUCTION;
      }
      else if ((localName.equals(STARTSYMBOL_ELEMENT)) && (state==STATE_START))
      {
        Nonterminal ssymbol = (Nonterminal)stack.pop();
        Grammar grammar = (Grammar)stack.peek();

        grammar.setStartSymbol(ssymbol);

        state = STATE_GRAMMAR;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.