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