Package net.sourceforge.chaperon.model.symbol

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


    super(name);
  }

  public void setUp()
  {
    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


   *
   * @throws Exception If a exception occurs.
   */
  private void processLexeme(String symbolname, String text)
  {
    Terminal symbol = new Terminal(symbolname);

    System.out.println("\n===================================\nProcess "+symbolname);

    if (current.isEmpty())
      throw new IllegalStateException("Parsing process is aborted");
View Full Code Here

  }

  public void runTest() throws Throwable
  {
    // Test for terminals
    Terminal a = new Terminal("a");
    Terminal b = new Terminal("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());

    Terminal a2 = new Terminal("a");

    assertEquals("Test if symbols are equal", a, a2);
    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
View Full Code Here

          new Production(getNonterminal(nonterminals, atts.getValue(SYMBOL_ATTRIBUTE)));
        production.setLocation(getLocation());

        String precedencesymbol = atts.getValue(PRECEDENCE_ATTRIBUTE);
        if ((precedencesymbol!=null) && (precedencesymbol.length()>0))
          production.setPrecedence(new Terminal(precedencesymbol));

        stack.push(production);

        state = STATE_PRODUCTION;
      }
      else if ((localName.equals(NONTERMINALSYMBOL_ELEMENT)) && (state==STATE_PRODUCTION))
      {
        stack.push(getNonterminal(nonterminals, atts.getValue(SYMBOL_ATTRIBUTE)));

        state = STATE_NONTERMINAL;
      }
      else if ((localName.equals(TERMINALSYMBOL_ELEMENT)) && (state==STATE_PRODUCTION))
      {
        stack.push(new Terminal(atts.getValue(SYMBOL_ATTRIBUTE)));

        state = STATE_TERMINAL;
      }
      else if ((localName.equals(ERRORSYMBOL_ELEMENT)) && (state==STATE_PRODUCTION))
      {
View Full Code Here

      throw new SAXException("Unexpected element "+qName+" at "+getLocation());
  }

  private Terminal getTerminal(Hashtable terminals, String name)
  {
    Terminal terminal = (Terminal)terminals.get(name);
    if (terminal==null)
    {
      terminal = new Terminal(name);
      terminals.put(name, terminal);
    }

    return terminal;
  }
View Full Code Here

    super(name);
  }

  public void setUp()
  {
    plus = new Terminal("+");
    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");

View Full Code Here

  public void setUp()
  {
    emptylist = new EmptyList();
    eof = new EndOfFile();

    plus = new Terminal("plus");
    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'");
View Full Code Here

    super("SymbolListTestCase");
  }

  public void setUp()
  {
    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

    super(name);
  }

  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();
View Full Code Here

      else if ((localName.equals(LEXEME_ELEMENT)) && (state==STATE_LEXICON))
      {
        Lexeme lexeme = new Lexeme();
        lexeme.setLocation(getLocation());
        if (atts.getValue(SYMBOL_ATTRIBUTE)!=null)
          lexeme.setSymbol(new Terminal(atts.getValue(SYMBOL_ATTRIBUTE)));

        stack.push(lexeme);

        state = STATE_LEXEME;
      }
View Full Code Here

TOP

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

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.