Package beaver.spec

Examples of beaver.spec.Production$List


     *
     * @param default_symbol synthetic symbol that is placed instead of the action lookahead
     */
    void compress()
    {
      Production maxrule = null;
      int maxcnt = 0;

      for (Action act = first; act != null; act = act.next)
      {
        if (act.type == Type.REDUCE)
        {
          Production rule = ((Reduce) act).rule;
          if (rule == maxrule) continue;
          int cnt = 1;
          for (Action cmp = act.next; cmp != null; cmp = cmp.next)
          {
            if (cmp.type == Type.REDUCE && ((Reduce) cmp).rule == rule)
View Full Code Here


    static private int[] makeProductionDescriptors(Grammar grammar)
    {
      int[] rules = new int[grammar.rules.length];
      for (int i = 0; i < grammar.rules.length; i++)
      {
        Production rule = grammar.rules[i];
        rules[i] = rule.lhs.id << 16 | rule.rhs.items.length;
      }
      return rules;
    }
View Full Code Here

       
    static private void writeReduceActionClasses(Grammar grammar, Writer out) throws IOException
    {
      for (int i = 0; i < grammar.rules.length; i++)
      {
        Production rule = grammar.rules[i];
        if (rule.code == null)
          continue;

        out.write("\n\t/**");
        out.write("\n\t * ");
        out.write(rule.toString());
        out.write("\n\t */");
        out.write("\n\tfinal class Action");
        out.write(String.valueOf(rule.id));
        out.write(" extends Action {\n");
        out.write("\t\t\t\tpublic Symbol reduce(Symbol[] _symbols, int offset) {\n");
View Full Code Here

    static private void writeStaticReturns(Grammar grammar, Writer out) throws IOException
    {
      BitSet ret_elems = new BitSet();
      for (int i = 0; i < grammar.rules.length; i++)
      {
        Production rule = grammar.rules[i];
        if (rule.code == null && rule.rhs.size() > 1)
        {
          int n = indexOfLastReferencedSymbol(rule.rhs);
                    if (n == 0)
                        continue;
View Full Code Here

    static private void writeParserActionsArray(Grammar grammar, Options opts, Writer out) throws IOException
    {
      for (int i = 0, last_i = grammar.rules.length - 1; i < grammar.rules.length; i++)
      {
        Production rule = grammar.rules[i];
        out.write("\n\t\t\t");
        if (rule.code == null)
        {
          if (rule.rhs.size() == 0)
          {
            out.write("Action.NONE");
            if (i != last_i) out.write(",  ");
            out.write("\t// [");
            out.write(String.valueOf(rule.id));
            out.write("] ");
            out.write(rule.toString());
          }
          else if (rule.rhs.size() == 1)
          {
            out.write("Action.RETURN");
            if (i != last_i) out.write(',');
            out.write("\t// [");
            out.write(String.valueOf(rule.id));
            out.write("] ");
            out.write(rule.toString());
          }
          else
          {
            int n = indexOfLastReferencedSymbol(rule.rhs);
            if (n == 0)
            {
              out.write("Action.RETURN");
            }
            else if (n > 0)
            {
              out.write("RETURN");
              out.write(String.valueOf(n + 1));
            }
                        else
                        {
                            out.write("RETURN");
                            out.write(String.valueOf(rule.rhs.size()));
                        }
            if (i != last_i) out.write(',');
            out.write("\t// [");
            out.write(String.valueOf(rule.id));
            out.write("] ");
            out.write(rule.toString());

            if (n < 0)
            {
              out.write("; returns '");
              out.write(rule.rhs.items[rule.rhs.size() - 1].symbol.name);
              out.write("' although none is marked");
            }
            else if (countReferencedSymbols(rule.rhs) > 1)
            {
              out.write("; returns '");
              out.write(rule.rhs.items[n].alias);
              out.write("' although more are marked");
            }
          }
        }
        else
        {
          out.write("new Action");
          if (opts.name_action_classes)
          {
            out.write(String.valueOf(rule.id));
            out.write("()");
            if (i != last_i) out.write(',');
            out.write("\t// [");
            out.write(String.valueOf(rule.id));
            out.write("] ");
            out.write(rule.toString());
          }
          else
          {
            out.write("() {\t// [");
            out.write(String.valueOf(rule.id));
            out.write("] ");
            out.write(rule.toString());
            out.write('\n');
            out.write("\t\t\t\tpublic Symbol reduce(Symbol[] _symbols, int offset) {\n");
            writeReduceActionCode(rule, out);
            out.write("\t\t\t\t}");
            out.write("\n\t\t\t}");
View Full Code Here

      state.actions.markReducibleProductions();
    }
    boolean has_unreducible = false;
    for (int i = 0; i < grammar.rules.length; i++)
    {
      Production rule = grammar.rules[i];
      if (!rule.is_reducible)
      {
        log.error(rule.start_pos, rule.end_pos, "Production \"" + rule.toString() + "\" can not be reduced");
        has_unreducible = true;
      }
    }
    if (has_unreducible)
    {
View Full Code Here

public class ListTest
{
   public static void main( String args[] )
   {
      List list = new List(); // create the List container

      // insert integers in list
      list.insertAtFront( -1 );
      list.print();
      list.insertAtFront( 0 );
      list.print();
      list.insertAtBack( 1 );
      list.print();
      list.insertAtBack( 5 );
      list.print();

      // remove objects from list; print after each removal
      try
      {
         Object removedObject = list.removeFromFront();
         System.out.printf( "%s removed\n", removedObject );
         list.print();

         removedObject = list.removeFromFront();
         System.out.printf( "%s removed\n", removedObject );
         list.print();

         removedObject = list.removeFromBack();
         System.out.printf( "%s removed\n", removedObject );
         list.print();

         removedObject = list.removeFromBack();
         System.out.printf( "%s removed\n", removedObject );
         list.print();
      } // end try
      catch ( EmptyListException emptyListException )
      {
         emptyListException.printStackTrace();
      } // end catch
View Full Code Here

TOP

Related Classes of beaver.spec.Production$List

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.