www.pudn.com > cppcc.rar > basic_dfa_spec.hh
/* * File: basic_dfa_spec.hh * $Id: basic_dfa_spec.hh,v 1.5 2002/06/26 20:45:36 alec Exp $ * * Author: Alec Panovici (alecu@email.com) * * Comments: * * Revision history: * * $Log: basic_dfa_spec.hh,v $ * Revision 1.5 2002/06/26 20:45:36 alec * g++ 3.x happy * * Revision 1.4 2002/05/27 02:58:35 alec * doc update * * Revision 1.3 2002/05/01 16:32:14 alec * dfa ok. huh ! * * Revision 1.2 2002/05/01 09:18:26 alec * - vBitset fixes * - FOLLOWPOS written (not tested yet) * * Revision 1.1 2002/04/30 16:26:38 alec * my big endian will eat your little endian * */ /* Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 */ #ifndef __BASIC_DFA_SPEC_HH__ #define __BASIC_DFA_SPEC_HH__ #include#include using namespace std; #include "debug.h" /** * This class contains the transition table for a DFA that resulted from a * scanner lexical state. One such object is created by an instance of * BasicDfaGenerator for each regexp parse tree resulted from the scanner's * section. */ class BasicDfaSpec { public: /** * Describes a transition in the transition table. */ typedef struct t_Transition { /** * The input character on which this transition is taken. */ unsigned char on; /** * The target state of this transition. */ unsigned int to; t_Transition () {} t_Transition (unsigned char on_, unsigned int to_) : on(on_), to(to_) {} } Transition; /** * This is a DFA state. */ typedef struct t_State { t_State () : isFinal(false), tokId(0) {} void addTransition (unsigned char on, unsigned int to) { transitions.push_back(Transition(on, to)); } #ifdef DEBUG void dump (ostream &os); #endif /** * The "valid" transitions from this state. We assume that if a transitions * on a certain input character isn't here then it defaults to the "error" * transition. */ vector transitions; /** * True if this is an accepting state. */ bool isFinal; /** * If this state is an accepting state, this indicates the matched token's * id. */ int tokId; } State; /** * Creates a new BasicDfaSpec object with the given name. The name is that * of the corresponding scanner lexical state. */ BasicDfaSpec (const string &name_) : name(name_) {} #ifdef DEBUG void dump (ostream &os); #endif /** * The name of this DFA. */ string name; /** * The transitions table of the DFA. At index i, the State object contains * the transitions the automaton can take while in state i. */ vector states; }; #endif /* #ifndef __BASIC_DFA_SPEC_HH__ */