Subversion Repositories filter_foundry

Rev

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

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