FileDocCategorySizeDatePackage
SimpleTokenManager.javaAPI DocGlassfish v2 API4078Wed Aug 30 15:34:10 BST 2006persistence.antlr

SimpleTokenManager

public class SimpleTokenManager extends Object implements Cloneable, TokenManager

Fields Summary
protected int
maxToken
protected Vector
vocabulary
private Hashtable
table
protected Tool
antlrTool
protected String
name
protected boolean
readOnly
Constructors Summary
SimpleTokenManager(String name_, Tool tool_)


        
        antlrTool = tool_;
        name = name_;
        // Don't make a bigger vector than we need, because it will show up in output sets.
        vocabulary = new Vector(1);
        table = new Hashtable();

        // define EOF symbol
        TokenSymbol ts = new TokenSymbol("EOF");
        ts.setTokenType(Token.EOF_TYPE);
        define(ts);

        // define <null-tree-lookahead> but only in the vocabulary vector
        vocabulary.ensureCapacity(Token.NULL_TREE_LOOKAHEAD);
        vocabulary.setElementAt("NULL_TREE_LOOKAHEAD", Token.NULL_TREE_LOOKAHEAD);
    
Methods Summary
public java.lang.Objectclone()

        SimpleTokenManager tm;
        try {
            tm = (SimpleTokenManager)super.clone();
            tm.vocabulary = (Vector)this.vocabulary.clone();
            tm.table = (Hashtable)this.table.clone();
            tm.maxToken = this.maxToken;
            tm.antlrTool = this.antlrTool;
            tm.name = this.name;
        }
        catch (CloneNotSupportedException e) {
            antlrTool.panic("cannot clone token manager");
            return null;
        }
        return tm;
    
public voiddefine(persistence.antlr.TokenSymbol ts)
define a token

        // Add the symbol to the vocabulary vector
        vocabulary.ensureCapacity(ts.getTokenType());
        vocabulary.setElementAt(ts.getId(), ts.getTokenType());
        // add the symbol to the hash table
        mapToTokenSymbol(ts.getId(), ts);
    
public java.lang.StringgetName()
Simple token manager doesn't have a name -- must be set externally

        return name;
    
public java.lang.StringgetTokenStringAt(int idx)
Get a token symbol by index

        return (String)vocabulary.elementAt(idx);
    
public persistence.antlr.TokenSymbolgetTokenSymbol(java.lang.String sym)
Get the TokenSymbol for a string

        return (TokenSymbol)table.get(sym);
    
public persistence.antlr.TokenSymbolgetTokenSymbolAt(int idx)
Get a token symbol by index

        return getTokenSymbol(getTokenStringAt(idx));
    
public java.util.EnumerationgetTokenSymbolElements()
Get an enumerator over the symbol table

        return table.elements();
    
public java.util.EnumerationgetTokenSymbolKeys()

        return table.keys();
    
public persistence.antlr.collections.impl.VectorgetVocabulary()
Get the token vocabulary (read-only).

return
A Vector of TokenSymbol

        return vocabulary;
    
public booleanisReadOnly()
Simple token manager is not read-only

        return false;
    
public voidmapToTokenSymbol(java.lang.String name, persistence.antlr.TokenSymbol sym)
Map a label or string to an existing token symbol

        // System.out.println("mapToTokenSymbol("+name+","+sym+")");
        table.put(name, sym);
    
public intmaxTokenType()
Get the highest token type in use

        return maxToken - 1;
    
public intnextTokenType()
Get the next unused token type

        return maxToken++;
    
public voidsetName(java.lang.String name_)
Set the name of the token manager

        name = name_;
    
public voidsetReadOnly(boolean ro)

        readOnly = ro;
    
public booleantokenDefined(java.lang.String symbol)
Is a token symbol defined?

        return table.containsKey(symbol);