Subversion Repositories filter_foundry

Rev

Rev 304 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 304 Rev 358
Line 1... Line 1...
1
%{
1
%{
2
 
2
 
3
/*
3
/*
4
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
4
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
5
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
5
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
6
    Copyright (C) 2018-2019 Daniel Marschall, ViaThinkSoft
6
    Copyright (C) 2018-2019 Daniel Marschall, ViaThinkSoft
7
 
7
 
8
    This program is free software; you can redistribute it and/or modify
8
    This program is free software; you can redistribute it and/or modify
9
    it under the terms of the GNU General Public License as published by  
9
    it under the terms of the GNU General Public License as published by  
10
    the Free Software Foundation; either version 2 of the License, or
10
    the Free Software Foundation; either version 2 of the License, or
11
    (at your option) any later version.
11
    (at your option) any later version.
12
 
12
 
13
    This program is distributed in the hope that it will be useful,
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
16
    GNU General Public License for more details.
17
 
17
 
18
    You should have received a copy of the GNU General Public License  
18
    You should have received a copy of the GNU General Public License  
19
    along with this program; if not, write to the Free Software
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
*/
21
*/
22
 
22
 
23
#include <ctype.h>
23
#include <ctype.h>
24
 
24
 
25
#include "node.h"
25
#include "node.h"
26
#include "dbg.h"
26
#include "dbg.h"
27
#include "y.tab.h"
27
#include "y.tab.h"
28
 
28
 
29
#define yywrap() 1
29
#define yywrap() 1
30
 
30
 
31
/* the reason for these hacks is to prevent any references to stdlib,
31
/* the reason for these hacks is to prevent any references to stdlib,
32
   which cause load failures in OS X due to mismatch of headers/libraries
32
   which cause load failures in OS X due to mismatch of headers/libraries
33
   when project is built with MPW */
33
   when project is built with MPW */
34
 
34
 
35
#if defined(__MRC__) && TARGET_CARBON
35
#if defined(__MRC__) && TARGET_CARBON
36
	#define stdin 0
36
	#define stdin 0
37
	#define stdout 0
37
	#define stdout 0
38
	#define stderr 0
38
	#define stderr 0
39
#endif 
39
#endif 
40
 
40
 
41
#define YY_FATAL_ERROR(msg)
41
#define YY_FATAL_ERROR(msg)
42
#define YY_INPUT
42
#define YY_INPUT
43
#define YYDECL int yylex(void)
43
#define YYDECL int yylex(void)
44
#define ECHO
44
#define ECHO
45
#define YY_NEVER_INTERACTIVE 1
45
#define YY_NEVER_INTERACTIVE 1
46
 
46
 
47
YYDECL;
47
YYDECL;
48
 
48
 
49
int tokpos,tokstart;
49
int tokpos,tokstart;
50
 
50
 
51
extern YYSTYPE yylval;
51
extern YYSTYPE yylval;
52
extern int inarglist[],arglistptr,varused[];
52
extern int inarglist[],arglistptr,varused[];
53
 
53
 
54
#define OP(x) \
54
#define OP(x) \
55
	yylval = newnode(x); \
55
	yylval = newnode(x); \
56
	return x;
56
	return x;
57
 
57
 
58
#define YY_USER_ACTION \
58
#define YY_USER_ACTION \
59
	tokstart = tokpos; \
59
	tokstart = tokpos; \
60
	tokpos += yyleng;
60
	tokpos += yyleng;
61
 
61
 
62
%}
62
%}
63
 
63
 
64
DIGIT		[0-9]
64
DIGIT		[0-9]
65
HEXDIGIT	[0-9A-Fa-f]
65
HEXDIGIT	[0-9A-Fa-f]
66
 
66
 
67
%%
67
%%
68
 
68
 
69
[ \t\n\r]+|"//"[^\n\r]* ; /* ignore whitespace, comments */
69
[ \t\n\r]+|"//"[^\n\r]* ; /* ignore whitespace, comments */
70
 
70
 
71
0[xX]{HEXDIGIT}+ {  /* hex constant; make new tree node */
71
0[xX]{HEXDIGIT}+ {  /* hex constant; make new tree node */
72
		int i,c;
72
		int i,c;
73
		value_type v;
73
		value_type v;
74
		char *p;
74
		char *p;
75
 
75
 
76
		for( i=yyleng-2,p=yytext+2,v = 0 ; i-- ; ){
76
		for( i=yyleng-2,p=yytext+2,v = 0 ; i-- ; ){
77
			c = toupper(*p++);
77
			c = toupper(*p++);
78
			v *= 16;
78
			v *= 16;
79
			v += c - (c>='A' ? 'A'-10 : '0');
79
			v += c - (c>='A' ? 'A'-10 : '0');
80
		}
80
		}
81
		yylval = newnode(TOK_NUM);
81
		yylval = newnode(TOK_NUM);
82
		yylval->v.value = v;
82
		yylval->v.value = v;
83
		return TOK_NUM; 
83
		return TOK_NUM; 
84
	}
84
	}
