summaryrefslogtreecommitdiff
path: root/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/STreeParser.cpp
blob: 0d50a337f0a067a15a2b7a0261c0c3d0fe9e8060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <stdio.h>
#include "STreeParser.h"

void STreeParser::
MATCH(SORASTBase *_t,int tok)
{
	if ( _t->type()!=tok )
	{
		if ( guessing ) _GUESS_FAIL;
		else mismatched_token(tok, _t);
	}
}

void STreeParser::
MATCHRANGE(SORASTBase *_t,int tok,int tok2)
{
	if ( _t->type()<tok || _t->type()>tok2 )
	{
		if ( guessing ) _GUESS_FAIL;
		else mismatched_range(tok, tok2, _t);
	}
}

void STreeParser::
WILDCARD(SORASTBase *_t)
{
	if ( _t==NULL )
	{
		if ( guessing ) _GUESS_FAIL;
		else missing_wildcard();
	}
}

void STreeParser::
mismatched_range(int looking_for, int upper_token, SORASTBase *found)
{
	if ( found!=NULL ) {
		fprintf(stderr,
				"parse error: expected token range %d..%d found token %d\n",
				looking_for, upper_token,
				found->type());
	}
	else {
		fprintf(stderr,
				"parse error: expected token range %d..%d found NULL tree\n",
				looking_for, upper_token);
	}
}

void STreeParser::
missing_wildcard()
{
	fprintf(stderr, "parse error: expected any token/tree found found NULL tree\n");
}

void STreeParser::
mismatched_token(int looking_for, SORASTBase *found)
{
	if ( found!=NULL ) {
		fprintf(stderr,
				"parse error: expected token %d found token %d\n",
				looking_for,
				found->type());
	}
	else {
		fprintf(stderr,
				"parse error: expected token %d found NULL tree\n",
				looking_for);
	}
}

void STreeParser::
no_viable_alt(char *rulename, SORASTBase *root)
{
	if ( root==NULL )
		fprintf(stderr,
				"parse error: in rule %s, no viable alternative for NULL tree\n",
				rulename);
	else
		fprintf(stderr,
				"parse error: in rule %s, no viable alternative for tree\n",
				rulename);
}

void STreeParser::
panic(char *err)
{
	fprintf(stderr, "panic: %s\n", err);
	exit(-1);
}

void STreeParser::
save_state(STreeParser *buf)
{
	buf->try_ok = this->try_ok;
	buf->sjrv = this->sjrv;
	buf->guessing = this->guessing;
	buf->startofguess = this->startofguess;
}

void STreeParser::
restore_state(STreeParser *buf)
{
	this->try_ok = buf->try_ok;
	this->sjrv = buf->sjrv;
	this->guessing = buf->guessing;
	this->startofguess = buf->startofguess;
}

void STreeParser::
_mkroot(SORASTBase **r, SORASTBase **s, SORASTBase **e, SORASTBase *t)
{
	*r = t;
}

void STreeParser::
_mkchild(SORASTBase **r, SORASTBase **s, SORASTBase **e, SORASTBase *t)
{
#ifdef BEFORE_GARYS_FIX
	/* if no sibling list, must attach to any existing root */
	if ( *s==NULL )
	{
		*s = *e = t;
		/* If r is NULL, then there was no root defined--must be sibling list */
		if ( *r==NULL ) *r = *s;
		else (*r)->setDown(t);
	}
	else { (*e)->setRight(t); *e = t; }
#endif
/*
	should do nothing if asked to add a NULL argument.  NULL's come up
	when a rule wants to return "nothing".
*/
	/* if no sibling list, must attach to any existing root */
	if (*s == NULL)
	{
		*s = *e = t;
		// If r is NULL then there was no root defined--must be sibling list
		if (*r == NULL)	*r = *s;
		else (*r)->setDown(t);
	}
	else if (*e != NULL)
	{
		(*e)->setRight(t);
		*e = t;
	}
	if (*e != NULL) {
		while ((*e)->right() != NULL) *e = (SORASTBase *)(*e)->right();
	}
}