Package net.sourceforge.chaperon.grammar.token

Examples of net.sourceforge.chaperon.grammar.token.Token


      for (j = 0; j < _ntsymbols.getSymbolCount(); j++)
        _table.setTransition(i, j, 0);

    // for all itemsets I in collection C
    ItemSet I;
    Token token;
    IntegerList reduceproductions;
    int highestproduction, priority;
    SymbolList shiftsymbols, reducesymbols;

    for (i = 0; i < _C.getSize(); i++)
    {
      I = _C.get(i);

      shiftsymbols = I.getShiftSymbols(); // Transition symbols for shift actions
      reducesymbols = I.getReduceSymbols(); // Lookahead symbols for reduce actions

      for (j = 0; j < _tsymbols.getSymbolCount(); j++)
      {
        reduceproductions = I.getReduceProductions(_tsymbols.getSymbol(j));
        priority = -1;
        highestproduction = -1;
        for (k = 0; k < reduceproductions.getSize(); k++)
        {
          /*if ((_grammar.getProductionList().getProduction(reduceproductions.get(k)).getSymbol().equals(
                      _grammar.getStartSymbol())) && (_tsymbols.getSymbol(j).equals(endsymbol)))
            _table.setAcceptAction(i, j, reduceproductions.get(k));*/

          if (_grammar.getProductionList().getProduction(reduceproductions.get(k)).getPriority()
                  > priority)
          {
            highestproduction = reduceproductions.get(k);
            priority = _grammar.getProductionList().getProduction(highestproduction).getPriority();
          }
        }

        //if (!_table.isAcceptAction(i, j))

        if (shiftsymbols.contains(_tsymbols.getSymbol(j)))
        {
          if (reducesymbols.contains(_tsymbols.getSymbol(j)))
          {
            token = _grammar.getTokenList().getToken(_tsymbols.getSymbol(j));

            if (token.getPriority() > priority)
            {
              _table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));

              if (_logger!=null)
                _logger.warn("Shift/Reduce Conflict State "+i+" between"+
                             System.getProperty(("line.separator"))+
                             token+System.getProperty(("line.separator"))+
                             _grammar.getProductionList().getProduction(highestproduction)+
                             System.getProperty(("line.separator"))+
                             "The parser will shift");
            }
            else if (token.getPriority() < priority)
            {
              /*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
                      _grammar.getStartSymbol()))
                   && (_tsymbols.getSymbol(j).equals(endsymbol)))
                _table.setAcceptAction(i, j, highestproduction);
              else*/
                _table.setReduceAction(i, j, highestproduction);

              if (_logger!=null)   
                _logger.warn("Shift/Reduce Conflict State "+i+" between"+
                             System.getProperty(("line.separator"))+
                             token+System.getProperty(("line.separator"))+
                             _grammar.getProductionList().getProduction(highestproduction)+
                             System.getProperty(("line.separator"))+
                             "The parser will reduce");
            }
            else
            {
              if (token.getAssociativity()==Associativity.RIGHT)
              {
                _table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));

                if (_logger!=null)   
                  _logger.warn("Shift/Reduce Conflict State "+i+" between"+
                               System.getProperty(("line.separator"))+
                               token+System.getProperty(("line.separator"))+
                               _grammar.getProductionList().getProduction(highestproduction)+
                               System.getProperty(("line.separator"))+
                               "The parser will shift");
              }
              else if (token.getAssociativity()==Associativity.LEFT)
              {
                /*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
                        _grammar.getStartSymbol()))
                    && (_tsymbols.getSymbol(j).equals(endsymbol)))
                  _table.setAcceptAction(i, j, highestproduction);
View Full Code Here


      {
        stack.push(new TokenList());
      }
      else if (localName.equals(TOKEN_ELEMENT))
      {
        Token token = new Token(TerminalSymbol.valueOf(atts.getValue(TOKEN_SYMBOL_ATTRIBUTE)));

        token.setAssociativity(getAssociativityFromAttributes(atts));
        stack.push(token);
      }
      /*else if (localName.equals(COMMENT_ELEMENT))
      {
        stack.push(new Comment(grammar));
View Full Code Here

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

   * Creates a empty grammar
   * Only EOF is definied as token.
   */
  public Grammar()
  {
    _tokenlist.addToken(new Token(TerminalSymbol.valueOf("EOF"), new EndOfFile()));

    _tokenlist.setOwner(this);
    //_universaltokenlist.setOwner(this);
    _ignorabletokenlist.setOwner(this);

View Full Code Here

TOP

Related Classes of net.sourceforge.chaperon.grammar.token.Token

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.