1 /* Abstract syntax tree
5 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
6 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
7 * company may do whatever they wish with source code distributed with
8 * PCCTS or the code generated by PCCTS, including the incorporation of
9 * PCCTS, or its output, into commerical software.
11 * We encourage users to develop software with PCCTS. However, we do ask
12 * that credit is given to us for developing PCCTS. By "credit",
13 * we mean that if you incorporate our source code into one of your
14 * programs (commercial product, research project, or otherwise) that you
15 * acknowledge this fact somewhere in the documentation, research report,
16 * etc... If you like PCCTS and have developed a nice tool with the
17 * output, please mention that you developed it using PCCTS. In
18 * addition, we ask that this header remain intact in our source code.
19 * As long as these guidelines are kept, we expect to continue enhancing
20 * this system and expect to make other tools available as they are
25 * Parr Research Corporation
26 * with Purdue University and AHPCRC, University of Minnesota
38 #define StringScanMaxText 50
39 #define MaxTreeStackDepth 400
41 typedef struct stringlexer {
45 char text[StringScanMaxText];
48 /* Define the structures needed for ast_scan() */
49 typedef struct stringparser {
55 typedef struct _scanast {
56 struct _scanast *_right, *_down;
59 int type() { return _token; }
60 struct _scanast *right() { return _right; }
61 struct _scanast *down() { return _down; }
64 #define VALID_SCAN_TOKEN(t) (t>=__LPAREN && t<=__PERIOD)
68 static char *scan_token_tbl[];
80 char *scan_token_str(int t);
81 void stringlexer_init(StringLexer *scanner, char *input);
82 void stringparser_init(StringParser *, StringLexer *);
83 ScanAST *stringparser_parse_scanast(char *templ, int *n);
84 ScanAST *stringparser_parse_tree(StringParser *parser);
85 ScanAST *stringparser_parse_element(StringParser *parser);
86 void stringscan_advance(StringLexer *scanner);
87 int stringscan_gettok(StringLexer *scanner);
88 void _push(PCCTS_AST **st, int *sp, PCCTS_AST *e);
89 PCCTS_AST *_pop(PCCTS_AST **st, int *sp);
90 int match_partial(PCCTS_AST *t, PCCTS_AST *u);
91 int scanmatch(ScanAST *t, PCCTS_AST **labels[], int *n);
92 void scanast_free(ScanAST *t);
93 ScanAST *new_scanast(int tok);
94 void stringparser_match(StringParser *parser, int type);
95 virtual PCCTS_AST *deepCopyBushy();
99 virtual ~PCCTS_AST() {;}
101 /* This group must be defined for SORCERER to work correctly */
102 virtual PCCTS_AST *right() = 0;
103 virtual PCCTS_AST *down() = 0;
104 virtual void setRight(PCCTS_AST *t) = 0;
105 virtual void setDown(PCCTS_AST *t) = 0;
106 // we define these so ANTLR doesn't have to
107 virtual int type() { return 0; }
108 virtual void setType(int t) {;}
109 virtual PCCTS_AST *shallowCopy() {panic("no shallowCopy() defined"); return NULL;}
111 /* These are not needed by ANTLR, but are support functions */
112 virtual PCCTS_AST *deepCopy(); // used by SORCERER in transform mode
113 virtual void addChild(PCCTS_AST *t);
114 virtual void lisp_action(FILE *f) {;}
115 virtual void lisp(FILE *f);
116 static PCCTS_AST *make(PCCTS_AST *rt, ...);
117 virtual PCCTS_AST *ast_find_all(PCCTS_AST *u, PCCTS_AST **cursor);
118 virtual int match(PCCTS_AST *u);
119 virtual void insert_after(PCCTS_AST *b);
120 virtual void append(PCCTS_AST *b);
121 virtual PCCTS_AST *tail();
122 virtual PCCTS_AST *bottom();
123 static PCCTS_AST *cut_between(PCCTS_AST *a, PCCTS_AST *b);
124 // virtual SList *to_slist();
125 virtual void tfree();
126 int ast_scan(char *templ, ...);
127 virtual int nsiblings();
128 virtual PCCTS_AST *sibling_index(int i);
130 void require(int e,char *err){ if ( !e ) panic(err); }
131 virtual void panic(char *err)
132 { fprintf(stderr, "PCCTS_AST: %s\n", err); exit(PCCTS_EXIT_FAILURE); }
135 #endif /* PCCTSAST_H */