Subversion Repositories filter_foundry

Rev

Rev 358 | Rev 495 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 358 Rev 492
Line 21... Line 21...
21
*/
21
*/
22
 
22
 
23
#include <stdio.h>
23
#include <stdio.h>
24
#include <string.h>
24
#include <string.h>
25
 
25
 
-
 
26
#ifdef WIN_ENV
-
 
27
	#include <windows.h> // for TCHAR
-
 
28
#else
-
 
29
	#ifdef UNICODE
-
 
30
	#define TCHAR wchar_t
-
 
31
	#else
-
 
32
	#define TCHAR char
-
 
33
	#endif
-
 
34
#endif
-
 
35
 
26
#ifndef false
36
#ifndef false
27
#define false 0
37
#define false 0
28
#define true 1
38
#define true 1
29
#endif
39
#endif
30
 
40
 
Line 33... Line 43...
33
 
43
 
34
//#ifdef MAC_ENV
44
//#ifdef MAC_ENV
35
int yyparse(void);
45
int yyparse(void);
36
int yylex(void); // hack. correct prototype is buried in lex output
46
int yylex(void); // hack. correct prototype is buried in lex output
37
//#endif
47
//#endif
-
 
48
 
-
 
49
// DM 29.04.2022
-
 
50
#define YY_(Msg) ((TCHAR*)TEXT(Msg))
-
 
51
 
-
 
52
 
38
void yyerror(char*);
53
void yyerror(TCHAR*);
39
int pushflag(int x);
54
int pushflag(int x);
40
struct node *parseexpr(char *s);
55
struct node *parseexpr(char *s);
41
 
56
 
42
#define DPARSE 
57
#define DPARSE 
43
 
58
 
44
struct node *parsetree;
59
struct node *parsetree;
45
char *errstr;
60
TCHAR *errstr;
46
 
61
 
47
enum{ PARENSTACK = 100 };
62
enum{ PARENSTACK = 100 };
48
 
63
 
49
int inarglist[PARENSTACK],arglistptr; // keep track of whether a comma is an function argument separator, or operator
64
int inarglist[PARENSTACK],arglistptr; // keep track of whether a comma is an function argument separator, or operator
50
 
65
 
51
int pushflag(int x){
66
int pushflag(int x){
52
	if(arglistptr < (PARENSTACK-1))
67
	if(arglistptr < (PARENSTACK-1))
53
		inarglist[++arglistptr] = x;
68
		inarglist[++arglistptr] = x;
54
	else{
69
	else{
55
		yyerror(_strdup("too many nested parentheses or function calls"));
70
		yyerror((TCHAR*)TEXT("too many nested parentheses or function calls"));
56
		return true;
71
		return true;
57
	}
72
	}
58
	return false;
73
	return false;
59
}
74
}
60
 
75
 
Line 142... Line 157...
142
	| expr ',' expr { $$ = $2; $$->child[0] = $1; $$->child[1] = $3; }
157
	| expr ',' expr { $$ = $2; $$->child[0] = $1; $$->child[1] = $3; }
143
/* unary operators */
158
/* unary operators */
144
	| '-' expr %prec NEG { $$ = $1; $$->child[0] = 0; $$->child[1] = $2; }
159
	| '-' expr %prec NEG { $$ = $1; $$->child[0] = 0; $$->child[1] = $2; }
145
	| '+' expr %prec NEG { $$ = $2; }
160
	| '+' expr %prec NEG { $$ = $2; }
146
/* error tokens */
161
/* error tokens */
147
	| TOK_UNKNOWN { yyerror(_strdup("unknown name")); YYERROR; }
162
	| TOK_UNKNOWN { yyerror((TCHAR*)TEXT("unknown name")); YYERROR; }
148
	| TOK_BADCHAR { yyerror(_strdup("disallowed character")); YYERROR; }
163
	| TOK_BADCHAR { yyerror((TCHAR*)TEXT("disallowed character")); YYERROR; }
149
	;
164
	;
150
 
165
 
151
%%
166
%%
152
 
167
 
153
// Daniel 06 July 2021: Move these two lines out of the function parseexpr(), otherwise the code won't compile in G++
168
// Daniel 06 July 2021: Move these two lines out of the function parseexpr(), otherwise the code won't compile in G++
Line 169... Line 184...
169
		if(!yyparse())
184
		if(!yyparse())
170
			return parsetree;
185
			return parsetree;
171
		else /* ensure we don't leak memory, on an unsuccessful parse */
186
		else /* ensure we don't leak memory, on an unsuccessful parse */
172
			freeallnodes();
187
			freeallnodes();
173
	}else
188
	}else
174
		yyerror(_strdup("null string???"));
189
		yyerror((TCHAR*)TEXT("null string???"));
175
	return 0;
190
	return 0;
176
}
191
}
177
 
192
 
178
void yyerror(char *msg){
193
void yyerror(TCHAR *msg){
179
	errstr = msg;
194
	errstr = msg;
180
}
195
}