|
Lexicon.java
|
// FILE. . . . . /home/hak/ilt/src/ilog/rif/Lexicon.java // EDIT BY . . . Hassan Ait-Kaci // ON MACHINE. . 4j4zn71 // STARTED ON. . Thu Apr 03 13:44:34 2008 package ilog.rif.bld;
This is a simple lexicon class implementing a very basic token
discriminator for the tokenizer in Tokenizer.java.
|
import java.util.HashSet;
class Lexicon
{
private final static boolean _isLetterOrUnderscore (char c)
{
return c == '_' || Character.isLetter(c);
}
private final static boolean _isWordChar (char c)
{
return (c >= '0' && c <= '9') || _isLetterOrUnderscore(c);
}
| Returns true iff all the characters in the string suffix starting at position p in the specified string s are word characters. |
private final static boolean _isAllWordChars (String s, int p)
{
for (int i=p; i<s.length(); i++)
if (!_isWordChar(s.charAt(i)))
return false;
return true;
}
| Returns true iff the specified string starts with a letter or undersscore, and every other character is a word character. |
public final static boolean isIdentifier (String s)
{
return _isLetterOrUnderscore(s.charAt(0)) && _isAllWordChars(s,1);
}
| Returns true iff the specified string starts with a question mark, and every other character is a word character. |
public final static boolean isVariable (String s)
{
if (s.charAt(0) != '?')
return false;
return _isAllWordChars(s,1);
}
| Returns true iff the specified string starts with an underscore character, and every other character is a word character. |
public final static boolean isLocalName (String s)
{
if (s.charAt(0) != '_')
return false;
return _isAllWordChars(s,1);
}
| The following is a store for BLD reserved words. |
public static final HashSet reserved = new HashSet();
| Returns true iff the specified string is a reserved word. |
public final static boolean isReserved (String word)
{
return reserved.contains(word);
}
| Declares the specified string as a reserved word. |
static final void reserved (String word)
{
reserved.add(word.intern());
}
}
This file was generated on Mon Nov 17 15:35:41 PST 2008 from file Lexicon.java
by the ilog.language.tools.Hilite Java tool written by Hassan Aït-Kaci