00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: VariableLexerRepository.cpp,v 1.7 2008/09/29 23:28:46 delpinux Exp $ 00019 00020 #include <VariableLexerRepository.hpp> 00021 00022 #include <Types.hpp> 00023 class Expression; 00024 class RealExpression; 00025 class BooleanExpression; 00026 class Vector3Expression; 00027 class StringExpression; 00028 00029 class FunctionExpression; 00030 00031 #include <FunctionExpressionMeshReferences.hpp> 00032 00033 class FieldExpression; 00034 class FieldExpressionList; 00035 00036 class MeshExpression; 00037 class MeshExpressionSurface; 00038 class MeshExpressionStructured; 00039 00040 #include <MeshExpression.hpp> 00041 00042 class SceneExpression; 00043 class DomainExpression; 00044 class OFStreamExpression; 00045 class IFStreamExpression; 00046 00047 class UnknownExpression; 00048 class UnknownListExpression; 00049 00050 class TestFunctionVariable; 00051 class TestFunctionExpressionList; 00052 00053 class BoundaryConditionListExpression; 00054 class BoundaryConditionExpression; 00055 class BoundaryExpression; 00056 00057 class PDEOperatorExpression; 00058 class PDEScalarOperatorExpressionOrderZero; 00059 class PDEVectorialOperatorExpressionOrderOne; 00060 class PDEScalarOperatorExpressionOrderOne; 00061 class PDEVectorialOperatorExpressionOrderTwo; 00062 00063 class PDEOperatorSumExpression; 00064 00065 class PDEEquationExpression; 00066 00067 class PDEProblemExpression; 00068 class PDESystemExpression; 00069 class SolverOptionsExpression; 00070 00071 class OptionExpression; 00072 00073 class OStreamExpression ; 00074 class OStreamExpressionList ; 00075 00076 class IStreamExpression ; 00077 class IStreamExpressionList ; 00078 00079 class SolverOptionsExpression; 00080 class SubOptionExpression; 00081 class SubOptionListExpression; 00082 00083 class Variable; 00084 class RealVariable; 00085 class Vector3Variable; 00086 class FunctionVariable; 00087 class OFStreamVariable; 00088 class IFStreamVariable; 00089 00090 class FunctionVariable; 00091 00092 class StringVariable; 00093 00094 class MeshVariable; 00095 class SceneVariable; 00096 class DomainVariable; 00097 class InsideExpression; 00098 class InsideListExpression; 00099 00100 class Instruction; 00101 00102 class IntegratedExpression; 00103 class IntegratedOperatorExpression; 00104 00105 class LinearExpression; 00106 00107 class MultiLinearExpression; 00108 class MultiLinearExpressionSum; 00109 class MultiLinearFormExpression; 00110 class MultiLinearFormSumExpression; 00111 00112 class VariationalDirichletListExpression; 00113 class BoundaryConditionExpressionDirichlet; 00114 class VariationalFormulaExpression; 00115 class VariationalProblemExpression; 00116 class ProblemExpression; 00117 00118 #include <FileDescriptor.hpp> 00119 #include <ScalarDiscretizationTypeBase.hpp> 00120 00121 #include <ScalarFunctionNormal.hpp> 00122 00123 #include <parse.ff.h> 00124 00125 VariableLexerRepository::Type VariableLexerRepository:: 00126 find(const std::string& name) const 00127 { 00128 Container::const_iterator i; 00129 size_t level=0; 00130 for (; level<=__blockLevel;++level) { 00131 i = __repository[level].find(name); 00132 if (i != __repository[level].end()) break; 00133 } 00134 if (level>__blockLevel) return -1; 00135 if (i == __repository[level].end()) return -1; 00136 else { 00137 return i->second; 00138 } 00139 } 00140 00141 void VariableLexerRepository:: 00142 markAsUnknown(const std::string& name) 00143 { 00144 Container::iterator i; 00145 size_t level=0; 00146 for (; level<=__blockLevel;++level) { 00147 i = __repository[level].find(name); 00148 if (i != __repository[level].end()) break; 00149 } 00150 00151 if (level>__blockLevel) { 00152 throw ErrorHandler(__FILE__,__LINE__, 00153 "cannot find variable "+name, 00154 ErrorHandler::unexpected); 00155 } 00156 00157 if (i == __repository[level].end()) 00158 { 00159 throw ErrorHandler(__FILE__,__LINE__, 00160 "cannot find variable "+name, 00161 ErrorHandler::unexpected); 00162 } else { 00163 i->second = VARUNKNOWNID; 00164 } 00165 } 00166 00167 00168 void VariableLexerRepository:: 00169 add(const std::string& name, const Type& type) 00170 { 00171 __repository[__blockLevel][name]=type; 00172 } 00173 00174 void VariableLexerRepository:: 00175 beginBlock() 00176 { 00177 __blockLevel++; 00178 __repository.push_back(Container()); 00179 } 00180 00181 void VariableLexerRepository:: 00182 endBlock() 00183 { 00184 ASSERT(__blockLevel>0); 00185 __repository[__blockLevel].clear(); 00186 __blockLevel--; 00187 00188 __repository.pop_back(); 00189 00190 // At the end of a block, unknowns are always variables! 00191 for (size_t level=0; level<=__blockLevel;++level) { 00192 for (Container::iterator ivariable = __repository[level].begin(); 00193 ivariable != __repository[level].end(); ++ivariable) { 00194 if (ivariable->second == VARUNKNOWNID) { 00195 ivariable->second = VARFNCTID; 00196 } 00197 } 00198 } 00199 } 00200 00201 VariableLexerRepository:: 00202 VariableLexerRepository() 00203 : __blockLevel(0) 00204 { 00205 __repository.push_back(Container()); 00206 } 00207 00208 VariableLexerRepository:: 00209 ~VariableLexerRepository() 00210 { 00211 ; 00212 } 00213
1.5.6