]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/AParser.h
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / Pccts / h / AParser.h
diff --git a/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/AParser.h b/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/AParser.h
new file mode 100644 (file)
index 0000000..85fe921
--- /dev/null
@@ -0,0 +1,358 @@
+/* ANTLRParser.h\r
+ *\r
+ * Define the generic ANTLRParser superclass, which is subclassed to\r
+ * define an actual parser.\r
+ *\r
+ * Before entry into this file: ANTLRTokenType must be set.\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 APARSER_H_GATE\r
+#define APARSER_H_GATE\r
+\r
+#include "pcctscfg.h"\r
+\r
+#include "pccts_stdio.h"\r
+#include "pccts_setjmp.h"\r
+\r
+PCCTS_NAMESPACE_STD\r
+\r
+#include ATOKEN_H\r
+#include ATOKENBUFFER_H\r
+\r
+#ifdef ZZCAN_GUESS\r
+#ifndef ZZINF_LOOK\r
+#define ZZINF_LOOK\r
+#endif\r
+#endif\r
+\r
+\r
+#define NLA      (token_type[lap&(LLk-1)])/* --> next LA */\r
+\r
+typedef unsigned char SetWordType;\r
+\r
+/* Define external bit set stuff (for SetWordType) */\r
+#define EXT_WORDSIZE  (sizeof(char)*8)\r
+#define EXT_LOGWORDSIZE  3\r
+\r
+           /* s y n t a c t i c  p r e d i c a t e  s t u f f */\r
+\r
+#ifndef zzUSER_GUESS_HOOK\r
+#define zzUSER_GUESS_HOOK(seqFrozen,zzrv)\r
+#endif\r
+\r
+#ifndef zzUSER_GUESS_DONE_HOOK\r
+#define zzUSER_GUESS_DONE_HOOK(seqFrozen)\r
+#endif\r
+\r
+/* MR14 Add zzUSER_GUESS_FAIL_HOOK and related code */\r
+\r
+#define zzUSER_GUESS_FAIL_HOOK_INTERNAL zzUSER_GUESS_FAIL_HOOK(SeqFrozen)\r
+#ifndef zzUSER_GUESS_FAIL_HOOK\r
+#define zzUSER_GUESS_FAIL_HOOK(zzGuessSeq)\r
+#endif\r
+\r
+\r
+typedef struct _zzjmp_buf {\r
+      jmp_buf state;\r
+    } zzjmp_buf;\r
+\r
+/* these need to be macros not member functions */\r
+#define zzGUESS_BLOCK    ANTLRParserState zzst; int zzrv; int _marker; int zzGuessSeqFrozen;\r
+#define zzNON_GUESS_MODE  if ( !guessing )\r
+#define zzGUESS_FAIL    guess_fail();\r
+\r
+/*  Note:  zzGUESS_DONE does not execute longjmp() */\r
+\r
+#define zzGUESS_DONE    {zzrv=1; inputTokens->rewind(_marker); guess_done(&zzst);zzUSER_GUESS_DONE_HOOK(zzGuessSeqFrozen) }\r
+#define zzGUESS        saveState(&zzst); \\r
+              guessing = 1; \\r
+                            zzGuessSeqFrozen = ++zzGuessSeq; \\r
+              _marker = inputTokens->mark(); \\r
+              zzrv = setjmp(guess_start.state); \\r
+                            zzUSER_GUESS_HOOK(zzGuessSeqFrozen,zzrv) \\r
+                if ( zzrv ) zzGUESS_DONE\r
+\r
+#define zzTRACEdata     const ANTLRChar *zzTracePrevRuleName = NULL;\r
+\r
+#ifndef zzTRACEIN\r
+#define zzTRACEIN(r)  zzTracePrevRuleName=traceCurrentRuleName;tracein(r);\r
+#endif\r
+#ifndef zzTRACEOUT\r
+#define zzTRACEOUT(r)  traceout(r);traceCurrentRuleName=zzTracePrevRuleName;\r
+#endif\r
+\r
+                  /* a n t l r  p a r s e r  d e f */\r
+\r
+struct ANTLRParserState {\r
+  /* class variables */\r
+  zzjmp_buf guess_start;\r
+  int guessing;\r
+\r
+  int inf_labase;\r
+  int inf_last;\r
+\r
+  int dirty;\r
+\r
+    int             traceOptionValue;       // MR10\r
+    int             traceGuessOptionValue;  // MR10\r
+    const ANTLRChar *traceCurrentRuleName;  // MR10\r
+    int             traceDepth;             // MR10\r
+\r
+};\r
+\r
+/* notes:\r
+ *\r
+ * multiple inheritance is a cool way to include what stuff is needed\r
+ * in this structure (like guess stuff).  however, i'm not convinced that\r
+ * multiple inheritance works correctly on all platforms.  not that\r
+ * much space is used--just include all possibly useful members.\r
+ *\r
+ * the class should also be a template with arguments for the lookahead\r
+ * depth and so on.  that way, more than one parser can be defined (as\r
+ * each will probably have different lookahead requirements).  however,\r
+ * am i sure that templates work?  no, i'm not sure.\r
+ *\r
+ * no attributes are maintained and, hence, the 'asp' variable is not\r
+ * needed.  $i can still be referenced, but it refers to the token\r
+ * associated with that rule element.  question: where are the token's\r
+ * stored if not on the software stack?  in local variables created\r
+ * and assigned to by antlr.\r
+ */\r
+class ANTLRParser {\r
+protected:\r
+  /* class variables */\r
+  static SetWordType bitmask[sizeof(SetWordType)*8];\r
+  static char eMsgBuffer[500];\r
+\r
+protected:\r
+  int LLk;          // number of lookahead symbols (old LL_K)\r
+  int demand_look;\r
+  ANTLRTokenType eofToken;      // when do I stop during resynch()s\r
+  int bsetsize;                 // size of bitsets created by ANTLR in\r
+                        // units of SetWordType\r
+\r
+  ANTLRTokenBuffer *inputTokens;  //place to get input tokens\r
+\r
+  zzjmp_buf guess_start;    // where to jump back to upon failure\r
+  int guessing;        // if guessing (using (...)? predicate)\r
+\r
+  // infinite lookahead stuff\r
+  int can_use_inf_look;    // set by subclass (generated by ANTLR)\r
+  int inf_lap;\r
+  int inf_labase;\r
+  int inf_last;\r
+  int *_inf_line;\r
+\r
+  const ANTLRChar **token_tbl; // pointer to table of token type strings MR20 const\r
+\r
+  int dirty;          // used during demand lookahead\r
+\r
+  ANTLRTokenType *token_type;    // fast reference cache of token.getType()\r
+//  ANTLRLightweightToken **token;  // the token with all its attributes\r
+  int lap;\r
+  int labase;\r
+#ifdef ZZDEFER_FETCH\r
+  int stillToFetch;                               // MR19 V.H. Simonis\r
+#endif\r
+\r
+private:\r
+  void fill_inf_look();\r
+\r
+protected:\r
+  virtual void guess_fail() {                         // MR9 27-Sep-97 make virtual\r
+        traceGuessFail();                               // MR10\r
+        longjmp(guess_start.state, 1); }                // MR9\r
+  virtual void guess_done(ANTLRParserState *st) {     // MR9 27-Sep-97 make virtual\r
+         restoreState(st); }                            // MR9\r
+  virtual int guess(ANTLRParserState *);              // MR9 27-Sep-97 make virtual\r
+  void look(int);\r
+    int _match(ANTLRTokenType, ANTLRChar **, ANTLRTokenType *,\r
+         _ANTLRTokenPtr *, SetWordType **);\r
+    int _setmatch(SetWordType *, ANTLRChar **, ANTLRTokenType *,\r
+         _ANTLRTokenPtr *, SetWordType **);\r
+    int _match_wsig(ANTLRTokenType);\r
+    int _setmatch_wsig(SetWordType *);\r
+    virtual void consume();\r
+    virtual void resynch(SetWordType *wd,SetWordType mask); // MR21\r
+  void prime_lookahead();\r
+  virtual void tracein(const ANTLRChar *r);              // MR10\r
+  virtual void traceout(const ANTLRChar *r);             // MR10\r
+  static unsigned MODWORD(unsigned x) {return x & (EXT_WORDSIZE-1);}  // x % EXT_WORDSIZE // MR9\r
+  static unsigned DIVWORD(unsigned x) {return x >> EXT_LOGWORDSIZE;}  // x / EXT_WORDSIZE // MR9\r
+  int set_deg(SetWordType *);\r
+  int set_el(ANTLRTokenType, SetWordType *);\r
+  virtual void edecode(SetWordType *);        // MR1\r
+  virtual void FAIL(int k, ...);              // MR1\r
+    int                 traceOptionValue;                           // MR10\r
+    int                 traceGuessOptionValue;                      // MR10\r
+    const ANTLRChar     *traceCurrentRuleName;                      // MR10\r
+    int                 traceDepth;                                 // MR10\r
+    void                traceReset();                               // MR10\r
+    virtual void        traceGuessFail();                           // MR10\r
+    virtual void        traceGuessDone(const ANTLRParserState *);   // MR10\r
+    int                 zzGuessSeq;                                 // MR10\r
+\r
+public:\r
+  ANTLRParser(ANTLRTokenBuffer *,\r
+        int k=1,\r
+        int use_inf_look=0,\r
+        int demand_look=0,\r
+        int bsetsize=1);\r
+  virtual ~ANTLRParser();\r
+\r
+  virtual void init();\r
+  \r
+  ANTLRTokenType LA(int i)\r
+  {\r
+//\r
+//  MR14 demand look will always be 0 for C++ mode\r
+//\r
+////  return demand_look ? token_type[(labase+(i)-1)&(LLk-1)] :\r
+////            token_type[(lap+(i)-1)&(LLk-1)];\r
+\r
+// MR19 V.H. Simonis Defer fetch feature\r
+\r
+#ifdef ZZDEFER_FETCH\r
+      undeferFetch();\r
+#endif\r
+    return token_type[(lap+(i)-1)&(LLk-1)];\r
+  }\r
+  _ANTLRTokenPtr LT(int i);\r
+\r
+  void setEofToken(ANTLRTokenType t)  { eofToken = t; }\r
+  ANTLRTokenType getEofToken() const  { return eofToken; }    // MR14\r
+\r
+  void noGarbageCollectTokens()  { inputTokens->noGarbageCollectTokens(); }\r
+  void garbageCollectTokens()    { inputTokens->garbageCollectTokens(); }\r
+\r
+    virtual void syn(_ANTLRTokenPtr tok, ANTLRChar *egroup,\r
+           SetWordType *eset, ANTLRTokenType etok, int k);\r
+  virtual void saveState(ANTLRParserState *);     // MR9 27-Sep-97 make virtual\r
+  virtual void restoreState(ANTLRParserState *);  // MR9 27-Sep-97 make virtual\r
+\r
+  virtual void panic(const char *msg); // MR20 const\r
+  static char *eMsgd(char *,int);\r
+  static char *eMsg(char *,char *);\r
+  static char *eMsg2(char *,char *,char *);\r
+\r
+  void consumeUntil(SetWordType *st);\r
+  void consumeUntilToken(int t);\r
+\r
+  virtual int _setmatch_wdfltsig(SetWordType *tokensWanted,\r
+           ANTLRTokenType tokenTypeOfSet,\r
+           SetWordType *whatFollows);\r
+  virtual int _match_wdfltsig(ANTLRTokenType tokenWanted,\r
+           SetWordType *whatFollows);\r
+  \r
+  const ANTLRChar * parserTokenName(int tok);      // MR1\r
+\r
+    int                 traceOptionValueDefault;        // MR11\r
+    int                 traceOption(int delta);         // MR11\r
+    int                 traceGuessOption(int delta);    // MR11\r
+\r
+//  MR8  5-Aug-97   S.Bochnak@microtool.com.pl\r
+//  MR8             Move resynch static local variable\r
+//  MR8               to class instance\r
+\r
+    int                 syntaxErrCount;                      // MR12\r
+    ANTLRTokenStream   *getLexer() const {                   // MR12\r
+      return inputTokens ? inputTokens->getLexer() : 0; }    // MR12\r
+protected:                                              // MR8\r
+    int     resynchConsumed;                            // MR8\r
+    char    *zzFAILtext; // workarea required by zzFAIL // MR9\r
+    void    undeferFetch();                             // MR19 V.H. Simonis\r
+    int     isDeferFetchEnabled();                      // MR19 V.H. Simonis\r
+};\r
+\r
+#define zzmatch(_t)              \\r
+  if ( !_match((ANTLRTokenType)_t, &zzMissText, &zzMissTok, \\r
+         (_ANTLRTokenPtr *) &zzBadTok, &zzMissSet) ) goto fail;\r
+\r
+#define zzmatch_wsig(_t,handler)            \\r
+  if ( !_match_wsig((ANTLRTokenType)_t) ) if ( guessing ) zzGUESS_FAIL else {_signal=MismatchedToken; goto handler;}\r
+\r
+#define zzsetmatch(_ts)              \\r
+  if ( !_setmatch(_ts, &zzMissText, &zzMissTok, \\r
+         (_ANTLRTokenPtr *) &zzBadTok, &zzMissSet) ) goto fail;\r
+\r
+#define zzsetmatch_wsig(_ts, handler)        \\r
+  if ( !_setmatch_wsig(_ts) ) if ( guessing ) zzGUESS_FAIL else {_signal=MismatchedToken; goto handler;}\r
+\r
+/* For the dflt signal matchers, a FALSE indicates that an error occurred\r
+ * just like the other matchers, but in this case, the routine has already\r
+ * recovered--we do NOT want to consume another token.  However, when\r
+ * the match was successful, we do want to consume hence _signal=0 so that\r
+ * a token is consumed by the "if (!_signal) consume(); _signal=NoSignal;"\r
+ * preamble.\r
+ */\r
+#define zzsetmatch_wdfltsig(tokensWanted, tokenTypeOfSet, whatFollows) \\r
+  if ( !_setmatch_wdfltsig(tokensWanted, tokenTypeOfSet, whatFollows) ) \\r
+    _signal = MismatchedToken;\r
+\r
+#define zzmatch_wdfltsig(tokenWanted, whatFollows) \\r
+  if ( !_match_wdfltsig(tokenWanted, whatFollows) ) _signal = MismatchedToken;\r
+\r
+\r
+//  MR1  10-Apr-97   zzfailed_pred() macro does not backtrack\r
+//  MR1        in guess mode.\r
+//  MR1      Identification and correction due to J. Lilley\r
+\r
+#ifndef zzfailed_pred\r
+#define zzfailed_pred(_p) \\r
+  if (guessing) { \\r
+    zzGUESS_FAIL; \\r
+  } else { \\r
+    fprintf(stdout,"line %d: semantic error; failed predicate: '%s'\n", \\r
+  LT(1)->getLine(), _p); \\r
+  }\r
+#endif\r
+\r
+#define zzRULE \\r
+    SetWordType *zzMissSet=NULL; ANTLRTokenType zzMissTok=(ANTLRTokenType)0;  \\r
+    _ANTLRTokenPtr zzBadTok=NULL; ANTLRChar *zzBadText=(ANTLRChar *)"";  \\r
+    int zzErrk=1,zzpf=0; \\r
+        zzTRACEdata \\r
+    ANTLRChar *zzMissText=(ANTLRChar *)"";\r
+\r
+#endif\r
+\r
+        /* S t a n d a r d  E x c e p t i o n  S i g n a l s */\r
+\r
+#define NoSignal      0\r
+#define MismatchedToken    1\r
+#define NoViableAlt      2\r
+#define NoSemViableAlt    3\r
+\r
+/* MR7  Allow more control over signalling                                  */\r
+/*        by adding "Unwind" and "SetSignal"                                */\r
+\r
+#define Unwind              4\r
+#define setSignal(newValue) *_retsignal=_signal=(newValue)\r
+#define suppressSignal       *_retsignal=_signal=0\r
+#define exportSignal        *_retsignal=_signal\r