changes_from_1.31
来自「本工具提供一个词法分析器和语法分析器的集成开发环境」· 31 代码 · 共 523 行 · 第 1/2 页
31
523 行
From robertb@oakhill.sps.mot.com Bob Bailey. Changed ANTLR C++ outputto avoid an error in Sun C++ 3.0.1. Made "public" return valuestructs created to hold multiple return values public.--------------------------------------------------------6 genmkFixed genmk so that target List.* is not included anymore. It'scalled SList.* anyway.--------------------------------------------------------7 \r vs \nScott Vorthmann <vorth@cmu.edu> fixed antlr.g in ANTLR so that \ris allowed as the return character as well as \n.--------------------------------------------------------8 ExceptionsBug in exceptions attached to labeled token/tokclass references. Didn't gencode for exceptions. This didn't work:a : "help" x:ID ; exception[x] catch MismatchedToken : <<printf("eh?\n");>>Now ANTLR generates (which is kinda big, but necessary): if ( !_match_wsig(ID) ) { if ( guessing ) goto fail; _signal=MismatchedToken; switch ( _signal ) { case MismatchedToken : printf("eh?\n"); _signal = NoSignal; break; default : goto _handler; } }which implies that you can recover and continue parsing after a missing/badtoken reference.--------------------------------------------------------9 genmkgenmk now correctly uses config file for CPP_FILE_SUFFIX stuff.--------------------------------------------------------10 general cleanup / PURIFYAnthony Green <green@vizbiz.com> suggested a bunch of good generalclean up things for the code; he also suggested a few things tohelp out the "PURIFY" memory allocation checker.--------------------------------------------------------11 $-variable references.Manuel ORNATO indicated that a $-variable outside of a rule causedANTLR to crash. I fixed this.12 Tom Moog suggestionFail action of semantic predicate needs "{}" envelope. FIXED.13 references to LT(1).I have enclosed all assignments such as: _t22 = (ANTLRTokenPtr)LT(1);in "if ( !guessing )" so that during backtracking the reference countfor token objects is not increased.TOKEN OBJECT GARBAGE COLLECTION1 INTRODUCTIONThe class ANTLRCommonToken is now garbaged collected through a "smart"pointer called ANTLRTokenPtr using reference counting. Any tokenobject not referenced by your grammar actions is destroyed by theANTLRTokenBuffer when it must make room for more token objects.Referenced tokens are then destroyed in your parser when localANTLRTokenPtr objects are deleted. For example,a : label:ID ;would be converted to something like:void yourclass::a(void){ zzRULE; ANTLRTokenPtr label=NULL; // used to be ANTLRToken *label; zzmatch(ID); label = (ANTLRTokenPtr)LT(1); consume(); ...}When the "label" object is destroyed (it's just a pointer to yourinput token object LT(1)), it decrements the reference count on theobject created for the ID. If the count goes to zero, the objectpointed by label is deleted.To correctly manage the garbage collection, you should useANTLRTokenPtr instead of "ANTLRToken *". Most ANTLR support code(visible to the user) has been modified to use the smart pointers.***************************************************************Remember that any local objects that you create are not deleted when alonjmp() is executed. Unfortunately, the syntactic predicates (...)?use setjmp()/longjmp(). There are some situations when a few tokenswill "leak".***************************************************************2 DETAILSo The default is to perform token object garbage collection. You may use parser->noGarbageCollectTokens() to turn off garbage collection.o The type ANTLRTokenPtr is always defined now (automatically). If you do not wish to use smart pointers, you will have to redefined ANTLRTokenPtr by subclassing, changing the header file or changing ANTLR's code generation (easy enough to do in gen.c).o If you don't use ParserBlackBox, the new initialization sequence is: ANTLRTokenPtr aToken = new ANTLRToken; scan.setToken(mytoken(aToken)); where mytoken(aToken) gets an ANTLRToken * from the smart pointer.o Define C++ preprocessor symbol DBG_REFCOUNTTOKEN to see a bunch of debugging stuff for reference counting if you suspect something.3 WHY DO I HAVE TO TYPECAST ALL MY TOKEN POINTERS NOW??????If you subclass ANTLRCommonToken and then attempt to refer to one ofyour token members via a token pointer in your grammar actions, theC++ compiler will complain that your token object does not have thatmember. For example, if you used to do this<<class ANTLRToken : public ANTLRCommonToken { int muck; ...};>>class Foo {a : t:ID << t->muck = ...; >> ;}Now, you must do change the t->muck reference to:a : t:ID << mytoken(t)->muck = ...; >> ;in order to downcast 't' to be an "ANTLRToken *" not the"ANTLRAbstractToken *" resulting from ANTLRTokenPtr::operator->().The macro is defined as:/* * Since you cannot redefine operator->() to return one of the user's * token object types, we must down cast. This is a drag. Here's * a macro that helps. template: "mytoken(a-smart-ptr)->myfield". */#define mytoken(tp) ((ANTLRToken *)(tp.operator->()))You have to use macro mytoken(grammar-label) now because smartpointers are not specific to a parser's token objects. In otherwords, the ANTLRTokenPtr class has a pointer to a genericANTLRAbstractToken not your ANTLRToken; the ANTLR support code mustuse smart pointers too, but be able to work with any kind ofANTLRToken. Sorry about this, but it's C++'s fault not mine. Somenebulous future version of the C++ compilers should obviate the needto downcast smart pointers with runtime type checking (and by allowingdifferent return type of overridden functions).A way to have backward compatible code is to shut off the token objectgarbage collection; i.e., use parser->noGarbageCollectTokens() andchange the definition of ANTLRTokenPtr (that's why you get source code<wink>).PARSER EXCEPTION HANDLINGI've noticed some weird stuff with the exception handling. I intendto give this top priority for the "book release" of ANTLR.==========1.32 Full Releaseo Changed Token class hierarchy to be (Thanks to Tom Moog): ANTLRAbstractToken ANTLRRefCountToken ANTLRCommonToken ANTLRNoRefCountCommonTokeno Added virtual panic() to ANTLRAbstractToken. Made ANTLRParser::panic() virtual also.o Cleaned up the dup() stuff in AST hierarchy to use shallowCopy() to make node copies. John Farr at Medtronic suggested this. I.e., if you want to use dup() with either ANTLR or SORCERER or -transform mode with SORCERER, you must defined shallowCopy() as: virtual PCCTS_AST *shallowCopy() { return new AST; p->setDown(NULL); p->setRight(NULL); return p; } or virtual PCCTS_AST *shallowCopy() { return new AST(*this); } if you have defined a copy constructor such as AST(const AST &t) // shallow copy constructor { token = t.token; iconst = t.iconst; setDown(NULL); setRight(NULL); }o Added a warning with -CC and -gk are used together. This is broken, hence a warning is appropriate.o Added warning when #-stuff is used w/o -gt option.o Updated MPW installation.o "Miller, Philip W." <MILLERPW@f1groups.fsd.jhuapl.edu> suggested that genmk be use RENAME_OBJ_FLAG RENAME_EXE_FLAG instead of hardcoding "-o" in genmk.c.o made all exit() calls use EXIT_SUCCESS or EXIT_FAILURE.===========================================================================1.33EXIT_FAILURE and EXIT_SUCCESS were not always defined. I had to modifya bunch of files to use PCCTS_EXIT_XXX, which forces a new version. Sorryabout that.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?