Logo Search packages:      
Sourcecode: jflex version File versions

LexicalStates.java

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * JFlex 1.3.5                                                             *
 * Copyright (C) 1998-2001  Gerwin Klein <lsf@jflex.de>                    *
 * All rights reserved.                                                    *
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License. See the file      *
 * COPYRIGHT for more information.                                         *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License along *
 * with this program; if not, write to the Free Software Foundation, Inc., *
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                 *
 *                                                                         *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

package JFlex;

import java.util.*;


/**
 * Simple symbol table, mapping lexical state names to integers. 
 *
 * @author Gerwin Klein
 * @version JFlex 1.3.5, $Revision: 1.13 $, $Date: 2001/10/08 10:08:01 $
 */
00032 public class LexicalStates {
  
  /** maps state name to state number */
00035   Hashtable states; 

  /** codes of inclusive states (subset of states) */
00038   Vector inclusive;

  /** number of declared states */
00041   int numStates;


  /**
   * constructs a new lexical state symbol table
   */
00047   public LexicalStates() {
    states = new Hashtable();
    inclusive = new Vector();
  }

  
  /**
   * insert a new state declaration
   */
00056   public void insert(String name, boolean is_inclusive) {
    if ( states.containsKey(name) ) return;

    Integer code = new Integer(numStates++);
    states.put(name, code);

    if (is_inclusive) 
      inclusive.addElement(code);
  }


  /**
   * returns the number (code) of a declared state, 
   * <code>null</code> if no such state has been declared.
   */
00071   public Integer getNumber(String name) {
    return (Integer) states.get(name);
  }

  
  /**
   * returns the number of declared states
   */
00079   public int number() {
    return numStates;
  }

  
  /**
   * returns the names of all states
   */
00087   public Enumeration names() {
    return states.keys();
  }

  /**
   * returns the code of all inclusive states
   */
00094   public Enumeration getInclusiveStates() {
    return inclusive.elements();
  }
}

Generated by  Doxygen 1.6.0   Back to index