Subversion Repositories filter_foundry

Rev

Rev 62 | Rev 192 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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