+++ /dev/null
-/* ANTLRToken.h\r
- *\r
- * SOFTWARE RIGHTS\r
- *\r
- * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
- * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
- * company may do whatever they wish with source code distributed with\r
- * PCCTS or the code generated by PCCTS, including the incorporation of\r
- * PCCTS, or its output, into commerical software.\r
- *\r
- * We encourage users to develop software with PCCTS. However, we do ask\r
- * that credit is given to us for developing PCCTS. By "credit",\r
- * we mean that if you incorporate our source code into one of your\r
- * programs (commercial product, research project, or otherwise) that you\r
- * acknowledge this fact somewhere in the documentation, research report,\r
- * etc... If you like PCCTS and have developed a nice tool with the\r
- * output, please mention that you developed it using PCCTS. In\r
- * addition, we ask that this header remain intact in our source code.\r
- * As long as these guidelines are kept, we expect to continue enhancing\r
- * this system and expect to make other tools available as they are\r
- * completed.\r
- *\r
- * ANTLR 1.33\r
- * Terence Parr\r
- * Parr Research Corporation\r
- * with Purdue University and AHPCRC, University of Minnesota\r
- * 1989-1998\r
- */\r
-\r
-#ifndef ATOKEN_H_GATE\r
-#define ATOKEN_H_GATE\r
-\r
-#include "pcctscfg.h"\r
-\r
-#include "pccts_string.h"\r
-#include "pccts_stdio.h"\r
-#include "pccts_stdlib.h"\r
-\r
-PCCTS_NAMESPACE_STD\r
-\r
-#ifndef ANTLRCommonTokenTEXTSIZE\r
-#define ANTLRCommonTokenTEXTSIZE 100\r
-#endif\r
-\r
-/* must define what a char looks like; can make this a class too */\r
-typedef char ANTLRChar;\r
-\r
-/* D E F I N E S M A R T P O I N T E R S */\r
-\r
-#include "pcctscfg.h"\r
-\r
-//#include ATOKPTR_H not tested yet, leave out\r
-class ANTLRAbstractToken;\r
-typedef ANTLRAbstractToken *_ANTLRTokenPtr;\r
-\r
-class DllExportPCCTS ANTLRAbstractToken {\r
-public:\r
- virtual ~ANTLRAbstractToken() {;}\r
- virtual ANTLRTokenType getType() = 0;\r
- virtual void setType(ANTLRTokenType t) = 0;\r
- virtual int getLine() = 0;\r
- virtual void setLine(int line) = 0;\r
- virtual ANTLRChar *getText() = 0;\r
- virtual void setText(ANTLRChar *) = 0;\r
-\r
- /* This function will disappear when I can use templates */\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *text,\r
- int line) = 0;\r
-\r
- /* define to satisfy ANTLRTokenBuffer's need to determine whether or\r
- not a token object can be destroyed. If nref()==0, no one has\r
- a reference, and the object may be destroyed. This function defaults\r
- to 1, hence, if you use deleteTokens() message with a token object\r
- not derived from ANTLRCommonRefCountToken, the parser will compile\r
- but will not delete objects after they leave the token buffer.\r
- */\r
- virtual unsigned nref() { return 1; }\r
- virtual void ref() {;}\r
- virtual void deref() {;}\r
-\r
- virtual void panic(char *msg)\r
- {\r
- fprintf(stderr, "ANTLRAbstractToken panic: %s\n", msg);\r
- exit(PCCTS_EXIT_FAILURE);\r
- }\r
-};\r
-\r
-/* This class should be subclassed. It cannot store token type or text */\r
-\r
-class DllExportPCCTS ANTLRRefCountToken : public ANTLRAbstractToken {\r
-public:\r
-#ifdef DBG_REFCOUNTTOKEN\r
- static int ctor;\r
- static int dtor;\r
-#endif\r
-protected:\r
- unsigned refcnt_;\r
-#ifdef DBG_REFCOUNTTOKEN\r
- char object[200];\r
-#endif\r
-\r
-public:\r
- ANTLRRefCountToken(ANTLRTokenType t, ANTLRChar *s)\r
-#ifndef DBG_REFCOUNTTOKEN\r
- {\r
- refcnt_ = 0;\r
- }\r
-#else\r
- {\r
- ctor++;\r
- refcnt_ = 0;\r
- if ( t==1 ) sprintf(object,"tok_EOF");\r
- else sprintf(object,"tok_%s",s);\r
- fprintf(stderr, "ctor %s #%d\n",object,ctor);\r
- }\r
-#endif\r
- ANTLRRefCountToken()\r
-#ifndef DBG_REFCOUNTTOKEN\r
- { refcnt_ = 0; }\r
-#else\r
- {\r
- ctor++;\r
- refcnt_ = 0;\r
- sprintf(object,"tok_blank");\r
- fprintf(stderr, "ctor %s #%d\n",object,ctor);\r
- }\r
- virtual ~ANTLRRefCountToken()\r
- {\r
- dtor++;\r
- if ( dtor>ctor ) fprintf(stderr, "WARNING: dtor>ctor\n");\r
- fprintf(stderr, "dtor %s #%d\n", object, dtor);\r
- object[0]='\0';\r
- }\r
-#endif\r
-\r
- // reference counting stuff needed by ANTLRTokenPtr.\r
- // User should not access these; for C++ language reasons, we had\r
- // to make these public. Yuck.\r
- void ref() { refcnt_++; }\r
- void deref() { refcnt_--; }\r
- unsigned nref() { return refcnt_; }\r
-\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *txt,\r
- int line)\r
- {\r
- panic("call to ANTLRRefCountToken::makeToken()\n");\r
- return NULL;\r
- }\r
-};\r
-\r
-class DllExportPCCTS ANTLRCommonNoRefCountToken : public ANTLRAbstractToken {\r
-protected:\r
- ANTLRTokenType _type;\r
- int _line;\r
- ANTLRChar _text[ANTLRCommonTokenTEXTSIZE+1];\r
-\r
-public:\r
- ANTLRCommonNoRefCountToken(ANTLRTokenType t, ANTLRChar *s)\r
- { setType(t); _line = 0; setText(s); }\r
- ANTLRCommonNoRefCountToken()\r
- { setType((ANTLRTokenType)0); _line = 0; setText(""); }\r
-\r
- ANTLRTokenType getType() { return _type; }\r
- void setType(ANTLRTokenType t) { _type = t; }\r
- virtual int getLine() { return _line; }\r
- void setLine(int line) { _line = line; }\r
- ANTLRChar *getText() { return _text; }\r
- void setText(ANTLRChar *s)\r
- { strncpy((char *)_text, (char *)s, ANTLRCommonTokenTEXTSIZE); }\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *txt,\r
- int line)\r
- {\r
- ANTLRAbstractToken *t = new ANTLRCommonNoRefCountToken;\r
- t->setType(tt); t->setText(txt); t->setLine(line);\r
- return t;\r
- }\r
-};\r
-\r
-class DllExportPCCTS ANTLRCommonToken : public ANTLRRefCountToken {\r
-protected:\r
- ANTLRTokenType _type;\r
- int _line;\r
- ANTLRChar _text[ANTLRCommonTokenTEXTSIZE+1];\r
-\r
-public:\r
- ANTLRCommonToken(ANTLRTokenType t, ANTLRChar *s) : ANTLRRefCountToken(t,s)\r
- { setType(t); _line = 0; setText(s); }\r
- ANTLRCommonToken()\r
- { setType((ANTLRTokenType)0); _line = 0; setText(""); }\r
- virtual ~ANTLRCommonToken() {;}\r
-\r
- ANTLRTokenType getType() { return _type; }\r
- void setType(ANTLRTokenType t) { _type = t; }\r
- virtual int getLine() { return _line; }\r
- void setLine(int line) { _line = line; }\r
- ANTLRChar *getText() { return _text; }\r
- void setText(ANTLRChar *s)\r
- { strncpy((char *)_text, (char *)s, ANTLRCommonTokenTEXTSIZE); }\r
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType tt,\r
- ANTLRChar *txt,\r
- int line)\r
- {\r
- ANTLRAbstractToken *t = new ANTLRCommonToken(tt,txt);\r
- t->setLine(line);\r
- return t;\r
- }\r
-};\r
-\r
-// used for backward compatibility\r
-typedef ANTLRCommonToken ANTLRCommonBacktrackingToken;\r
-\r
-#endif\r