Package net.sourceforge.chaperon.grammar

Examples of net.sourceforge.chaperon.grammar.Grammar


    try
    {

      if (localName.equals(GRAMMAR_ELEMENT))
      {
        grammar = new Grammar();
        grammar.setURI(atts.getValue(URI_ATTRIBUTE));
        stack.push(grammar);
      }
      else if (localName.equals(TOKENLIST_ELEMENT))
      {
View Full Code Here


        grammar = (Grammar) stack.pop();
      }
      else if (localName.equals(TOKENLIST_ELEMENT))
      {
        TokenList tokens = (TokenList) stack.pop();
        Grammar grammar = (Grammar) stack.peek();

        grammar.getTokenList().addToken(tokens);
      }
      else if (localName.equals(IGNORABLETOKENLIST_ELEMENT))
      {
        TokenList tokens = (TokenList) stack.pop();
        Grammar grammar = (Grammar) stack.peek();

        grammar.getIgnorableTokenList().addToken(tokens);
      }
      else if (localName.equals(TOKEN_ELEMENT))
      {
        Token token = (Token) stack.pop();
        TokenList tokens = (TokenList) stack.peek();

        tokens.addToken(token);
      }
      else if ((localName.equals(ALTERNATION_ELEMENT))
               || (localName.equals(CONCATENATION_ELEMENT))
               || (localName.equals(CHARACTERSEQUENCE_ELEMENT))
               || (localName.equals(CHARACTERCLASS_ELEMENT))
               || (localName.equals(UNIVERSALCHARACTER_ELEMENT))
               || (localName.equals(BEGINOFLINE_ELEMENT))
               || (localName.equals(ENDOFLINE_ELEMENT))
               || (localName.equals("ncc")))
      {
        DefinitionElement definitionelement = (DefinitionElement) stack.pop();

        if (stack.peek() instanceof Alternation)
        {
          Alternation alternation = (Alternation) stack.peek();

          alternation.addDefinitionElement(definitionelement);
        }
        else if (stack.peek() instanceof Concatenation)
        {
          Concatenation concatenation = (Concatenation) stack.peek();

          concatenation.addDefinitionElement(definitionelement);
        }
        else if (stack.peek() instanceof Token)
        {
          Token token = (Token) stack.peek();

          token.setDefinition(definitionelement);
        }
      }
      else if ((localName.equals(CHARACTERSET_ELEMENT))
               || (localName.equals(CHARACTERINTERVAL_ELEMENT)))
      {
        CharacterClassElement characterclasselement = (CharacterClassElement) stack.pop();
        CharacterClass characterclass = (CharacterClass) stack.peek();

        characterclass.addCharacterClassElement(characterclasselement);

      }
      /*else if (localName.equals(COMMENT_ELEMENT))
      {
        Comment comment = (Comment) stack.pop();
        Grammar grammar = (Grammar) stack.peek();

        grammar.setComment(comment);
      }
      else if (localName.equals(WHITESPACE_ELEMENT))
      {
        Whitespace whitespace = (Whitespace) stack.pop();
        Grammar grammar = (Grammar) stack.peek();

        grammar.setWhitespace(whitespace);
      }*/
      else if (localName.equals(PRODUCTIONLIST_ELEMENT))
      {
        ProductionList productions = (ProductionList) stack.pop();
        Grammar grammar = (Grammar) stack.peek();

        grammar.getProductionList().addProduction(productions);
      }
      else if (localName.equals(PRODUCTION_ELEMENT))
      {
        Production production = (Production) stack.pop();
        ProductionList productions = (ProductionList) stack.peek();

        productions.addProduction(production);
      }
      else if (localName.equals(NONTERMINALSYMBOL_ELEMENT))
      {
        Symbol ntsymbol = (Symbol) stack.pop();
        Production production = (Production) stack.peek();

        production.getDefinition().addSymbol(ntsymbol);
      }
      else if (localName.equals(TERMINALSYMBOL_ELEMENT))
      {
        Symbol tsymbol = (Symbol) stack.pop();
        Production production = (Production) stack.peek();

        production.getDefinition().addSymbol(tsymbol);
      }
      else if (localName.equals(STARTSYMBOL_ELEMENT))
      {
        NonTerminalSymbol ssymbol = (NonTerminalSymbol) stack.pop();
        Grammar grammar = (Grammar) stack.peek();

        grammar.setStartSymbol(ssymbol);
      }
      else
        System.out.println(localName + " would not process");

    }
