1 | // \file grammar.g |
---|
2 | // \brief ANTLR based YAO lexer and parser. |
---|
3 | // \remarks This file somehow breaks the "one class declaration per file" rule. |
---|
4 | // \version 2007/10/01 (yyyy/mm/dd) |
---|
5 | // \author Luigi Nardi <luiginardi(at)gmail.com> |
---|
6 | // |
---|
7 | // This file is part of YAO, a framework for variational assimilation in |
---|
8 | // numerical models. |
---|
9 | // Copyright (c) 2001-onwards LOCEAN. All rights reserved. |
---|
10 | // |
---|
11 | // This program may be redistributed and/or modified under the terms of the GNU |
---|
12 | // General Public License as published by the Free Software Foundation, either |
---|
13 | // version 2 of the license, or (at your option) any later version. |
---|
14 | // |
---|
15 | // This program is provided AS IS and WITHOUT ANY WARRANTY, including any |
---|
16 | // implied warranty of DESIGN, MERCHANTABILITY or FITNESS FOR A PARTICULAR |
---|
17 | // PURPOSE. |
---|
18 | |
---|
19 | |
---|
20 | header "pre_include_hpp"{ |
---|
21 | #include <iostream> |
---|
22 | #include <cstdlib> |
---|
23 | #include "../YAOObjects/Constant.hpp" |
---|
24 | #include "../YAOObjects/Context.hpp" |
---|
25 | #include "../YAOObjects/Function.hpp" |
---|
26 | #include "../YAOObjects/Identifier.hpp" |
---|
27 | #include "../YAOObjects/Neuron.hpp" |
---|
28 | #include "../YAOObjects/Operator.hpp" |
---|
29 | #include "../YAOObjects/Table.hpp" |
---|
30 | #include "../help/FilePath.hpp" |
---|
31 | #include "../YAOObjects/Modul.hpp" |
---|
32 | #include "../YAOObjects/Connection.hpp" |
---|
33 | #include "../YAOObjects/Order.hpp" |
---|
34 | #include "../help/Display.hpp" |
---|
35 | } |
---|
36 | |
---|
37 | header "post_include_cpp"{ |
---|
38 | #include <iomanip> |
---|
39 | |
---|
40 | //! \namespace antlr |
---|
41 | //! \brief ANTLR namespace. |
---|
42 | using namespace antlr; |
---|
43 | using namespace std; |
---|
44 | } |
---|
45 | |
---|
46 | options{ |
---|
47 | language = "Cpp"; // Generates C++ code. |
---|
48 | namespace = "yao"; // Encapsulates parser in namespace yao. |
---|
49 | namespaceStd = "std::"; // Makes generated code more readable. |
---|
50 | namespaceAntlr = "antlr::"; // Makes generated code more readable. |
---|
51 | //genHashLines = false; // Makes generated code more readable. |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * \class yao::BaseParser |
---|
56 | * \brief BaseParser class, handles project description analysis. Building |
---|
57 | * the AST is worthless here as all constructs can be generated from previously parsed information. |
---|
58 | */ |
---|
59 | class BaseParser extends Parser; |
---|
60 | options{ |
---|
61 | exportVocab = Yao; // Sets YAO vocabulary name. |
---|
62 | defaultErrorHandler = false; // Turns off default exception handling. |
---|
63 | buildAST = false; // Turns off AST construction. |
---|
64 | } |
---|
65 | |
---|
66 | { |
---|
67 | public: |
---|
68 | |
---|
69 | virtual ~BaseParser() {} //!< Destructor. |
---|
70 | |
---|
71 | private: |
---|
72 | |
---|
73 | /** |
---|
74 | * Searches given token in table (throws exception when not found). |
---|
75 | * @param aTable the Table where we want to search the information. |
---|
76 | * @param aName the name that we want to search. |
---|
77 | */ |
---|
78 | template <typename T> |
---|
79 | std::string search(const Table<T>& aTable,const antlr::RefToken& aName){ |
---|
80 | YAO_ENFORCE(aTable.find(aName->getText()))(aName->getLine())("unknown ") |
---|
81 | (T::getPropertyName(0))(": ")(aName->getText()); |
---|
82 | return aName->getText(); |
---|
83 | } |
---|
84 | |
---|
85 | void exit(){ //!< Exits parser. |
---|
86 | std::cout << "> exit" << std::endl; |
---|
87 | std::exit(EXIT_SUCCESS); |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * The display_flagop of the YAO version 8 is obsolete in this current version. |
---|
92 | * This is why the display of the modules, exec disp_modul, already shows this information. |
---|
93 | * We leave this display here for compability with others version but we do not implement it. |
---|
94 | **/ |
---|
95 | void displayFlagop() const{ |
---|
96 | cout << "displayFlagop" << ": Obsolete in current YAO version." << endl |
---|
97 | << "The information linking each module with the operator (if it has one) is already available in the display of the modules:" |
---|
98 | << "\"exec disp_modul\"." << endl << endl; |
---|
99 | } |
---|
100 | |
---|
101 | protected: |
---|
102 | |
---|
103 | Table<Identifier> theIdentifierTable; //!< Table of identifiers. |
---|
104 | Table<Constant> theConstantTable; //!< Table of constants. |
---|
105 | std::vector<std::string> theHeaderList; //!< List of header (hat) files. |
---|
106 | Context theContext; //!< Code generation context (options). |
---|
107 | Table<Trajectory> theTrajectoryTable; //!< Table of trajectories. |
---|
108 | Table<Space> theSpaceTable; //!< Table of so-called spaces (model operators). |
---|
109 | Table<Operator> theOperatorTable; //!< Table of operators. |
---|
110 | Table<Neuron> theNeuronTable; //!< Table of neurons. |
---|
111 | Table<Function> theFunctionTable; //!< Table of user-defined functions. |
---|
112 | Table<yao::Modul> theModulTable; //!< Table of user-defined modules. |
---|
113 | Table<Connection> theConnectionTable; //!< Table of user-defined connections. |
---|
114 | Table<Order> theOrderTable; //!< Table of user-defined orders. |
---|
115 | Display theDisplay; //!< Record that contains all the display requested. |
---|
116 | } |
---|
117 | |
---|
118 | /* |
---|
119 | incompleted----NOT YET IMPLEMENTED: |
---|
120 | Yao9 has a new conception of the YAO grammar. Firstly we have to define obligatorialy a "Model declaration block" |
---|
121 | and then we define others pieces of blocks later. The important thing is that every new stuff introducted must |
---|
122 | exist, so it has been defined before. So space and trajectory block can be reversed in the description block but |
---|
123 | when we declare the space it must refer to a trajectory that already exist. |
---|
124 | */ |
---|
125 | description : |
---|
126 | ( defvalBlock )? |
---|
127 | hat_nameBlock |
---|
128 | ( optionBlock )? |
---|
129 | ( // Model declaration block. |
---|
130 | trajBlock |
---|
131 | spaceBlock |
---|
132 | ( operaBlock )? |
---|
133 | ( netwardBlock )? |
---|
134 | modulBlock |
---|
135 | ctBlock |
---|
136 | orderBlock |
---|
137 | )+ |
---|
138 | ( insert_fctBlock )? |
---|
139 | EOF! |
---|
140 | ; |
---|
141 | |
---|
142 | defvalBlock |
---|
143 | : ( execStatement | defvalDeclaration )+ |
---|
144 | ; |
---|
145 | |
---|
146 | hat_nameBlock |
---|
147 | : hat_nameDefinition ( hat_nameDefinition | execStatement )* |
---|
148 | ; |
---|
149 | |
---|
150 | optionBlock |
---|
151 | : optionDeclaration ( optionDeclaration | execStatement )* |
---|
152 | ; |
---|
153 | |
---|
154 | trajBlock |
---|
155 | : trajDeclaration ( trajDeclaration | execStatement )* |
---|
156 | ; |
---|
157 | |
---|
158 | spaceBlock |
---|
159 | : spaceDeclaration ( spaceDeclaration | execStatement )* |
---|
160 | ; |
---|
161 | |
---|
162 | operaBlock |
---|
163 | : operaDeclaration ( operaDeclaration | execStatement )* |
---|
164 | ; |
---|
165 | |
---|
166 | netwardBlock |
---|
167 | : netwardDeclaration ( netwardDeclaration | execStatement )* |
---|
168 | ; |
---|
169 | |
---|
170 | modulBlock |
---|
171 | : modulDeclaration ( modulDeclaration | execStatement )* |
---|
172 | ; |
---|
173 | |
---|
174 | ctBlock |
---|
175 | : ctDefinition ( ctDefinition | execStatement )* |
---|
176 | ; |
---|
177 | |
---|
178 | orderBlock |
---|
179 | : orderDefinition ( orderDefinition | execStatement )* |
---|
180 | ; |
---|
181 | |
---|
182 | insert_fctBlock |
---|
183 | : insert_fctDeclaration ( insert_fctDeclaration | execStatement )* |
---|
184 | ; |
---|
185 | |
---|
186 | execStatement // Command execution statement. |
---|
187 | : EXEC^ ( EXIT { this->exit(); } |
---|
188 | | HELP { theDisplay.setHelp(true); } |
---|
189 | | DISP_DEFVAL { theDisplay.setDefval(true); } |
---|
190 | | DISP_TRAJ { theDisplay.setTrajectory(true); } |
---|
191 | | DISP_SPACE { theDisplay.setSpace(true); } |
---|
192 | | DISP_OPERA { theDisplay.setOpera(true); } |
---|
193 | | DISP_NETWARD { theDisplay.setNeuron(true); } |
---|
194 | | DISP_MODUL { theDisplay.setModule(true); } |
---|
195 | | DISP_CT_IN { theDisplay.setConnection(true); } |
---|
196 | | DISP_CT_OUT { cout << std::endl << "warning DISP_CT_OUT" << ": this exec belong to olds versions of YAO." << endl; } |
---|
197 | | DISP_FLAGOP { cout << "warning DISP_FLAGOP" << ": this exec belong to olds versions of YAO." << endl |
---|
198 | << "The information linking each module with the operator (if it has one) is already available in the display of modules:" |
---|
199 | << "\"exec disp_modul\"" << endl; } |
---|
200 | | DISP_OPTION { theDisplay.setContext(true); } |
---|
201 | ) |
---|
202 | ; |
---|
203 | |
---|
204 | defvalDeclaration // Constant declaration. |
---|
205 | { |
---|
206 | string name; |
---|
207 | string value; |
---|
208 | } |
---|
209 | : DEFVAL^ name=identifier |
---|
210 | ( // Unassigned constant. |
---|
211 | | value=integerLiteral |
---|
212 | | value=floatLiteral |
---|
213 | | value=stringLiteral |
---|
214 | | value=constantName { value = theConstantTable.find(value)->getText(); } |
---|
215 | ) |
---|
216 | { int line = LT(1)->getLine(); |
---|
217 | //exception case of Y3_M |
---|
218 | YAO_ENFORCE(!(name=="Y3_M" && atoi(value.c_str()) <= 0))(line)("Y3_M must be positive "); |
---|
219 | theConstantTable.push_back(Constant(name, value)); |
---|
220 | } |
---|
221 | ; |
---|
222 | |
---|
223 | hat_nameDefinition // Header (hat) file definition. |
---|
224 | { vector<string> fileList; |
---|
225 | string str; |
---|
226 | } |
---|
227 | : HAT_NAME^ |
---|
228 | ( |
---|
229 | name:IDENTIFIER { |
---|
230 | // Firstly we control if it is a constant defined with defval. |
---|
231 | Constant * con = theConstantTable.find(name->getText()); |
---|
232 | if(con==NULL){ |
---|
233 | // If it is not a constant warning for DEPRECATED notation. |
---|
234 | str = name->getText(); |
---|
235 | str.append(".h"); |
---|
236 | theHeaderList.push_back(str); |
---|
237 | cout << endl << "Warning in hat directive: " |
---|
238 | << "the syntax for inserting the hat file should be:" << endl |
---|
239 | << "> hat_name \"name.h\"" << endl << "instead of deprecated" << endl |
---|
240 | << "> hat_name name." << endl << "Please add quotation marks and extension. " << endl |
---|
241 | << "YAO has corrected the problem, the hat file is: " << endl; |
---|
242 | for(vector<string>::iterator it=theHeaderList.begin(); it!=theHeaderList.end(); it++) |
---|
243 | cout << *it << endl; |
---|
244 | }else { |
---|
245 | // If it is a constant is something like "hatName.h" or "hatName", so we manipulate. |
---|
246 | FilePath fp = (static_cast<FilePath>(con->getText()).removeDoubleQuote()); |
---|
247 | if(!(fp.getExtension() == ".h")){ |
---|
248 | fp.append(".h"); |
---|
249 | cout << endl << "Warning in hat directive: " |
---|
250 | << "the syntax for inserting the hat file should be:" << endl |
---|
251 | << "> hat_name \"name.h\"" << endl << "instead of deprecated" << endl |
---|
252 | << "> hat_name name." << endl << "Please add quotation marks and extension. " << endl |
---|
253 | << "YAO has corrected the problem, the hat file is: " << endl; |
---|
254 | //for(vector<string>::iterator it=theHeaderList.begin(); it!=theHeaderList.end(); it++) |
---|
255 | //cout << *it << endl; |
---|
256 | cout << fp << endl; |
---|
257 | } |
---|
258 | theHeaderList.push_back(fp); |
---|
259 | } |
---|
260 | } |
---|
261 | | |
---|
262 | fileList=stringConstantList |
---|
263 | { |
---|
264 | vector<string>::iterator it; |
---|
265 | for(it=fileList.begin(); it!=fileList.end(); it++) |
---|
266 | *it = (static_cast<FilePath>(*it).removeDoubleQuote()).isFileHeader(); |
---|
267 | theHeaderList.insert(theHeaderList.end(), fileList.begin(), fileList.end()); |
---|
268 | } |
---|
269 | ) |
---|
270 | ; |
---|
271 | |
---|
272 | optionDeclaration |
---|
273 | : OPTION^ ( optionAttribute )+ |
---|
274 | ; |
---|
275 | |
---|
276 | optionAttribute |
---|
277 | { |
---|
278 | vector<string> fileList; |
---|
279 | int writeMode, size; |
---|
280 | } |
---|
281 | : O_TOOL^ { theContext.setTool(); } |
---|
282 | | O_REAL^ ( |
---|
283 | FLOAT { theContext.setDouble(false); } |
---|
284 | | DOUBLE { |
---|
285 | if(!theContext.isDouble()) |
---|
286 | cout << "Warning: multiple definition of O_REAL option, ambiguities are possible\n"; |
---|
287 | theContext.setDouble(); |
---|
288 | } |
---|
289 | ) |
---|
290 | | O_EXTOBJ^ fileList=stringConstantList |
---|
291 | { |
---|
292 | vector<string>::iterator it; |
---|
293 | for(it=fileList.begin(); it!=fileList.end(); it++) |
---|
294 | *it = (static_cast<FilePath>(*it).removeDoubleQuote()).isFileObject(); |
---|
295 | theContext.addExternal(fileList); |
---|
296 | } |
---|
297 | | O_NETWARD^ size=positiveConstant |
---|
298 | { |
---|
299 | if(theContext.getNeuronSize()) |
---|
300 | cout << "Warning: multiple definition of O_NETWARD option, ambiguities are possible\n"; |
---|
301 | theContext.setNeuron(size); |
---|
302 | } |
---|
303 | | O_M1QN3^ |
---|
304 | { |
---|
305 | if(theContext.isM2qn1()) |
---|
306 | cout << "Warning: multiple definition of O_M1QN3 option, ambiguities are possible\n"; |
---|
307 | theContext.setM1qn3(); |
---|
308 | } |
---|
309 | ( M2QN1 { theContext.setM2qn1(); } )? |
---|
310 | | O_VARINCR^ { theContext.setIncremental(); } |
---|
311 | | O_AUTODF^ |
---|
312 | { |
---|
313 | if(theContext.getAutoDiff()) |
---|
314 | cout << "Warning: multiple definition of O_AUTODF option, ambiguities are possible\n"; |
---|
315 | theContext.setAutoDiff(); |
---|
316 | } |
---|
317 | ( ALL {theContext.setAutoDiff(2);} | ONLY {theContext.setAutoDiff(1);} )? |
---|
318 | ( writeMode=integerConstant |
---|
319 | { |
---|
320 | int line = LT(1)->getLine(); |
---|
321 | YAO_ENFORCE(writeMode == 0 || writeMode == 1)(line)("AUTODF option: write mode must be 0 or 1"); |
---|
322 | theContext.setAutoDiffWriteMode(writeMode); |
---|
323 | } |
---|
324 | )? |
---|
325 | | O_GRADTEST^ { theContext.setGradTest(); } |
---|
326 | | O_DBG_NANF^ { theContext.setDebugNan(); } |
---|
327 | | O_DBG_TING^ { theContext.setDebugInput(); } |
---|
328 | | O_DBG_BETA^ { theContext.setDebugBeta(); } |
---|
329 | | O_DBG_TRC_FWARD^ { theContext.setDebugForward(); } |
---|
330 | | O_DBG_TRC_BWARD^ { theContext.setDebugBackward(); } |
---|
331 | | O_DBG_TRC_LWARD^ { theContext.setDebugLinward(); } |
---|
332 | | O_DBG_TRC_AWARD^ |
---|
333 | { |
---|
334 | theContext.setDebugForward(); |
---|
335 | theContext.setDebugBackward(); |
---|
336 | theContext.setDebugLinward(); |
---|
337 | } |
---|
338 | ; |
---|
339 | |
---|
340 | trajDeclaration // Trajectory declaration. |
---|
341 | { |
---|
342 | string name; |
---|
343 | Trajectory::Type type; |
---|
344 | int line; |
---|
345 | int boot; // (uptime) |
---|
346 | int size; // (nbsteptime) |
---|
347 | double step = 1; // (dtime) |
---|
348 | double offset = 0; // (offtime) |
---|
349 | } |
---|
350 | : TRAJ^ name=identifier type=trajectoryType |
---|
351 | boot=integerConstant // (uptime) |
---|
352 | ( ( floatConstant floatConstant )=> |
---|
353 | offset=floatConstant // (offtime) |
---|
354 | { line = LT(1)->getLine(); } step=floatConstant // (dtime) |
---|
355 | { YAO_ENFORCE(step > 0)(line)("invalid step in trajectory: ")(name); } |
---|
356 | | // Optional predicate, avoids non-determinism. |
---|
357 | ) { line = LT(1)->getLine(); } |
---|
358 | size=positiveConstant // (nbsteptime) |
---|
359 | { |
---|
360 | YAO_ENFORCE(boot < size)(line)("invalid size in trajectory: ")(name); |
---|
361 | theTrajectoryTable.push_back(Trajectory(name, boot, size, step, offset, type)); |
---|
362 | } |
---|
363 | ; |
---|
364 | |
---|
365 | |
---|
366 | spaceDeclaration // So-called space (model operator) declaration. |
---|
367 | { |
---|
368 | string name; |
---|
369 | vector<int> shape; |
---|
370 | string parent; |
---|
371 | } |
---|
372 | : SPACE^ name=identifier M! shape=extent parent=trajectoryName |
---|
373 | { |
---|
374 | theSpaceTable.push_back(Space(name, theTrajectoryTable.find(parent), shape)); |
---|
375 | } |
---|
376 | ; |
---|
377 | |
---|
378 | operaDeclaration // Operator declaration. |
---|
379 | { |
---|
380 | string name; |
---|
381 | Operator::Type type; |
---|
382 | vector<int> shape; |
---|
383 | string parent; |
---|
384 | } |
---|
385 | : OPERA^ name=identifier type=operatorType shape=extent parent=trajectoryName |
---|
386 | { |
---|
387 | theOperatorTable.push_back(Operator(name, theTrajectoryTable.find(parent), shape, type)); |
---|
388 | } |
---|
389 | ; |
---|
390 | |
---|
391 | netwardDeclaration // Neuron declaration. |
---|
392 | { |
---|
393 | string name; |
---|
394 | int indegree; |
---|
395 | int outdegree; |
---|
396 | } |
---|
397 | : NETWARD^ name=identifier indegree=integerConstant outdegree=integerConstant |
---|
398 | { theNeuronTable.push_back(Neuron(name, indegree, outdegree)); } |
---|
399 | ; |
---|
400 | |
---|
401 | modulDeclaration // Module declaration. |
---|
402 | { |
---|
403 | int type; |
---|
404 | string parent, name; |
---|
405 | } |
---|
406 | : MODUL^ name=identifier { type = LT(1)->getType(); } |
---|
407 | parent=modulParent { |
---|
408 | if(type == SPACE) |
---|
409 | theModulTable.push_back(Modul(name, theSpaceTable.find(parent), true)); |
---|
410 | else theModulTable.push_back(Modul(name, theOperatorTable.find(parent), false)); |
---|
411 | } |
---|
412 | ( modulAttribute )* |
---|
413 | ; |
---|
414 | |
---|
415 | modulAttribute |
---|
416 | { |
---|
417 | Table<Modul>::iterator it = (theModulTable.end() - 1); |
---|
418 | int size, axe; |
---|
419 | string name; |
---|
420 | } |
---|
421 | : NOWARD { it->setNoward(true); } |
---|
422 | | INTER^ { if(it->isInter()) cout << "Warning: multiple definition of inter module option, ambiguities are possible\n";} |
---|
423 | axe=axis {it->setInter(axe);} |
---|
424 | ( axe=axis { |
---|
425 | if(it->isInterYA(axe)) |
---|
426 | cout << "Warning: multiple definition of inter YA" << axe << " option, ambiguities are possible\n"; |
---|
427 | it->setInter(axe); |
---|
428 | } |
---|
429 | ( axe=axis { |
---|
430 | if(it->isInterYA(axe)) |
---|
431 | cout << "Warning: multiple definition of inter YA" << axe << " option, ambiguities are possible\n" |
---|
432 | << "Warning <inter option>: define 3 axes for a subspace of a maximum 3 dimensions space has no sense\n"; |
---|
433 | it->setInter(axe); |
---|
434 | if(it->isInterYA(1) && it->isInterYA(2) && it->isInterYA(3)){ |
---|
435 | cout << "Warning: you define for inter Module option the YA1 YA2 and YA3 parameters that mean the entire space.\n" |
---|
436 | << "In this case the definition of the subspace inter option has no sense\n"; |
---|
437 | it->setInter(0); |
---|
438 | } |
---|
439 | })? |
---|
440 | )? |
---|
441 | | INPUT^ { if(it->getInput()) cout << "Warning: multiple definition of input module option, ambiguities are possible\n"; } |
---|
442 | ( ARRAY { it->setArray(true); })? |
---|
443 | size=integerConstant { it->setInput(size); } |
---|
444 | | OUTPUT^ { if(it->getOutput()) cout << "Warning: multiple definition of output module option, ambiguities are possible\n"; } |
---|
445 | size=integerConstant { it->setOutput(size); } |
---|
446 | | TARGET {it->setTarget(1); /*it->setTempo(true);*/} //default maybe?!: if target then is also tempo. |
---|
447 | // syntaxe: target [{uptime, UPTIME, steptime, STEPTIME, alltime, ALLTIME}] the default is uptime. |
---|
448 | ( (UPTIME { it->setTarget(2);} | STEPTIME {it->setTarget(3);} | ALLTIME {it->setTarget(4);} ) |
---|
449 | { if(it->getTarget() > 1) cout << "Warning: multiple definition of target module option, ambiguities are possible\n"; } |
---|
450 | )? |
---|
451 | | TEMPO { it->setTempo(true); } |
---|
452 | | COUT { it->setCout(true); } |
---|
453 | | LOPERA { if(it->isLopera()) cout << "Warning: multiple definition of lopera module option, ambiguities are possible\n"; } |
---|
454 | ( name=operatorName { |
---|
455 | if(it->alreadyLopera(name)) |
---|
456 | cout << "Warning: multiple definition of Operator " << name << " in lopera module option\n"; |
---|
457 | else it->addLopera(name); |
---|
458 | } |
---|
459 | )+ |
---|
460 | | COVT^ name=moduleName |
---|
461 | { |
---|
462 | int line = LT(1)->getLine(); |
---|
463 | if(it->isCovt()) |
---|
464 | cout << "Warning: multiple definition of covt module option, ambiguities are possible\n"; |
---|
465 | YAO_ENFORCE(theModulTable.find(name)->isCout() || theModulTable.find(name)->isTarget()) |
---|
466 | (line)("directive modul: token covt must refer a cout or target modul\n"); |
---|
467 | YAO_ENFORCE(theModulTable.find(name)->getCovt().empty() || theModulTable.find(name)->getCovt() == name) |
---|
468 | (line)("directive modul: token covt already referred cost or target modul\n"); |
---|
469 | // If the module is Space and not Operator we exit. |
---|
470 | YAO_ENFORCE(!it->isSpaceOrOperator())(line)("the covt option can be applied only to modules defined like Operators.\n"); |
---|
471 | YAO_ENFORCE(it->getParent()->getType() == 'B' || it->getParent()->getType() == 'R' || it->getParent()->getType() == 'K') |
---|
472 | (line)("directive modul: token covt must be associated with a covariance operator 'B', 'R' or 'K'\n"); |
---|
473 | theModulTable.find(name)->setCovt(it->getName()); |
---|
474 | } |
---|
475 | | SPEC { it->setSpec(true); } |
---|
476 | | NETWARD { it->setNetward(true); } |
---|
477 | | AUTONET^ name=neuronName |
---|
478 | { |
---|
479 | if(it->isAutonet()) |
---|
480 | cout << "Warning: multiple definition of autonet module option, ambiguities are possible\n"; |
---|
481 | it->setAutonet(name);} |
---|
482 | | CLONOL^ name=moduleName |
---|
483 | { |
---|
484 | if(it->isClonol()) |
---|
485 | cout << "Warning: multiple definition of clonol module option, ambiguities are possible\n"; |
---|
486 | it->setClonol(name); |
---|
487 | } |
---|
488 | | CLONOF^ name=moduleName |
---|
489 | { |
---|
490 | if(it->isClonof()) |
---|
491 | cout << "Warning: multiple definition of clonof module option, ambiguities are possible\n"; |
---|
492 | it->setClonof(name);} |
---|
493 | | HIDJAC { it->setHidjac(true); } // Hidden jackobien : adjoint direct like tapenade ... |
---|
494 | | NOADF |
---|
495 | { |
---|
496 | if(it->isOnAdf()) |
---|
497 | cout << "Warning: multiple definition of ONADF/NOADF module option, ambiguities are possible\n"; |
---|
498 | it->setOnAdf(false); |
---|
499 | } |
---|
500 | | ONADF { it->setOnAdf(true); } |
---|
501 | ; |
---|
502 | |
---|
503 | ctDefinition // Connection definition. CT*M constructs should be deprecated. |
---|
504 | { |
---|
505 | Connection connection; |
---|
506 | string name; |
---|
507 | bool ctinType=true; // True if CTIN, false if CTINM. |
---|
508 | } |
---|
509 | : |
---|
510 | ( CTIN^ | CTINM^ { ctinType=false; } |
---|
511 | ) |
---|
512 | name=moduleName { connection.setInModule(name); connection.setCtinType(ctinType); theConnectionTable.push_back(connection); } |
---|
513 | range[0] FROM! |
---|
514 | name=moduleName { Table<Connection>::iterator con = (theConnectionTable.end() - 1); con->setOutModule(name); } |
---|
515 | range[1] range_i ( range_jkt )? |
---|
516 | ; |
---|
517 | |
---|
518 | orderDefinition |
---|
519 | { |
---|
520 | Order ord(&theModulTable); |
---|
521 | string commonName, spaceNames; |
---|
522 | //string objectName("Soce"); |
---|
523 | vector<string> orderTokens; |
---|
524 | } |
---|
525 | : ORDER^ ( |
---|
526 | MODINSPACE |
---|
527 | objectName1:IDENTIFIER |
---|
528 | //commonName=spaceName |
---|
529 | { |
---|
530 | //objectName=commonName; |
---|
531 | int line = LT(1)->getLine(); |
---|
532 | commonName = objectName1->getText(); |
---|
533 | if(theSpaceTable.find(commonName)){ |
---|
534 | YAO_ENFORCE(theSpaceTable.find(commonName)->isCounterOrderHeader()==false) |
---|
535 | (line)("order error: that space or opera name (")(commonName)(") has already been met\n"); |
---|
536 | theSpaceTable.find(commonName)->setCounterOrderHeader(true); |
---|
537 | }else{ |
---|
538 | YAO_ENFORCE(theOperatorTable.find(commonName)->isCounterOrderHeader()==false) |
---|
539 | (line)("order error: that space or opera name (")(commonName)(") has already been met\n"); |
---|
540 | theOperatorTable.find(commonName)->setCounterOrderHeader(true); |
---|
541 | } |
---|
542 | ord.setOrderPhase(1); |
---|
543 | } |
---|
544 | |
---|
545 | /* objectName1:IDENTIFIER{ |
---|
546 | //objectName="Soce"; |
---|
547 | //objectName1->getText(); |
---|
548 | //if(theSpaceTable.find(objectName->getText())) |
---|
549 | // if(theSpaceTable.find(objectName)) |
---|
550 | { |
---|
551 | // Here the object reed is a space. |
---|
552 | YAO_ENFORCE(theSpaceTable.find(objectName)->isCounterOrderHeader()==false) |
---|
553 | (line)("order error: that space or opera name (")(objectName)(") has already been met\n"); |
---|
554 | theSpaceTable.find(objectName)->setCounterOrderHeader(true); |
---|
555 | cout << " space------------------------------------------ " << endl; |
---|
556 | ord.setOrderPhase(1); |
---|
557 | } |
---|
558 | }*//*else{ |
---|
559 | this->search(theOperatorTable, objectName); |
---|
560 | // Here the object reed is an operator. |
---|
561 | YAO_ENFORCE(theOperatorTable.find(objectName->getText())->isCounterOrderHeader()==false) |
---|
562 | (line)("order error: that space or opera name (")(objectName->getText())(") has already been met\n"); |
---|
563 | theOperatorTable.find(objectName->getText())->setCounterOrderHeader(true); |
---|
564 | cout << " operator " << endl; |
---|
565 | |
---|
566 | } |
---|
567 | ord.setOrderPhase(1); |
---|
568 | } |
---|
569 | */ |
---|
570 | |
---|
571 | |
---|
572 | // devo finire qui: aggiungere la possibilitC di avere un opera anche e non solo uno space |
---|
573 | |
---|
574 | //controllare l'esecuzione dello script sull'altra shell e quindi verificare bene che anche in rete pisces funziona |
---|
575 | |
---|
576 | ( modulOrder[orderTokens] { |
---|
577 | ord.orderTokens.insert(ord.orderTokens.end(), orderTokens.begin(), orderTokens.end()); |
---|
578 | orderTokens.clear(); |
---|
579 | } |
---|
580 | )+ |
---|
581 | |
---|
582 | | SPACEINTRAJ commonName=trajectoryName { |
---|
583 | int line = LT(1)->getLine(); |
---|
584 | YAO_ENFORCE(theTrajectoryTable.find(commonName)->isCounterOrder()==false) |
---|
585 | (line)("order error: that trajectory name (")(commonName)(") has already been met\n"); |
---|
586 | theTrajectoryTable.find(commonName)->setCounterOrder(true); |
---|
587 | ord.setOrderPhase(2); |
---|
588 | } |
---|
589 | ( spaceNames=spaceName { ord.orderTokens.push_back(spaceNames); } )+ |
---|
590 | ) FORDER! |
---|
591 | { |
---|
592 | ord.setName(commonName); |
---|
593 | theOrderTable.push_back(ord); |
---|
594 | } |
---|
595 | ; |
---|
596 | |
---|
597 | modulOrder[vector<string>& orderTokens] |
---|
598 | { |
---|
599 | int axe; |
---|
600 | string token; |
---|
601 | } |
---|
602 | : tok1:ORDER^ { orderTokens.push_back(tok1->getText()); } |
---|
603 | ( axe=axis { orderTokens.push_back(Order::translateAxe(axe)); } )+ |
---|
604 | ( token=moduleName |
---|
605 | { |
---|
606 | orderTokens.push_back(token); |
---|
607 | // Generate a warning if the module is already present in a directive order modinspace |
---|
608 | /*if(theModulTable.find(token)->isCounterOrder()){ |
---|
609 | cout << "WARNING: the module " << token << " appears more than once in order directive\n" |
---|
610 | << " you should rather use clone key word !?\n"; |
---|
611 | }else theModulTable.find(token)->setCounterOrder(true); |
---|
612 | */ |
---|
613 | } |
---|
614 | | modulOrder[orderTokens] )+ |
---|
615 | tok3:FORDER! { orderTokens.push_back(tok3->getText()); } |
---|
616 | ; |
---|
617 | |
---|
618 | insert_fctDeclaration |
---|
619 | { |
---|
620 | bool parameterized = false; |
---|
621 | string name; |
---|
622 | } |
---|
623 | : INSERT_FCT^ ( ARG { parameterized = true; } )? name=identifier |
---|
624 | { theFunctionTable.push_back(Function(name, parameterized)); } |
---|
625 | ; |
---|
626 | |
---|
627 | // Common syntax rules: identifier. |
---|
628 | identifier returns [std::string result] |
---|
629 | : name:IDENTIFIER |
---|
630 | { |
---|
631 | int line = LT(1)->getLine(); |
---|
632 | result = name->getText(); |
---|
633 | Table<Identifier>::const_pointer found = theIdentifierTable.find(result); |
---|
634 | YAO_ENFORCE(!found)(name->getLine())(line)(result)(" already declared line ")(found->getLine()); |
---|
635 | theIdentifierTable.push_back(Identifier(result, name->getLine())); |
---|
636 | } |
---|
637 | ; |
---|
638 | |
---|
639 | // Common syntax rules: literals. |
---|
640 | integerLiteral returns [std::string result] |
---|
641 | : value:INTEGER_LITERAL { result = value->getText(); } |
---|
642 | ; |
---|
643 | |
---|
644 | floatLiteral returns [std::string result] |
---|
645 | : value:FLOAT_LITERAL { result = value->getText(); } |
---|
646 | ; |
---|
647 | |
---|
648 | stringLiteral returns [std::string result] |
---|
649 | : value:STRING_LITERAL { result = value->getText(); } |
---|
650 | ; |
---|
651 | |
---|
652 | // Common syntax rules: constants. |
---|
653 | integerConstant returns [int result] |
---|
654 | { |
---|
655 | int line = LT(1)->getLine(); |
---|
656 | string value; |
---|
657 | } |
---|
658 | : ( value=integerLiteral |
---|
659 | | value=constantName { value = theConstantTable.find(value)->getText(); } |
---|
660 | ){ result = stream_cast<int>(value); } // Be carefull value cannot be greater then a 16 bit number (is a signed so 15 bit for positive number). |
---|
661 | exception catch [bad_cast] |
---|
662 | { YAO_REPORT(line)("can't convert ")(value)(" to integer"); } |
---|
663 | ; |
---|
664 | |
---|
665 | floatConstant returns [double result] |
---|
666 | { |
---|
667 | int line = LT(1)->getLine(); |
---|
668 | string value; |
---|
669 | } |
---|
670 | : ( value=integerLiteral |
---|
671 | | value=floatLiteral |
---|
672 | | value=constantName { value = theConstantTable.find(value)->getText(); } |
---|
673 | ) |
---|
674 | { result = stream_cast<double>(value); } |
---|
675 | exception catch [bad_cast] |
---|
676 | { YAO_REPORT(line)("can't convert ")(value)(" to floating point value"); } |
---|
677 | ; |
---|
678 | |
---|
679 | stringConstant returns [std::string result] |
---|
680 | { int line = LT(1)->getLine(); } |
---|
681 | : ( result=stringLiteral |
---|
682 | | result=constantName |
---|
683 | { |
---|
684 | result = theConstantTable.find(result)->getText(); |
---|
685 | YAO_ENFORCE(*result.begin() == '\"')(line)("can't convert ")(result)(" to quoted string"); |
---|
686 | } |
---|
687 | ) |
---|
688 | ; |
---|
689 | |
---|
690 | stringConstantList returns [std::vector<std::string> result] |
---|
691 | { string filename; } |
---|
692 | : ( filename=stringConstant { result.push_back(filename); } )+ |
---|
693 | ; |
---|
694 | |
---|
695 | positiveConstant returns [int result] |
---|
696 | { int line = LT(1)->getLine(); } |
---|
697 | : result=integerConstant { YAO_ENFORCE(result > 0)(line)("invalid size"); } |
---|
698 | ; |
---|
699 | |
---|
700 | // Common syntax rules: object names. |
---|
701 | constantName returns [std::string result] |
---|
702 | : name:IDENTIFIER { result = this->search(theConstantTable, name); } |
---|
703 | ; |
---|
704 | |
---|
705 | trajectoryName returns [std::string result] |
---|
706 | : name:IDENTIFIER { result = this->search(theTrajectoryTable, name); } |
---|
707 | ; |
---|
708 | |
---|
709 | spaceName returns [std::string result] |
---|
710 | : name:IDENTIFIER { result = this->search(theSpaceTable, name); } |
---|
711 | ; |
---|
712 | |
---|
713 | operatorName returns [std::string result] |
---|
714 | : name:IDENTIFIER { result = this->search(theOperatorTable, name); } |
---|
715 | ; |
---|
716 | |
---|
717 | neuronName returns [std::string result] |
---|
718 | : name:IDENTIFIER { result = this->search(theNeuronTable, name); } |
---|
719 | ; |
---|
720 | |
---|
721 | moduleName returns [std::string result] |
---|
722 | : name:IDENTIFIER { result = this->search(theModulTable, name); } |
---|
723 | ; |
---|
724 | |
---|
725 | // Common syntax rules: object attributes. |
---|
726 | trajectoryType returns [Trajectory::Type result] |
---|
727 | { |
---|
728 | int line = LT(1)->getLine(); |
---|
729 | string type = LT(1)->getText(); |
---|
730 | } |
---|
731 | : ( M | B | H | R | K | I | J | T | IDENTIFIER ) |
---|
732 | //We have included also the operators and the axes because these are keywords |
---|
733 | //(they are recognized like keywords from the lexer) and so |
---|
734 | //they are not normal IDENTIFIERs (the LA(1) value is different). |
---|
735 | { |
---|
736 | // Produces same error message as operatorType. |
---|
737 | YAO_ENFORCE(type.length() == 1)(line)("unexpected token: ")(type); |
---|
738 | result = type[0]; |
---|
739 | YAO_ENFORCE(result != '_')(line)("unexpected token: ")(type); |
---|
740 | } |
---|
741 | ; |
---|
742 | |
---|
743 | extent returns [std::vector<int> result] |
---|
744 | { |
---|
745 | int x; |
---|
746 | int y; |
---|
747 | int z; |
---|
748 | } |
---|
749 | : ( positiveConstant positiveConstant positiveConstant trajectoryName )=> |
---|
750 | x=positiveConstant y=positiveConstant z=positiveConstant |
---|
751 | { result.push_back(x); result.push_back(y); result.push_back(z); } |
---|
752 | | ( positiveConstant positiveConstant trajectoryName )=> |
---|
753 | x=positiveConstant y=positiveConstant |
---|
754 | { result.push_back(x); result.push_back(y); } |
---|
755 | | ( positiveConstant trajectoryName )=> |
---|
756 | x=positiveConstant { result.push_back(x); } |
---|
757 | ; |
---|
758 | |
---|
759 | operatorType returns [Operator::Type result] |
---|
760 | : H { result = Operator::H; } // Observation operator. |
---|
761 | | B { result = Operator::B; } // Background error covariance operator. |
---|
762 | | R { result = Operator::R; } // Observation error covariance operator. |
---|
763 | | K { result = Operator::K; } // Balance operator. |
---|
764 | ; |
---|
765 | |
---|
766 | modulParent returns [string name] |
---|
767 | : ( SPACE^ name=spaceName | OPERA^ name=operatorName ) |
---|
768 | ; |
---|
769 | |
---|
770 | axis returns [int axe] // Ascending or descending axis. |
---|
771 | : YA1 {axe=1;} | YB1 {axe=-1;} |
---|
772 | | YA2 {axe=2;} | YB2 {axe=-2;} |
---|
773 | | YA3 {axe=3;} | YB3{axe=-3;} |
---|
774 | ; |
---|
775 | |
---|
776 | // "parameterNumber" is a number that identifies the actual position we are parsing in the directive. This is in order to understand |
---|
777 | // which type of range we are managing: 0 is for the input range, 1 is for the output range, 2/3/4/5 are for the i/j/k/t respectively. |
---|
778 | range[short parameterNumber] |
---|
779 | { |
---|
780 | Table<Connection>::iterator con = (theConnectionTable.end() - 1); |
---|
781 | int begin=0, end=0; |
---|
782 | } |
---|
783 | : begin=integerConstant ( DOT_DOT^ end=integerConstant )? |
---|
784 | {con->setAbsoluteInterval(begin, end, parameterNumber);} |
---|
785 | ; |
---|
786 | |
---|
787 | range_i |
---|
788 | { |
---|
789 | Table<Connection>::iterator con = (theConnectionTable.end() - 1); |
---|
790 | int value=0; |
---|
791 | } |
---|
792 | : range[2] |
---|
793 | | I ( rangeOperator:MODULO^ value=integerConstant )? |
---|
794 | { |
---|
795 | if(value) |
---|
796 | con->setRelativeInterval(rangeOperator->getText(), value, 2); |
---|
797 | else con->setRelativeInterval("", 0, 2); |
---|
798 | } |
---|
799 | ; |
---|
800 | |
---|
801 | range_jkt |
---|
802 | : ( range_j range_k range_t )=> range_j range_k range_t |
---|
803 | | ( range_j range_k )=> range_j range_k |
---|
804 | | ( range_j range_t )=> range_j range_t |
---|
805 | | ( range_j )=> range_j |
---|
806 | | range_t |
---|
807 | ; |
---|
808 | |
---|
809 | range_j |
---|
810 | { |
---|
811 | Table<Connection>::iterator con = (theConnectionTable.end() - 1); |
---|
812 | int value=0; |
---|
813 | } |
---|
814 | : range[3] |
---|
815 | | J ( rangeOperator:MODULO^ value=integerConstant )? |
---|
816 | { |
---|
817 | if(value) |
---|
818 | con->setRelativeInterval(rangeOperator->getText(), value, 3); |
---|
819 | else con->setRelativeInterval("", 0, 3); |
---|
820 | } |
---|
821 | ; |
---|
822 | |
---|
823 | range_k |
---|
824 | { |
---|
825 | Table<Connection>::iterator con = (theConnectionTable.end() - 1); |
---|
826 | int value=0; |
---|
827 | } |
---|
828 | : range[4] |
---|
829 | | K ( rangeOperator:MODULO^ value=integerConstant )? |
---|
830 | { if(value) |
---|
831 | con->setRelativeInterval(rangeOperator->getText(), value, 4); |
---|
832 | else con->setRelativeInterval("", 0, 4); |
---|
833 | } |
---|
834 | ; |
---|
835 | |
---|
836 | range_t |
---|
837 | { |
---|
838 | Table<Connection>::iterator con = (theConnectionTable.end() - 1); |
---|
839 | int value=0; |
---|
840 | } |
---|
841 | : range[5] |
---|
842 | | (tT:T ( rangeOperator:MODULO^ value=integerConstant )? |
---|
843 | { if(tT->getText() == "t"){ // 't' case. |
---|
844 | if(value) |
---|
845 | con->setRelativeInterval(rangeOperator->getText(), value, 5); |
---|
846 | else con->setRelativeInterval("", 0, 5); |
---|
847 | }else{ // 'T' case. |
---|
848 | int line = LT(1)->getLine(); |
---|
849 | YAO_ENFORCE( theModulTable.find(con->getOutModule())->getTrajectory() != theModulTable.find(con->getInModule())->getTrajectory() ) |
---|
850 | (line)("ctin directive: capital T index should be used only when different trajectories\n"); |
---|
851 | if(value) |
---|
852 | con->setRelativeInterval(rangeOperator->getText(), value, 6); |
---|
853 | else con->setRelativeInterval("", 0, 6); |
---|
854 | } |
---|
855 | } |
---|
856 | ) |
---|
857 | ; |
---|
858 | |
---|
859 | |
---|
860 | {bool warning = false;} // For the warning message of deprecated comment. We want print just one time. |
---|
861 | /** |
---|
862 | * \class yao::BaseLexer |
---|
863 | * \brief BaseLexer class, handles whitespaces, comments, identifiers, literals (integer, float, string) and ranges. |
---|
864 | * The lexing recognizes all the token of the description file. |
---|
865 | * All the tokens are given to the parser in a second stage. |
---|
866 | */ |
---|
867 | class BaseLexer extends Lexer; |
---|
868 | options |
---|
869 | { |
---|
870 | k = 2; // Fixed look-ahead. |
---|
871 | charVocabulary = '\0'..'\377'; // Sets allowed lexer characters. |
---|
872 | defaultErrorHandler = false; // Turns off default exception handling. |
---|
873 | testLiterals = false; // Turns off tokens testing against reserved keywords. |
---|
874 | caseSensitiveLiterals = false; // Ignores case for reserved keywords. |
---|
875 | } |
---|
876 | |
---|
877 | tokens // Reserved keywords (identifiers). |
---|
878 | { |
---|
879 | // Old syntax keywords. |
---|
880 | EXEC = "exec"; |
---|
881 | EXIT = "exit"; |
---|
882 | DISP_DEFVAL = "disp_defval"; |
---|
883 | DISP_TRAJ = "disp_traj"; |
---|
884 | DISP_SPACE = "disp_space"; |
---|
885 | DISP_OPERA = "disp_opera"; |
---|
886 | DISP_NETWARD = "disp_netward"; |
---|
887 | DISP_MODUL = "disp_modul"; |
---|
888 | DISP_CT_IN = "disp_ct_in"; |
---|
889 | DISP_CT_OUT = "disp_ct_out"; |
---|
890 | DISP_FLAGOP = "disp_flagop"; |
---|
891 | DISP_OPTION = "disp_option"; |
---|
892 | DEFVAL = "defval"; |
---|
893 | HAT_NAME = "hat_name"; |
---|
894 | O_TOOL = "O_TOOL"; |
---|
895 | O_REAL = "O_REAL"; |
---|
896 | FLOAT = "float"; |
---|
897 | DOUBLE = "double"; |
---|
898 | O_EXTOBJ = "O_EXTOBJ"; |
---|
899 | O_NETWARD = "O_NETWARD"; |
---|
900 | O_M1QN3 = "O_M1QN3"; |
---|
901 | O_VARINCR = "O_VARINCR"; |
---|
902 | O_AUTODF = "O_AUTODF"; |
---|
903 | ALL = "all"; // option of O_AUTODF : all the modules |
---|
904 | ONLY = "only"; // option of O_AUTODF : only some modules |
---|
905 | O_GRADTEST = "O_GRADTEST"; |
---|
906 | O_DBG_NANF = "O_DBG_NANF"; |
---|
907 | O_DBG_TING = "O_DBG_TING"; |
---|
908 | O_DBG_BETA = "O_DBG_BETA"; |
---|
909 | O_DBG_TRC_FWARD = "O_DBG_TRC_FWARD"; |
---|
910 | O_DBG_TRC_BWARD = "O_DBG_TRC_BWARD"; |
---|
911 | O_DBG_TRC_LWARD = "O_DBG_TRC_LWARD"; |
---|
912 | O_DBG_TRC_AWARD = "O_DBG_TRC_AWARD"; |
---|
913 | TRAJ = "traj"; |
---|
914 | M = "M"; |
---|
915 | SPACE = "space"; |
---|
916 | OPERA = "opera"; |
---|
917 | NETWARD = "netward"; |
---|
918 | MODUL = "modul"; |
---|
919 | NOWARD = "noward"; |
---|
920 | INTER = "inter"; |
---|
921 | YA1 = "YA1"; |
---|
922 | YA2 = "YA2"; |
---|
923 | YA3 = "YA3"; |
---|
924 | YB1 = "YB1"; |
---|
925 | YB2 = "YB2"; |
---|
926 | YB3 = "YB3"; |
---|
927 | ARRAY = "array"; |
---|
928 | TARGET = "target"; |
---|
929 | UPTIME = "uptime"; |
---|
930 | STEPTIME = "steptime"; |
---|
931 | ALLTIME = "alltime"; |
---|
932 | TEMPO = "tempo"; |
---|
933 | COUT = "cout"; |
---|
934 | LOPERA = "lopera"; |
---|
935 | COVT = "covt"; |
---|
936 | SPEC = "spec"; |
---|
937 | AUTONET = "autonet"; |
---|
938 | CLONOL = "clonol"; |
---|
939 | CLONOF = "clonof"; |
---|
940 | HIDJAC = "hidjac"; |
---|
941 | NOADF = "noadf"; |
---|
942 | ONADF = "onadf"; |
---|
943 | CTIN = "ctin"; |
---|
944 | CTINM = "ctinm"; |
---|
945 | INSERT_FCT = "insert_fct"; |
---|
946 | ARG = "arg"; |
---|
947 | MODINSPACE = "modinspace"; |
---|
948 | SPACEINTRAJ = "spaceintraj"; |
---|
949 | FORDER = "forder"; |
---|
950 | |
---|
951 | // Common keywords. |
---|
952 | HELP = "help"; |
---|
953 | INPUT = "input"; |
---|
954 | OUTPUT = "output"; |
---|
955 | OPTION = "option"; |
---|
956 | M2QN1 = "M2QN1"; |
---|
957 | H = "H"; |
---|
958 | B = "B"; |
---|
959 | R = "R"; |
---|
960 | K = "K"; |
---|
961 | FROM = "from"; |
---|
962 | TO = "to"; |
---|
963 | I = "i"; |
---|
964 | J = "j"; |
---|
965 | T = "t"; |
---|
966 | ORDER = "order"; |
---|
967 | } |
---|
968 | |
---|
969 | { |
---|
970 | |
---|
971 | public: |
---|
972 | |
---|
973 | virtual ~BaseLexer() {} //!< Destructor. |
---|
974 | } |
---|
975 | |
---|
976 | WHITESPACE // Space or newline (increments line count). |
---|
977 | : ( ' ' | '\t' | '\f' | ( "\r\n" | '\r' | '\n' ) { newline(); } ) |
---|
978 | { $setType(Token::SKIP); |
---|
979 | setColumn(1); // This is added for the condition getColumn() == 1 in the DEPRECATEDCOMMENT rule ; |
---|
980 | } |
---|
981 | ; |
---|
982 | |
---|
983 | // Single line comment '//' ('#' and '|' are deprecated but |
---|
984 | // for compatibility with precedents Yao applications we consider also these cases). |
---|
985 | DEPRECATEDCOMMENT // Deprecated comment '#'. |
---|
986 | : {getColumn() == 1}? '#' ( ~( '\n' | '\r' ) )* ( '\n' | '\r' ) |
---|
987 | {if(!warning) |
---|
988 | cout << " Warning: use of '#' for comments is deprecated, use C notation '//'" << endl; |
---|
989 | warning = true; |
---|
990 | newline(); |
---|
991 | $setType(Token::SKIP); |
---|
992 | }; |
---|
993 | |
---|
994 | COMMENT |
---|
995 | : ("//" |
---|
996 | | '|' //deprecated comment | |
---|
997 | { |
---|
998 | if(!warning) |
---|
999 | cout << " Warning: use of '|' for comments is deprecated, use C notation '//'" << endl; |
---|
1000 | warning = true; |
---|
1001 | } |
---|
1002 | ) |
---|
1003 | ( ~( '\n' | '\r' ) )* ( '\n' | '\r' ) { newline(); $setType(Token::SKIP); }; |
---|
1004 | |
---|
1005 | IDENTIFIER // Identifier or reserved keyword. |
---|
1006 | options { |
---|
1007 | paraphrase = "an identifier "; // Makes error messages more readable. |
---|
1008 | testLiterals = true; // Tests identifiers against reserved keywords. |
---|
1009 | } |
---|
1010 | : ( 'a'..'z' | 'A'..'Z' | '_' ) ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' )* ; |
---|
1011 | |
---|
1012 | INTEGER_LITERAL // Base 10 integer. |
---|
1013 | options { paraphrase = "an integer value"; } // Makes error messages more readable. |
---|
1014 | : ( '0'..'9' )+ |
---|
1015 | ( { (LA(2) != '.') }? '.' ( '0'..'9' )* ( EXPONENT )? |
---|
1016 | { $setType(FLOAT_LITERAL); } // Left factoring. |
---|
1017 | | ( EXPONENT { $setType(FLOAT_LITERAL); } )? // Left factoring. |
---|
1018 | ); |
---|
1019 | |
---|
1020 | protected |
---|
1021 | EXPONENT |
---|
1022 | : ( 'e' | 'E' ) ( '+' | '-' )? ( '0'..'9' )+ |
---|
1023 | ; |
---|
1024 | |
---|
1025 | FLOAT_LITERAL // Floating point value. |
---|
1026 | options { paraphrase = "a floating point value";} // Makes error messages more readable. |
---|
1027 | : '.' ( '0'..'9' )+ ( EXPONENT )? |
---|
1028 | ; |
---|
1029 | |
---|
1030 | STRING_LITERAL // Single line quoted string. |
---|
1031 | options { paraphrase = "a quoted string"; } // Makes error messages more readable. |
---|
1032 | : '"' (' ' | '\t')* ( 'a'..'z' | 'A'..'Z' | '_' | '-' | '.'| '0'..'9' )+ (' ' | '\t')* '"' |
---|
1033 | ; |
---|
1034 | |
---|
1035 | /*STRING_LITERAL // Single line quoted string. |
---|
1036 | options { paraphrase = "a quoted string"; } // Makes error messages more readable. |
---|
1037 | : '"' ( '\\' ( 'b' | 't' | 'n' | 'f' | 'r' | "\"" | '\'' | '\\' ) |
---|
1038 | | ~( '\\' | '\"' | '\n' | '\r' ) )* '"' |
---|
1039 | ; |
---|
1040 | */ |
---|
1041 | DOT_DOT // Absolute range operator. |
---|
1042 | : ".." |
---|
1043 | ; |
---|
1044 | |
---|
1045 | MODULO // Relative range operator. |
---|
1046 | : '+' |
---|
1047 | | '-' |
---|
1048 | | '~' |
---|
1049 | | "%+" |
---|
1050 | | "%-" |
---|
1051 | | "%~" |
---|
1052 | | "#+" |
---|
1053 | | "#-" |
---|
1054 | | "#~" |
---|
1055 | ; |
---|