00001 /* 00002 * ConfigParser.h - parser for Rulbus configuration file. 00003 * 00004 * This file is part of the Rulbus Device Class Library (RDCL). 00005 * 00006 * Copyright (C) 2003-2004, Leiden University. 00007 * 00008 * This library is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * The library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with mngdriver; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * $Id: ConfigParser.h 2 2004-10-12 11:54:15Z moene $ 00023 */ 00024 00025 #ifndef __CONFIGPARSER_H 00026 #define __CONFIGPARSER_H 00027 00028 #include <vector> // for CardList 00029 00030 #ifndef __COMMON_H 00031 #include "Common.h" 00032 #endif 00033 00034 #include "ConfigScanner.h" // header 00035 00036 namespace Rulbus 00037 { 00038 DECLARE_CLASS( ConfigParser ); 00039 DECLARE_CLASS( ConfigScanner ); 00040 DECLARE_CLASS( ConfigBuilder ); 00041 DECLARE_CLASS( ConfigContext ); 00042 DECLARE_CLASS( RulbusDevice ); 00043 00137 class ConfigParser 00138 { 00139 public: 00140 ConfigParser( ConfigScanner& scanner, ConfigBuilder& builder, ConfigContext& context ); 00141 00142 void parse(); 00143 00144 protected: 00145 void parseProgram(); 00146 00147 void parseFileAssignment(); 00148 00149 void parseRackDeclarationSequence(); 00150 void parseRackDeclaration(); 00151 void parseRackInitializer(); 00152 00153 void parseRackAddressAssignment(); 00154 void parseCardDeclarationSequence(); 00155 void parseCardDeclaration(); 00156 void parseCardInitializer( ConfigToken::TokenCode card ); 00157 // void parseRB8506 (); // generic 00158 void parseRB8509 ( bool scanProperties = true ); 00159 void parseRB8510 ( bool scanProperties = true ); 00160 void parseRB8514 ( bool scanProperties = true ); 00161 // void parseRB8515 (); // generic 00162 void parseRB8905 ( bool scanProperties = true ); 00163 // void parseRB9005 ( bool scanProperties = true ); 00164 00165 void parseGenericCard( ConfigToken::TokenCode card, bool scanProperties = true ); 00166 00167 Int parseAddress ( ConfigToken::TokenCode token = ConfigToken::tcCARD ); 00168 bool parseHasExtTrigger ( ); 00169 Int parseNumChannels ( ); 00170 bool parseBipolar ( ); 00171 Real parseVoltPerBit ( ); 00172 Real parseIntrDelay ( ); 00173 00174 bool parseBooleanProperty( ConfigToken::TokenCode token ); 00175 Int parseIntegerProperty( ConfigToken::TokenCode token ); 00176 Real parseRealProperty ( ConfigToken::TokenCode token ); 00177 Real parseOptUnit ( ConfigToken::TokenCode token ); 00178 00179 void parseOptDelimiter ( ); 00180 void parseOptAssignOp ( ); 00181 00182 void checkRackAllowed ( ); 00183 void checkDuplicateRackName( ); 00184 void checkDuplicateCardName( ); 00185 void checkRackDeclaration ( ); 00186 void checkCardDeclarations ( ); 00187 void checkDuplicateRackAddr( bool withline = false ); 00188 void checkOverlapCardAddr ( bool withline = false ); 00189 00190 void addCard( RulbusDevicePtr card ); 00191 void clearRackCardList ( ); 00192 void updateRackCardList ( ); 00193 00194 void getToken( ); 00195 bool test ( ConfigToken::TokenCode token, bool require = true ); 00196 void expect ( ConfigToken::TokenCode token, bool require = true ); 00197 00205 class ParseError : public std::logic_error 00206 { 00207 public: 00209 ParseError( StringCref msg ) : std::logic_error( to_cstr( msg ) ) 00210 { 00211 ; //do nothing 00212 } 00213 }; 00214 00215 private: 00216 typedef std::vector<RulbusDevicePtr> CardList; 00217 typedef std::vector<String> NameList; 00218 typedef std::vector<bool> AddrList; 00219 typedef std::vector<int> LineList; 00220 00221 ConfigToken::TokenCode t; 00222 00223 ConfigScanner *theScanner; 00224 ConfigBuilder& theBuilder; 00225 ConfigContext& theContext; 00226 ConfigToken *theToken; 00227 00228 String theRackName; 00229 Int theRackAddress; 00230 Int theRackLine; 00231 00232 String theCardName; 00233 Int theCardAddress; 00234 00235 CardList theCardList; 00236 NameList theCardNameList; 00237 LineList theCardLineList; 00238 00239 CardList theRackCardList; 00240 AddrList theRackAddrSet; 00241 NameList theRackNameSet; 00242 LineList theRackLineSet; 00243 00244 private: 00245 static const int DEF_CARDS = 32; 00246 static const int LIM_RACKS = 16; 00247 00248 static CharCptr already_assigned; 00249 }; 00250 00251 } // namespace Rulbus 00252 00253 #endif // __CONFIGPARSER_H 00254 00255 /* 00256 * end of file 00257 */ 00258