package osa.attribute.atgrammar.grammar;

import osa.attribute.atgrammar.grammar.symbols.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: </p>
 * <p>Company: </p>
 * @author not attributable
 * @version
 */

public class DerivationString
  extends SymbolsString
  {
  private Symbol current_symbol=null;
  private int current_index=0;

  private Grammar grammar_reference;

  public DerivationString(Grammar grammar_reference)
    {
    this.grammar_reference=grammar_reference;
    current_symbol=grammar_reference.getInitialSymbol();
    appendSymbol(current_symbol);
    }

  public void executeSubstitution(GrammarProduction production)
    {
    NonTerminalSymbol symbol_to_substitute;
    symbol_to_substitute=(NonTerminalSymbol)current_symbol;

    SymbolsString substitution_string;
    substitution_string=production.executeProduction(symbol_to_substitute);

    removeSymbolAt(current_index);

    insertStringAt(current_index,substitution_string);
    }

  }