changes_from_1.31
来自「本工具提供一个词法分析器和语法分析器的集成开发环境」· 31 代码 · 共 523 行 · 第 1/2 页
31
523 行
CHANGES FROM 1.31This file contains the migration of PCCTS from 1.31 in the order thatchanges were made. 1.32b7 is the last beta before full 1.32.Terence Parr, Parr Research Corporation 1995.======================================================================1.32b1Added Russell Quong to banner, changed banner for output slightlyFixed it so that you have before / after actions for C++ in class defFixed bug in optimizer that made it sometimes forget to set internal token pointers. Only showed up when a {...} was in the "wrong spot".======================================================================1.32b2Added fixes by Dave Seidel for PC compilers in 32 bit mode (config.hand set.h).======================================================================1.32b3Fixed hideous bug in code generator for wildcard and for ~token op.from Dave Seidel Added pcnames.bat 1. in antlr/main.c: change strcasecmp() to stricmp() 2. in dlg/output.c: use DLEXER_C instead on "DLexer.C" 3. in h/PBlackBox.h: use <iostream.h> instead of <stream.h>======================================================================1.32b4When the -ft option was used, any path prefix screwed upthe gate on the .h filesFixed yet another bug due to the optimizer.The exception handling thing was a bit wacko:a : ( A B )? A B | A C ; exception ...caused an exception if "A C" was the input. In other words,it found that A C didn't match the (A B)? pred and causedan exception rather than trying the next alt. All I didwas to change the zzmatch_wsig() macros.Fixed some problems in gen.c relating to the name of tokenclass bit sets in the output.Added the tremendously cool generalized predicate. For themoment, I'll give this bried description.a : <<predicate>>? blah | foo ;This implies that (assuming blah and foo are syntacticallyambiguous) "predicate" indicates the semantic validity ofapplying "blah". If "predicate" is false, "foo" is attempted.Previously, you had to say:a : <<LA(1)==ID ? predicate : 1>>? ID | ID ;Now, you can simply use "predicate" without the ?: operatorif you turn on ANTLR command line option: "-prc on". Thistells ANTLR to compute that all by itself. It computes ntokens of lookahead where LT(n) or LATEXT(n) is the farthestahead you look.If you give a predicate using "-prc on" that is followedby a construct that can recognize more than one n-sequence,you will get a warning from ANTLR. For example,a : <<isTypeName(LT(1)->getText())>>? (ID|INT) ;This is wrong because the predicate will be applied to INTsas well as ID's. You should use this syntax to makethe predicate more specific:a : (ID)? => <<isTypeName(LT(1)->getText())>>? (ID|INT) ;which says "don't apply the predicate unless ID is thecurrent lookahead context".You cannot currently have anything in the "(context)? =>"except sequences such as:( LPAREN ID | LPAREN SCOPE )? => <<pred>>?I haven't tested this THAT much, but it does work for theC++ grammar.======================================================================1.32b5Added getLine() to the ANTLRTokenBase and DLGBasedToken classesleft line() for backward compatibility.----Removed SORCERER_TRANSFORM from the ast.h stuff.-------Fixed bug in code gen of ANTLR such that nested syn preds work moreefficiently now. The ANTLRTokenBuffer was getting very largewith nested predicates.------Memory leak is now gone from ANTLRTokenBuf; all tokens are deleted.For backward compatibility reasons, you have to say parser->deleteTokens()or mytokenbuffer->deleteTokens() but later it will be the default mode.Say this after the parser is constructed. E.g., ParserBlackBox<DLGLexer, MyParser, ANTLRToken> p(stdin); p.parser()->deleteTokens(); p.parser()->start_symbol();==============================1.32b6Changed so that deleteTokens() will do a delete ((ANTLRTokenBase *))on the ptr. This gets the virtual destructor.Fixed some weird things in the C++ header files (a few return types).Made the AST routines correspond to the book and SORCERER stuff.New token stuff: See testcpp/14/test.gANTLR accepts a #pragma gc_tokens which says[1] Generate label = copy(LT(1)) instead of label=LT(1) for all labeled token references.[2] User now has to define ANTLRTokenPtr (as a class or a typedef to just a pointer) as well as the ANTLRToken class itself. See the example.To delete tokens in token buffer, use deleteTokens() message on parser. All tokens that fall off the ANTLRTokenBuffer get deleted which is what currently happens when deleteTokens() message has been sent to token buffer.We always generate ANTLRTokenPtr instead of 'ANTLRToken *' now.Then if no pragma set, ANTLR generates a class ANTLRToken; typedef ANTLRToken *ANTLRTokenPtr;in each file.Made a warning for x:rule_ref <<$x>>; still no warning for $i's, however.class BB {a : x:b y:A <<$x$y>> ;b : B;}generatesAntlr parser generator Version 1.32b6 1989-1995test.g, line 3: error: There are no token ptrs for rule references: '$x'===================1.32b7:[With respect to token object garbage collection (GC), 1.32b7 backtracks from 1.32b6, but results in better and less intrusive GC. This is the last beta version before full 1.32.]BIGGEST CHANGES:o The "#pragma gc_tokens" is no longer used.o .C files are now .cpp files (hence, makefiles will have to be changed; or you can rerun genmk). This is a good move, but causes some backward incompatibility problems. You can avoid this by changing CPP_FILE_SUFFIX to ".C" in pccts/h/config.h.o The token object class hierarchy has been flattened to include only three classes: ANTLRAbstractToken, ANTLRCommonToken, and ANTLRCommonNoRefCountToken. The common token now does garbage collection via ref counting.o "Smart" pointers are now used for garbage collection. That is, ANTLRTokenPtr is used instead of "ANTLRToken *".o The antlr.1 man page has been cleaned up slightly.o The SUN C++ compiler now complains less about C++ support code.o Grammars which subclass ANTLRCommonToken must wrap all token pointer references in mytoken(token_ptr). This is the only serious backward incompatibility. See below.MINOR CHANGES:--------------------------------------------------------1 deleteTokens()The deleteTokens() message to the parser or token buffer has been changedto one of: void noGarbageCollectTokens() { inputTokens->noGarbageCollectTokens(); } void garbageCollectTokens() { inputTokens->garbageCollectTokens(); }The token buffer deletes all non-referenced tokens by default now.--------------------------------------------------------2 makeToken()The makeToken() message returns a new type. The function should looklike: virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt, ANTLRChar *txt, int line) { ANTLRAbstractToken *t = new ANTLRCommonToken(tt,txt); t->setLine(line); return t; }--------------------------------------------------------3 TokenTypeChanged TokenType-> ANTLRTokenType (often forces changes in AST defs dueto #[] constructor called to AST(tokentype, string)).--------------------------------------------------------4 AST()You must define AST(ANTLRTokenPtr t) now in your AST class definition.You might also have to include ATokPtr.h above the definition; e.g.,if AST is defined in a separate file, such as AST.h, it's a good ideato include ATOKPTR_H (ATokPtr.h). For example, #include ATOKPTR_H class AST : public ASTBase { protected: ANTLRTokenPtr token; public: AST(ANTLRTokenPtr t) { token = t; } void preorder_action() { char *s = token->getText(); printf(" %s", s); } };Note the use of smart pointers rather than "ANTLRToken *".--------------------------------------------------------5 SUN C++
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?