00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #ifndef __EBNF_LA_NODE_HH__
00068 #define __EBNF_LA_NODE_HH__
00069
00070 #include <string>
00071 #include <vector>
00072 using namespace std;
00073
00074 #include "ebnf_node.hh"
00075 #include "vbitset.hh"
00076 #include "numbered_la_spec.hh"
00077 #include "catch_clause.hh"
00078
00079 class TokenDesc;
00080 class ITokenSpec;
00081
00086 class EbnfLaNode : public EbnfNode
00087 {
00088
00089 public:
00090
00095 EbnfLaNode (const Position &pos_, NumberedLaSpec *laSpec_ = NULL) :
00096 EbnfNode(pos_), laSpec(laSpec_)
00097 {}
00098
00103 EbnfLaNode (const EbnfLaNode &o) :
00104 EbnfNode(o.getPos()),
00105 laSpec(o.laSpec != NULL ? dynamic_cast<NumberedLaSpec*>(o.laSpec->clone())
00106 : NULL),
00107 first(o.first), follow(o.follow), nullable(o.nullable),
00108 startCode(o.startCode), endCode(o.endCode),
00109 forceStartCode(o.forceStartCode), forceEndCode(o.forceEndCode),
00110 catchList(o.catchList), colour(o.colour)
00111 {}
00112
00113 ~EbnfLaNode ()
00114 {
00115 if (laSpec != NULL) delete laSpec;
00116 }
00117
00118 #ifdef DEBUG
00119 protected:
00120
00121 static int indent_level;
00122
00123 static void indent()
00124 {
00125 indent_level++;
00126 }
00127
00128 static void unindent ()
00129 {
00130 indent_level--;
00131 }
00132
00133 static ostream& format (ostream &os)
00134 {
00135 for (int i = 0; i < indent_level; i++)
00136 os << " ";
00137 return os;
00138 }
00139 void dumpAttributes (ostream &os) const;
00140
00141 public:
00142
00143 static ITokenSpec *tokens;
00144 #endif
00145
00146 public:
00147
00151 NumberedLaSpec *laSpec;
00152
00157 CodeChunk startCode;
00158
00163 CodeChunk endCode;
00164
00165 bool forceStartCode, forceEndCode;
00166
00171 vector<CatchClause> catchList;
00172
00178 vBitset first;
00179
00185 vBitset follow;
00186
00193 bool nullable;
00194
00198 typedef enum { white, grey, black } Colours;
00199
00207 Colours colour;
00208 };
00209
00210
00215 class EbnfOrNode : public EbnfLaNode
00216 {
00217 public:
00218
00219 EbnfOrNode (EbnfLaNode *pre_, EbnfLaNode *post_,
00220 const Position &pos_) :
00221 EbnfLaNode(pos_),
00222 pre(pre_), post(post_)
00223 {}
00224
00225 EbnfOrNode (const EbnfOrNode &o) :
00226 EbnfLaNode(o),
00227 pre(dynamic_cast<EbnfLaNode*>(o.pre->clone())),
00228 post(dynamic_cast<EbnfLaNode*>(o.post->clone()))
00229 {}
00230
00231 virtual EbnfNode& operator [] (int index)
00232 {
00233 ASSERT((0 <= index) && (index <= 1),
00234 "Bad index in EbnfOrNode::operator []");
00235 return index ? *post : *pre;
00236 }
00237
00238 virtual EbnfNode* clone ()
00239 {
00240 return new EbnfOrNode(*this);
00241 }
00242
00243 virtual int getChildCount ()
00244 {
00245 return 2;
00246 }
00247
00248 virtual ~EbnfOrNode ()
00249 {
00250 delete pre;
00251 delete post;
00252 }
00253
00254 #ifdef DEBUG
00255
00256 virtual void dump (ostream &os) const;
00257
00258 #endif
00259
00260 public:
00261
00265 EbnfLaNode *pre;
00266
00270 EbnfLaNode *post;
00271 };
00272
00273
00278 class EbnfCatNode : public EbnfLaNode
00279 {
00280 public:
00281
00282 EbnfCatNode (EbnfLaNode *pre_, EbnfLaNode *post_,
00283 const Position &pos_) :
00284 EbnfLaNode(pos_),
00285 pre(pre_), post(post_)
00286 {}
00287
00288 EbnfCatNode (const EbnfCatNode &o) :
00289 EbnfLaNode(o),
00290 pre(dynamic_cast<EbnfLaNode*>(o.pre->clone())),
00291 post(dynamic_cast<EbnfLaNode*>(o.post->clone()))
00292 {}
00293
00294 virtual EbnfNode& operator [] (int index)
00295 {
00296 ASSERT((0 <= index) && (index <= 1),
00297 "Bad index in EbnfCatNode::operator []");
00298 return index ? *post : *pre;
00299 }
00300
00301 virtual int getChildCount ()
00302 {
00303 return 2;
00304 }
00305
00306 virtual EbnfNode* clone ()
00307 {
00308 return new EbnfCatNode(*this);
00309 }
00310
00311 virtual ~EbnfCatNode ()
00312 {
00313 delete pre;
00314 delete post;
00315 }
00316
00317 #ifdef DEBUG
00318
00319 virtual void dump (ostream &os) const;
00320
00321 #endif
00322
00323 public:
00324
00328 EbnfLaNode *pre;
00329
00333 EbnfLaNode *post;
00334 };
00335
00336
00341 class EbnfStarNode : public EbnfLaNode
00342 {
00343 public:
00344
00345 EbnfStarNode (EbnfLaNode *in_,
00346 const Position &pos_) :
00347 EbnfLaNode(pos_),
00348 in(in_)
00349 {}
00350
00351 EbnfStarNode (const EbnfStarNode &o) :
00352 EbnfLaNode(o),
00353 in(dynamic_cast<EbnfLaNode*>(o.in->clone()))
00354 {}
00355
00356 virtual EbnfNode& operator [] (int index)
00357 {
00358 ASSERT((0 == index),
00359 "Bad index in EbnfStarNode::operator []");
00360 return *in;
00361 }
00362
00363 virtual int getChildCount ()
00364 {
00365 return 1;
00366 }
00367
00368 virtual EbnfNode* clone ()
00369 {
00370 return new EbnfStarNode(*this);
00371 }
00372
00373 virtual ~EbnfStarNode ()
00374 {
00375 delete in;
00376 }
00377
00378
00379 #ifdef DEBUG
00380
00381 virtual void dump (ostream &os) const;
00382
00383 #endif
00384
00385 public:
00386
00390 EbnfLaNode *in;
00391 };
00392
00393
00397 class EbnfNonterminalNode : public EbnfLaNode
00398 {
00399 public:
00400
00401 EbnfNonterminalNode (const string &targetVar_, const Position &targetVarPos_,
00402 const string &nontermName_,
00403 const string &actualArgs_, const Position &argsPos_,
00404 const Position &pos_) :
00405 EbnfLaNode(pos_),
00406 targetVar(targetVarPos_, targetVar_),
00407 nontermName(nontermName_), actualArgs(argsPos_, actualArgs_)
00408 {}
00409
00410 EbnfNonterminalNode (const EbnfNonterminalNode &o) :
00411 EbnfLaNode(o),
00412 targetVar(o.targetVar), nontermName(o.nontermName),
00413 actualArgs(o.actualArgs)
00414 {}
00415
00416 virtual EbnfNode& operator [] (int index)
00417 {
00418 ASSERT(0, "EbnfNonterminalNode::operator [] called !");
00419 return * (EbnfNode*) NULL;
00420 }
00421
00422 virtual int getChildCount ()
00423 {
00424 return 0;
00425 }
00426
00427 virtual EbnfNode* clone ()
00428 {
00429 return new EbnfNonterminalNode(*this);
00430 }
00431
00432 #ifdef DEBUG
00433
00434 virtual void dump (ostream &os) const;
00435
00436 #endif
00437
00438 public:
00439
00445 CodeChunk targetVar;
00446
00450 string nontermName;
00451
00456 CodeChunk actualArgs;
00457
00463 EbnfLaNode *nonterm;
00464 };
00465
00466
00470 class EbnfTerminalNode : public EbnfLaNode
00471 {
00472 public:
00473
00474 EbnfTerminalNode (TokenDesc &terminal_,
00475 const Position &pos_) :
00476 EbnfLaNode(pos_),
00477 terminal(terminal_)
00478 {}
00479
00480 EbnfTerminalNode (const EbnfTerminalNode &o) :
00481 EbnfLaNode(o),
00482 terminal(o.terminal)
00483 {}
00484
00485
00486 virtual EbnfNode& operator [] (int index)
00487 {
00488 ASSERT(0, "EbnfTerminalNode::operator [] called !");
00489 return * (EbnfNode*) NULL;
00490 }
00491
00492 virtual int getChildCount ()
00493 {
00494 return 0;
00495 }
00496
00497 virtual EbnfNode* clone ()
00498 {
00499 return new EbnfTerminalNode(*this);
00500 }
00501
00502 #ifdef DEBUG
00503
00504 virtual void dump (ostream &os) const;
00505
00506 #endif
00507
00508 public:
00509
00514 TokenDesc &terminal;
00515 };
00516
00517
00521 class EbnfLambdaNode : public EbnfLaNode
00522 {
00523 public:
00524
00525 EbnfLambdaNode (const Position &pos_) :
00526 EbnfLaNode(pos_)
00527 {}
00528
00529 EbnfLambdaNode (const EbnfLambdaNode &o) :
00530 EbnfLaNode(o)
00531 {}
00532
00533 virtual EbnfNode& operator [] (int index)
00534 {
00535 ASSERT(0, "EbnfLambdaNode::operator [] called !");
00536 return *(EbnfNode*) NULL;
00537 }
00538
00539 virtual int getChildCount ()
00540 {
00541 return 0;
00542 }
00543
00544 virtual EbnfNode* clone ()
00545 {
00546 return new EbnfLambdaNode(*this);
00547 }
00548
00549 #ifdef DEBUG
00550
00551 virtual void dump (ostream &os) const;
00552
00553 #endif
00554
00555 };
00556
00557
00558 #endif