Package beaver.spec

Examples of beaver.spec.Production$RHS$Item


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

    Document doc = _docBuilder.newDocument();
    Element elem = doc.createElement("item-notes");
    Text textValue = doc.createTextNode("SalesID# 3445");
    elem.appendChild(textValue);
   
    Item item = pBuilder.createShoppingItem(itemName, itemDesc, quantity,
      unitPrice, null, currency, elem);
   
    assertEquals(itemName, item.getItemName());
    assertEquals(itemDesc, item.getItemDescription());
    assertEquals(quantity, item.getQuantity());
    assertEquals(4999.99F, item.getUnitPrice().getValue().floatValue());
    assertEquals(currency, item.getUnitPrice().getCurrency());
    assertEquals(elem, item.getMerchantPrivateItemData().getAny());
  }
View Full Code Here

    String[] itemDescs = new String[] {"mp3 player", "podcast subscription"};
    int[] quantities = new int[] {2, 1};
    float[] prices = new float[] {249.99F, 3.99F};
    List<Item> itemList = new ArrayList<Item>();
    for (int i = 0; i < itemNames.length; i++) {
      Item cartItem = pBuilder.createShoppingItem(itemNames[i], itemDescs[i],
        quantities[i], prices[i], null, null, null);
      itemList.add(cartItem);
    }
   
    return itemList;
View Full Code Here

  public Item createShoppingItem(String itemName, String itemDesc,
      int quantity, float unitPrice, String currency,
      String taxTableSelector, Element privateItemData)
      throws ProtocolException {
    Money money = createMoney(unitPrice, currency);
    Item item = _objectFact.createItem();
    item.setItemName(itemName);
    item.setItemDescription(itemDesc);
    item.setQuantity(quantity);
    item.setUnitPrice(money);

    if (taxTableSelector != null) {
      item.setTaxTableSelector(taxTableSelector);
    }
   
    if (privateItemData != null) {
      AnyType anyType = _objectFact.createAnyType();
      anyType.setAny(privateItemData);
      item.setMerchantPrivateItemData(anyType);
    }
   
    return item;
  }
View Full Code Here

      String taxTableSelector, Element privateItemData)
      throws ProtocolException {
   
    try {
      Money money = createMoney(unitPrice, currency);
      Item item = _objectFact.createItem();
      item.setItemName(itemName);
      item.setItemDescription(itemDesc);
      item.setQuantity(quantity);
      item.setUnitPrice(money);
 
      if (taxTableSelector != null) {
        item.setTaxTableSelector(taxTableSelector);
      }
     
      if (privateItemData != null) {
        AnyType anyType = _objectFact.createAnyType();
        anyType.setAny(privateItemData);
        item.setMerchantPrivateItemData(anyType);
      }
     
      return item;
    } catch (JAXBException jaxbEx) {
      throw new ProtocolException(jaxbEx.getMessage());
View Full Code Here

TOP

Related Classes of beaver.spec.Production$RHS$Item

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.