Clay Shell Version 17

Version 17 of the Clay Shell program is like the previous version except that a sequence of commands can be chunked for subsequent use. That is, a command can be defined.

Demos

java -jar ".../Clay17.jar" -h 300 -w 700 -c random

Code

package clay17;

import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;

public class Main {
    
    <<<Just like in the previous version!>>>

}

class ClayFrame extends Frame  implements ActionListener {
  
    <<<Just like in the previous version!>>>
  
}

class Interpreter {
    
    private ClayFrame clayFrame;
    private Definition definition = null;
        
    public Interpreter(ClayFrame cf) {

        <<<Just like in the previous version!>>>

    }
    
    private String[] quotes;
    private String[] words;
    
    private void establishWords()
    {

        <<<Just like in the previous version!>>>

    }
    
    private void establishQuotes()
    {

        <<<Just like in the previous version!>>>

    }

    public void interpret(String input)
    {

        <<<Just like in the previous version!>>>

    }

    public void interpretCommand(String command) {
        if ( command.equals("red") ) {
            clayFrame.pa().setBackground(Color.red);
        } else if ( command.equals("yellow") ) {
            clayFrame.pa().setBackground(Color.yellow);
        } else if ( command.equals("green") ) {
            clayFrame.pa().setBackground(Color.green);
        } else if ( command.equals("random") ) {
            clayFrame.pa().setBackground(randomColor());
        } else if ( command.equals("clear") ) {
            clayFrame.ta().setText("");
        } else if ( command.equals("clean") ) {
            clayFrame.pa().setBackground(Color.white);
        } else if ( command.equals("quote") ) {
            interpretQuoteCommand();
        } else if ( command.equals("word") ) {
            interpretWordCommand();
        } else if ( command.equals("pause") ) {
            pause();
        } else if ( command.equals(definition.head()) ) {
            interpretSimpleCommandSequence(definition.body());
        } else {
            clayFrame.ta().append("### Clay error:  Unrecognizable command: " + command + "\n");
        }
    }

    private void interpretQuoteCommand() {

        <<<Just like in the previous version!>>>

    }
       
    private void interpretWordCommand() {

        <<<Just like in the previous version!>>>

    }
       
    public Color randomColor() {

        <<<Just like in the previous version!>>>

    }

    private boolean isSimpleCommand(String input) {

        <<<Just like in the previous version!>>>

    }

    private boolean identifier(String input) {

        <<<Just like in the previous version!>>>

    }

    private boolean id(String input) {

        <<<Just like in the previous version!>>>

    }

    private boolean isAlphaNumeric(char ch) {

        <<<Just like in the previous version!>>>

    }

    private boolean alpha(char ch) {

        <<<Just like in the previous version!>>>

    }

    private boolean numeric(char ch) {

        <<<Just like in the previous version!>>>

    }

    private void interpretSimpleCommandSequence(String input) {

        <<<Just like in the previous version!>>>

    }

    private boolean isSimpleCommandSequence(String input) {

        <<<Just like in the previous version!>>>

    }
    
    private void pause() {

        <<<Just like in the previous version!>>>

    }
    
    private boolean isClayDefinition(String input) {
        StringTokenizer st = new StringTokenizer(input);
        if ( st.countTokens() < 3 ) {
            return false;
        } else {
            String first = st.nextToken();
            String second = st.nextToken();
            String rest = rest(st);
            return identifier(first) & 
                    second.equals("=") & 
                    isSimpleCommandSequence(rest);
        }
    }
    
    private void interpretClayDefinition(String input) {
        StringTokenizer st = new StringTokenizer(input);
        String head = st.nextToken();
        String eqsign = st.nextToken();
        String body = rest(st);
        definition = new Definition(head,body);
    }

    private String rest(StringTokenizer st) {
        String result = "";
        while ( st.hasMoreTokens() ) {
            result = result + " " + st.nextToken();
        }
        return result;
    }

}

class Definition {

    private String head;
    private String body;
    
    public Definition(String head, String body) {
        this.head = head;
        this.body = body;
    }
    
    public String toString() {
        return head + " = " + body;
    }    

    public String head() {
        return head;
    }
    
    public String body() {
        return body;
    }
    
}
Questions

  1. What is the new "featured" variable in this version?
  2. What is the new "featured" class in this version?
  3. What are the "featured" methods in this version? (Name two!)