import java.util.*;

/**
 * Production (Grammar rule) in the form of A {semantics} -> B C D
 * 
 * @author Nobo Komagata
 * @version 5/30/03
 */
public class Production
{
    public Category lhs;
    public Category[] rhs;

    /**
     * Constructor for objects of class Production
     */
    public Production(String production) 
    {
        // LHS = a single category (type:sem)
        StringTokenizer tok = new StringTokenizer(production);
        lhs = new Category(tok.nextToken("{").trim(),               // type
                           tok.nextToken("}").substring(1).trim()); // sem
        tok.nextToken(">");
        
        // RHS = list of Categories (no semantics)
        tok = new StringTokenizer(tok.nextToken("\n").substring(1));
        rhs = new Category[tok.countTokens()];

        for (int i = 0; i < rhs.length; ++i) {
            rhs[i] = new Category(tok.nextToken(" ").trim(), null);
            //                                               no semantics
        }
    }

    /**
     * String representation of the Production
     * 
     * @param       None
     * @return      String representation 
     */
    public String toString() {
        String s = lhs.type + " {" + lhs.sem + "} -> ";

        for (int i = 0; i < rhs.length; ++i) {
            s += (rhs[i].type + " ");
        }

        return s;
    }
}

