• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef STreeParser_h
2 #define STreeParser_h
3 
4 /*
5  * STreeParser.h
6  *
7  * SOFTWARE RIGHTS
8  *
9  * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public
10  * domain.  An individual or company may do whatever they wish with
11  * source code distributed with SORCERER or the code generated by
12  * SORCERER, including the incorporation of SORCERER, or its output, into
13  * commerical software.
14  *
15  * We encourage users to develop software with SORCERER.  However, we do
16  * ask that credit is given to us for developing SORCERER.  By "credit",
17  * we mean that if you incorporate our source code into one of your
18  * programs (commercial product, research project, or otherwise) that you
19  * acknowledge this fact somewhere in the documentation, research report,
20  * etc...  If you like SORCERER and have developed a nice tool with the
21  * output, please mention that you developed it using SORCERER.  In
22  * addition, we ask that this header remain intact in our source code.
23  * As long as these guidelines are kept, we expect to continue enhancing
24  * this system and expect to make other tools available as they are
25  * completed.
26  *
27  * SORCERER 1.00B
28  * Parr Research Corporation
29  * with Purdue University and AHPCRC, University of Minnesota
30  * 1992-1994
31  */
32 
33 /* The programmer should derive a class from SORASTBase; SORASTBase defines
34  * the minimum public interface that a tree node must follow for SORCERER to
35  * be able to walk the trees.
36  */
37 
38 /* The @-vars are added by the subclass created by SORCERER; the constructor
39  * is used to init the @-vars.
40  */
41 
42 #include <stdio.h>
43 #include <setjmp.h>
44 #include <stdlib.h>
45 #include "SASTBase.h"
46 
47 #define _DOWN        _t=(SORASTBase *)_t->down()
48 #define _RIGHT        _t=(SORASTBase *)_t->right()
49 
50 #define _SAVE        SORASTBase *_save=_t
51 #define _RESTORE      _t = _save
52 #define _GUESS_BLOCK    STreeParser _st; int _gv; SORASTBase *_savet=NULL;
53 #define _GUESS        {save_state(&_st); \
54               _savet = _t; \
55               guessing = 1; \
56               _gv = setjmp(startofguess.state);}
57 #define _GUESS_FAIL      longjmp(startofguess.state, 1)
58 #define _GUESS_DONE      {restore_state(&_st); _t = _savet;}
59 #define _MATCH(tok)      MATCH(_t,tok)
60 #define _MATCHRANGE(t1,t2)  MATCHRANGE(_t,t1,t2)
61 #define _WILDCARD      WILDCARD(_t)
62 
63 #define ast_return(t)    *_result = (SORASTBase *)t;
64 
65 #define STreeTry(r,p,t)     \
66       (p)->try_result = NULL;          \
67             (p)->sjrv = setjmp((p)->startofguess);  \
68             if ( !(p)->sjrv ) {            \
69                 rule(p,t,&try_result);        \
70                 (p)->try_ok = 1;          \
71       }                    \
72             else {                  \
73                 (p)->try_ok = 0;          \
74       }                    \
75             if ( (p)->try_ok )
76 
77 
78 /* Used only during TRANSFORM mode */
79 #define  TREE_CONSTR_PTRS  SORASTBase *_r=NULL,*_s=NULL,*_e=NULL
80 
81 typedef struct _Sjmp_buf {
82       jmp_buf state;
83     } Sjmp_buf;
84 
85 class STreeParser {
86 protected:
87   int try_ok, sjrv;    /* used by STreeTry macro */
88   SORASTBase *try_result;  /* tree coming back from try */
89   int guessing;
90   Sjmp_buf startofguess;
91 //  SORASTBase *t;
92 
93   void _mkroot(SORASTBase **, SORASTBase **, SORASTBase **, SORASTBase *);
94   void _mkchild(SORASTBase **, SORASTBase **, SORASTBase **, SORASTBase *);
95   virtual void mismatched_range(int looking_for, int upper_token, SORASTBase *found);
96   virtual void missing_wildcard();
97   virtual void mismatched_token(int looking_for, SORASTBase *found);
98   virtual void no_viable_alt(char *rulename, SORASTBase *root);
99   virtual void MATCH(SORASTBase *_t, int tok);
100   virtual void MATCHRANGE(SORASTBase *_t, int tok, int tok2);
101   virtual void WILDCARD(SORASTBase *_t);
102 
103 public:
STreeParser()104   STreeParser() { guessing = 0; }
105   virtual void panic(char *err);
106   void save_state(STreeParser *);
107   void restore_state(STreeParser *);
108 };
109 
110 #endif
111