View Full Code Here

        getLogger().debug("(Re)building the parsertable from '"+_grammarSource.getSystemId()+"'");

        SAXGrammarGenerator grammargenerator = new SAXGrammarGenerator();
        SourceUtil.toSAX(_grammarSource, grammargenerator, this.manager);

        Grammar grammar = grammargenerator.getGrammar();
        SyntaxErrorException see = grammar.validate();
        if (see!=null)
        {
          getLogger().error("Grammar is not correct", see);
          throw new ProcessingException("Grammar is not correct", see);
        }
View Full Code Here

        getLogger().debug("(Re)building the parsertable from '"+_grammarSource.getSystemId()+"'");

        SAXGrammarGenerator grammargenerator = new SAXGrammarGenerator();
        SourceUtil.toSAX(_grammarSource, grammargenerator, _manager);

        Grammar grammar = grammargenerator.getGrammar();
        SyntaxErrorException see = grammar.validate();
        if (see!=null)
        {
          getLogger().error("Grammar is not correct", see);
          throw new ProcessingException("Grammar is not correct", see);
        }
View Full Code Here

        catch (SAXParseException se)
        {
          log("The grammar file is not valid: " + se.getMessage());
          return;
        }
        Grammar grammar = grammargenerator.getGrammar();

        ParserTableGenerator generator = new ParserTableGenerator(grammar);
        generator.enableLogging(logger);
        ParserTable parsertable = generator.getParserTable();
View Full Code Here

        catch (SAXParseException se)
        {
          log("The grammar file is not valid: " + se.getMessage());
          return;
        }
        Grammar grammar = grammargenerator.getGrammar();

        ParserTableGenerator generator = new ParserTableGenerator(grammar);
        generator.enableLogging(logger);
        ParserTable parsertable = generator.getParserTable();
View Full Code Here

    info("parsing grammar file " + grammarFile.getName() + "...");
    parser.parse(grammarFile.getAbsolutePath());

    info("building parser table...");
    final Grammar g = gg.getGrammar();

    if (g == null)
    {
      throw new Exception("no Grammar was generated while parsing grammar file");
    }
View Full Code Here

   */
  public Associativity getAssociativity()
  {
    if (_owner==null)
      throw new IllegalStateException("Doesn't have a owner");
    Grammar grammar = _owner.getOwner();
    if (grammar==null)
      throw new IllegalStateException("ProductionList doesn't have a owner");

    if (_precedence != null)
      return grammar.getTokenList().getToken(_precedence).getAssociativity();
    for (int i = _definition.getSymbolCount() - 1; i >= 0; i--)
      if (_definition.getSymbol(i).isTerminal())
        return grammar.getTokenList().getToken(_definition.getSymbol(i)).getAssociativity();
    return Associativity.NONASSOC;
  }
View Full Code Here

   */
  public int getPriority()
  {
    if (_owner==null)
      throw new IllegalStateException("Doesn't have a owner");
    Grammar grammar = _owner.getOwner();
    if (grammar==null)
      throw new IllegalStateException("ProductionList doesn't have a owner");

    if (_precedence != null)
      return grammar.getTokenList().getToken(_precedence).getPriority();
    for (int i = _definition.getSymbolCount() - 1; i >= 0; i--)
      if (_definition.getSymbol(i).isTerminal())
        return grammar.getTokenList().getToken(_definition.getSymbol(i)).getPriority();
    return 0;
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.chaperon.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.