Package net.sourceforge.chaperon.model.symbol

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


        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

        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

    return terminal;
  }

  private Nonterminal getNonterminal(Hashtable nonterminals, String name)
  {
    Nonterminal nonterminal = (Nonterminal)nonterminals.get(name);
    if (nonterminal==null)
    {
      nonterminal = new Nonterminal(name);
      nonterminals.put(name, nonterminal);
    }

    return nonterminal;
  }
View Full Code Here

    mult = new Terminal("*");
    bopen = new Terminal("(");
    bclose = new Terminal(")");
    id = new Terminal("id");

    E = new Nonterminal("E");
    T = new Nonterminal("T");
    F = new Nonterminal("F");

    grammar = new Grammar();

    // E -> E + T
    Production production = new Production(E);
View Full Code Here

    mult = new Terminal("mult");
    bopen = new Terminal("bopen");
    bclose = new Terminal("bclose");
    id = new Terminal("id");

    E = new Nonterminal("E");
    Eprime = new Nonterminal("E'");
    T = new Nonterminal("T");
    Tprime = new Nonterminal("T'");
    F = new Nonterminal("F");

    grammar = new Grammar();

    grammar.setStartSymbol(E);
View Full Code Here

  {
    a = new Terminal("a");
    b = new Terminal("b");
    c = new Terminal("c");

    A = new Nonterminal("A");
    B = new Nonterminal("B");
    C = new Nonterminal("C");
  }
View Full Code Here

  public void setUp()
  {
    a = new Terminal("a");
    b = new Terminal("b");
    E = new Nonterminal("E");
    F = new Nonterminal("F");
    G = new Nonterminal("G");

    grammar = new Grammar();

    p1 = new Production(F);
    p1.getDefinition().addSymbol(E);
View Full Code Here

  {
    a = new Terminal("a");
    b = new Terminal("b");
    c = new Terminal("c");

    A = new Nonterminal("A");
    B = new Nonterminal("B");
    C = new Nonterminal("C");
  }
View Full Code Here

    c = new Terminal("c");
    d = new Terminal("d");

    eof = new EndOfFile();

    S = new Nonterminal("S");
    C = new Nonterminal("C");

    grammar = new Grammar();

    Production production = new Production(S);
    production.getDefinition().addSymbol(C);
View Full Code Here

TOP

Related Classes of net.sourceforge.chaperon.model.symbol.Nonterminal

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.