Subversion Repositories filter_foundry

Rev

Rev 41 | Go to most recent revision | Details | 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
 
22
//#ifdef TARGET_API_MAC_CARBON
23
//	/* can't use StdCLib ctype.h, it refers to symbols which aren't in OS X stdclib */
24
//	int toupper(int);
25
//#else
26
	#include <ctype.h>
27
//#endif
28
 
29
#include "node.h"
30
#include "dbg.h"
31
#include "y.tab.h"
32
 
33
#define yywrap() 1
34
 
35
/* the reason for these hacks is to prevent any references to stdlib,
36
   which cause load failures in OS X due to mismatch of headers/libraries
37
   when project is built with MPW */
38
 
39
#if defined(__MRC__) && TARGET_CARBON
40
#define stdin 0
41
#define stdout 0
42
#define stderr 0
43
#endif 
44
 
45
#define YY_FATAL_ERROR(msg)
46
#define YY_INPUT
47
#define YYDECL int yylex(void)
48
#define ECHO
49
#define YY_NEVER_INTERACTIVE 1
50
 
51
YYDECL;
52
 
53
int tokpos,tokstart;
54
 
55
extern YYSTYPE yylval;
56
extern int inarglist[],arglistptr,varused[];
57
 
58
#define OP(x) \
59
	yylval = newnode(x); \
60
	return x;
61
 
62
#define YY_USER_ACTION \
63
	tokstart = tokpos; \
64
	tokpos += yyleng;
65
 
66
%}
67
 
68
DIGIT		[0-9]
69
HEXDIGIT	[0-9A-Fa-f]
70
 
71
%%
72
 
73
[ \t\n\r]+|"//"[^\n\r]* ; /* ignore whitespace, comments */
74
 
75
0[xX]{HEXDIGIT}+ {  /* hex constant; make new tree node */
76
		int i,c;
77
		value_type v;
78
		char *p;
79
 
80
		for( i=yyleng-2,p=yytext+2,v = 0 ; i-- ; ){
81
			c = toupper(*p++);
82
			v *= 16;
83
			v += c - (c>='A' ? 'A'-10 : '0');
84
		}
85
		yylval = newnode(TOK_NUM);
86
		yylval->v.value = v;
87
		return TOK_NUM; 
88
	}
89
 
90
{DIGIT}+ {  /* decimal constant; make new tree node */
91
		/* {DIGIT}*(\.{DIGIT}+)?([eE][\+\-]?{DIGIT}+)? */
92
		yylval = newnode(TOK_NUM);
93
#ifdef FP_VALUE
94
		yylval->v.value = atof(yytext);
95
#else
96
		yylval->v.value = atoi(yytext);
97
#endif
98
		return TOK_NUM; 
99
	}
100
 
101
"<<" { OP(SHLEFT); }
102
">>" { OP(SHRIGHT); }
103
"<=" { OP(LE); }
104
">=" { OP(GE); }
105
"==" { OP(EQ); }
106
"!=" { OP(NE); }
107
"&&" { OP(LOGAND); }
108
"||" { OP(LOGOR); } 
109
	/* "**"	{ OP(EXP); } */
110
 
111
 
112
[!~+\-*/%<>&^|?] { OP(yytext[0]); } /* an operator; make new tree node */
113
 
114
,	{ /* comma is special; sometimes it's an operator, and sometimes a function argument separator */
115
		if(inarglist[arglistptr])
116
			return TOK_ARGSEP;
117
		else{
118
			OP(yytext[0]);
119
		}
120
	}
121
 
122
[():] return yytext[0]; /* these tokens are just sugar; never tree nodes */
123
 
124
[a-zA-Z][a-zA-Z0-9]+ { /* an identifier (more than one character); look it up */
125
		struct sym_rec *s = lookup(yytext);
126
		if(s){ /* a known function or variable; make a tree node for it */
127
			yylval = newnode(s->token);
128
			yylval->v.sym = s;
129
			return s->token;
130
		}else
131
			return TOK_UNKNOWN; 
132
	}
133
 
134
[rgbaciuvxyzdmXYZDM] { /* single character variable */
135
		yylval = newnode(TOK_SPECIALVAR);
136
		yylval->v.specialvar = yytext[0];
137
		return TOK_SPECIALVAR;
138
	}
139
 
140
.	return TOK_BADCHAR;
141
 
142
%%