package osa.attribute.atgrammar.grammar.symbols;

import java.util.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class TerminalSymbol
  extends Symbol
  {

  protected String lexical_value;
  protected String default_lexical_value=null;

  public TerminalSymbol(String symbol_name)
    {
    super(symbol_name);
    symbol_type=Symbol.TERMINAL_SYMBOL;
    is_cloned=false;
    original_reference=this;
    }

  public String getLexicalValue()
    {
    return lexical_value;
    }

  public void setLexicalValue(String value)
    {
    lexical_value=value;
    }

  public String getDefaultLexicalValue()
    {
    return this.default_lexical_value;
    }

  public void setDefaultLexicalValue(String value)
    {
    default_lexical_value=value;
    }

  public Object clone()
    {
    // creating clone instance
    TerminalSymbol cloned=new TerminalSymbol(original_reference.getOriginalName());
    // setting corresponding symbol index
    cloned.symbol_index=original_reference.getCounterValue();
    original_reference.incrementCounter();
    // storing reference to original
    if(is_cloned)
      {
      cloned.original_reference=this.original_reference;
      }
    else
      {
      cloned.original_reference=this;
      }
    cloned.is_cloned=true;
    // copying fields



    // cloning attributes
    Attribute temp_attribute;
    int attr_count=this.getAttrubutesCount();
    for(int i=0;i<attr_count;i++)
       {
       temp_attribute=(Attribute)original_reference.attributes_list.get(i);
       cloned.attributes_list.add(temp_attribute.clone());
       }

    return cloned;
    }
  }