Package beaver.spec

Examples of beaver.spec.Production


     *
     * @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

TOP

Related Classes of beaver.spec.Production

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.