//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
using System;
using System.Collections;
using Ilog.Language.Util;
using Ilog.Language.Tools;
namespace Ilog.Language.Syntax
{
/**
* This class is derived by the classes representating all symbols
* used in by grammar or a parser.
*
* @see GrammarSymbol
* @see OperatorSymbol
*
* @version Last modified on Wed May 25 17:24:15 2005 by hak
* @author Hassan Aït-Kaci
* @copyright © 2000 ILOG, S.A.
*/
public class Symbol : ArrayListIndexed, Named, Comparable
{
/**
* Constructs a symbol with the specified name in the specified ArrayList.
*/
public Symbol (String name, ArrayList list)
: base(list)
{
this.name = String.Intern(name);
}
/**
* Constructs a symbol with the specified name in the specified ArrayList.
*/
public Symbol (String name, ArrayList list, int index)
: base(list,index)
{
this.name = String.Intern(name);
}
/** The name of the symbol. */
protected String name;
public String Name
{
get { return name; }
}
/**
* The substring of this symbol's name starting with its first letter
* if it contains any; otherwise, the full name.
*/
private String letterName;
public String LetterName
{
get
{
if (letterName == null)
letterName = Misc.LetterSubstring(name);
return letterName;
}
}
/**
* Returns true iff this symbol precedes the specified one.
* Symbols other than operators are ordered by their names,
* ignoring all leading non-letter characters. Operators are
* ordered by their precedences in their category - i.e.,
* this method is overridden in the subclass Operator.
* It is also overridden by NonTerminal in the case where the
* grammar's RULE_ORDER_MODE is true.
*/
public virtual bool LessThan (Comparable other)
{
if (!(other is Symbol))
return false;
String name = LetterName;
String oname = ((Symbol)other).LetterName;
char c1 = name[0];
char c2 = oname[0];
if (Char.IsLetter(c1) || Char.IsDigit(c1))
{
if (!(Char.IsLetter(c2) || Char.IsDigit(c2)))
return false;
}
else
if (Char.IsLetter(c2) || Char.IsDigit(c2))
return true;
return (String.Compare(name,oname,true) < 0);
}
public override string ToString ()
{
return name;
}
}
}