]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | #include <stdio.h>\r |
2 | #include "STreeParser.h"\r | |
3 | \r | |
4 | void STreeParser::\r | |
5 | MATCH(SORASTBase *_t,int tok)\r | |
6 | {\r | |
7 | if ( _t->type()!=tok )\r | |
8 | {\r | |
9 | if ( guessing ) _GUESS_FAIL;\r | |
10 | else mismatched_token(tok, _t);\r | |
11 | }\r | |
12 | }\r | |
13 | \r | |
14 | void STreeParser::\r | |
15 | MATCHRANGE(SORASTBase *_t,int tok,int tok2)\r | |
16 | {\r | |
17 | if ( _t->type()<tok || _t->type()>tok2 )\r | |
18 | {\r | |
19 | if ( guessing ) _GUESS_FAIL;\r | |
20 | else mismatched_range(tok, tok2, _t);\r | |
21 | }\r | |
22 | }\r | |
23 | \r | |
24 | void STreeParser::\r | |
25 | WILDCARD(SORASTBase *_t)\r | |
26 | {\r | |
27 | if ( _t==NULL )\r | |
28 | {\r | |
29 | if ( guessing ) _GUESS_FAIL;\r | |
30 | else missing_wildcard();\r | |
31 | }\r | |
32 | }\r | |
33 | \r | |
34 | void STreeParser::\r | |
35 | mismatched_range(int looking_for, int upper_token, SORASTBase *found)\r | |
36 | {\r | |
37 | if ( found!=NULL ) {\r | |
38 | fprintf(stderr,\r | |
39 | "parse error: expected token range %d..%d found token %d\n",\r | |
40 | looking_for, upper_token,\r | |
41 | found->type());\r | |
42 | }\r | |
43 | else {\r | |
44 | fprintf(stderr,\r | |
45 | "parse error: expected token range %d..%d found NULL tree\n",\r | |
46 | looking_for, upper_token);\r | |
47 | }\r | |
48 | }\r | |
49 | \r | |
50 | void STreeParser::\r | |
51 | missing_wildcard()\r | |
52 | {\r | |
53 | fprintf(stderr, "parse error: expected any token/tree found found NULL tree\n");\r | |
54 | }\r | |
55 | \r | |
56 | void STreeParser::\r | |
57 | mismatched_token(int looking_for, SORASTBase *found)\r | |
58 | {\r | |
59 | if ( found!=NULL ) {\r | |
60 | fprintf(stderr,\r | |
61 | "parse error: expected token %d found token %d\n",\r | |
62 | looking_for,\r | |
63 | found->type());\r | |
64 | }\r | |
65 | else {\r | |
66 | fprintf(stderr,\r | |
67 | "parse error: expected token %d found NULL tree\n",\r | |
68 | looking_for);\r | |
69 | }\r | |
70 | }\r | |
71 | \r | |
72 | void STreeParser::\r | |
73 | no_viable_alt(char *rulename, SORASTBase *root)\r | |
74 | {\r | |
75 | if ( root==NULL )\r | |
76 | fprintf(stderr,\r | |
77 | "parse error: in rule %s, no viable alternative for NULL tree\n",\r | |
78 | rulename);\r | |
79 | else\r | |
80 | fprintf(stderr,\r | |
81 | "parse error: in rule %s, no viable alternative for tree\n",\r | |
82 | rulename);\r | |
83 | }\r | |
84 | \r | |
85 | void STreeParser::\r | |
86 | panic(char *err)\r | |
87 | {\r | |
88 | fprintf(stderr, "panic: %s\n", err);\r | |
89 | exit(-1);\r | |
90 | }\r | |
91 | \r | |
92 | void STreeParser::\r | |
93 | save_state(STreeParser *buf)\r | |
94 | {\r | |
95 | buf->try_ok = this->try_ok;\r | |
96 | buf->sjrv = this->sjrv;\r | |
97 | buf->guessing = this->guessing;\r | |
98 | buf->startofguess = this->startofguess;\r | |
99 | }\r | |
100 | \r | |
101 | void STreeParser::\r | |
102 | restore_state(STreeParser *buf)\r | |
103 | {\r | |
104 | this->try_ok = buf->try_ok;\r | |
105 | this->sjrv = buf->sjrv;\r | |
106 | this->guessing = buf->guessing;\r | |
107 | this->startofguess = buf->startofguess;\r | |
108 | }\r | |
109 | \r | |
110 | void STreeParser::\r | |
111 | _mkroot(SORASTBase **r, SORASTBase **s, SORASTBase **e, SORASTBase *t)\r | |
112 | {\r | |
113 | *r = t;\r | |
114 | }\r | |
115 | \r | |
116 | void STreeParser::\r | |
117 | _mkchild(SORASTBase **r, SORASTBase **s, SORASTBase **e, SORASTBase *t)\r | |
118 | {\r | |
119 | #ifdef BEFORE_GARYS_FIX\r | |
120 | /* if no sibling list, must attach to any existing root */\r | |
121 | if ( *s==NULL )\r | |
122 | {\r | |
123 | *s = *e = t;\r | |
124 | /* If r is NULL, then there was no root defined--must be sibling list */\r | |
125 | if ( *r==NULL ) *r = *s;\r | |
126 | else (*r)->setDown(t);\r | |
127 | }\r | |
128 | else { (*e)->setRight(t); *e = t; }\r | |
129 | #endif\r | |
130 | /*\r | |
131 | should do nothing if asked to add a NULL argument. NULL's come up\r | |
132 | when a rule wants to return "nothing".\r | |
133 | */\r | |
134 | /* if no sibling list, must attach to any existing root */\r | |
135 | if (*s == NULL)\r | |
136 | {\r | |
137 | *s = *e = t;\r | |
138 | // If r is NULL then there was no root defined--must be sibling list\r | |
139 | if (*r == NULL) *r = *s;\r | |
140 | else (*r)->setDown(t);\r | |
141 | }\r | |
142 | else if (*e != NULL)\r | |
143 | {\r | |
144 | (*e)->setRight(t);\r | |
145 | *e = t;\r | |
146 | }\r | |
147 | if (*e != NULL) {\r | |
148 | while ((*e)->right() != NULL) *e = (SORASTBase *)(*e)->right();\r | |
149 | }\r | |
150 | }\r | |
151 | \r |