85
 
85
 
86
{DIGIT}+ {  /* decimal constant; make new tree node */
86
{DIGIT}+ {  /* decimal constant; make new tree node */
87
		/* {DIGIT}*(\.{DIGIT}+)?([eE][\+\-]?{DIGIT}+)? */
87
		/* {DIGIT}*(\.{DIGIT}+)?([eE][\+\-]?{DIGIT}+)? */
88
		yylval = newnode(TOK_NUM);
88
		yylval = newnode(TOK_NUM);
89
#ifdef FP_VALUE
89
#ifdef FP_VALUE
90
		yylval->v.value = atof(yytext);
90
		yylval->v.value = atof(yytext);
91
#else
91
#else
92
		yylval->v.value = atoi(yytext);
92
		yylval->v.value = atoi(yytext);
93
#endif
93
#endif
94
		return TOK_NUM; 
94
		return TOK_NUM; 
95
	}
95
	}
96
 
96
 
97
"<<" { OP(SHLEFT); }
97
"<<" { OP(SHLEFT); }
98
">>" { OP(SHRIGHT); }
98
">>" { OP(SHRIGHT); }
99
"<=" { OP(LE); }
99
"<=" { OP(LE); }
100
">=" { OP(GE); }
100
">=" { OP(GE); }
101
"==" { OP(EQ); }
101
"==" { OP(EQ); }
102
"!=" { OP(NE); }
102
"!=" { OP(NE); }
103
"&&" { OP(LOGAND); }
103
"&&" { OP(LOGAND); }
104
"||" { OP(LOGOR); } 
104
"||" { OP(LOGOR); } 
105
	/* "**"	{ OP(EXP); } */
105
	/* "**"	{ OP(EXP); } */
106
 
106
 
107
 
107
 
108
[!~+\-*/%<>&^|?] { OP(yytext[0]); } /* an operator; make new tree node */
108
[!~+\-*/%<>&^|?] { OP(yytext[0]); } /* an operator; make new tree node */
109
 
109
 
110
,	{ /* comma is special; sometimes it's an operator, and sometimes a function argument separator */
110
,	{ /* comma is special; sometimes it's an operator, and sometimes a function argument separator */
111
		if(inarglist[arglistptr])
111
		if(inarglist[arglistptr])
112
			return TOK_ARGSEP;
112
			return TOK_ARGSEP;
113
		else{
113
		else{
114
			OP(yytext[0]);
114
			OP(yytext[0]);
115
		}
115
		}
116
	}
116
	}
117
 
117
 
118
[():] return yytext[0]; /* these tokens are just sugar; never tree nodes */
118
[():] return yytext[0]; /* these tokens are just sugar; never tree nodes */
119
 
119
 
120
[a-zA-Z][a-zA-Z0-9]+ { /* an identifier (more than one character); look it up */
120
[a-zA-Z][a-zA-Z0-9]+ { /* an identifier (more than one character); look it up */
121
		struct sym_rec *s = lookup(yytext);
121
		struct sym_rec *s = lookup(yytext);
122
		if(s){ /* a known function or variable; make a tree node for it */
122
		if(s){ /* a known function or variable; make a tree node for it */
123
			yylval = newnode(s->token);
123
			yylval = newnode(s->token);
124
			yylval->v.sym = s;
124
			yylval->v.sym = s;
125
			return s->token;
125
			return s->token;
126
		}else
126
		}else
127
			return TOK_UNKNOWN; 
127
			return TOK_UNKNOWN; 
128
	}
128
	}
129
 
129
 
130
[t] {
130
[t] {
131
		yylval = newnode(TOK_NUM);
131
		yylval = newnode(TOK_NUM);
132
		yylval->v.value = 0;
132
		yylval->v.value = 0;
133
		return TOK_NUM; 
133
		return TOK_NUM; 
134
	}
134
	}
135
 
135
 
136
[rgbaciuvxyzpdmXYZDMRGBACIUV] { /* single character variable */
136
[rgbaciuvxyzpdmXYZDMRGBACIUV] { /* single character variable */
137
		yylval = newnode(TOK_SPECIALVAR);
137
		yylval = newnode(TOK_SPECIALVAR);
138
		yylval->v.specialvar = yytext[0];
138
		yylval->v.specialvar = yytext[0];
139
		/* values are defined in process.c */
139
		/* values are defined in process.c */
140
		return TOK_SPECIALVAR;
140
		return TOK_SPECIALVAR;
141
	}
141
	}
142
 
142
 
143
.	return TOK_BADCHAR;
143
.	return TOK_BADCHAR;
144
 
144
 
145
%%
145
%%