48 |
#include "strbuf.h" |
#include "strbuf.h" |
49 |
#include "php_res.h" |
#include "php_res.h" |
50 |
|
|
51 |
|
#define lex_symbol_generation_rule(x) php_ ## x |
52 |
|
#define LEXLEX lex_symbol_generation_rule(lex) |
53 |
|
#define LEXTEXT lex_symbol_generation_rule(text) |
54 |
|
#define LEXLENG lex_symbol_generation_rule(leng) |
55 |
|
#define LEXRESTART lex_symbol_generation_rule(restart) |
56 |
|
#define LEXLINENO lex_symbol_generation_rule(lineno) |
57 |
|
|
58 |
#define PHP_TOKEN 1 |
#define PHP_TOKEN 1 |
59 |
#define PHP_VARIABLE 2 |
#define PHP_VARIABLE 2 |
60 |
#define PHP_STRING 3 |
#define PHP_STRING 3 |
107 |
#ifdef ECHO |
#ifdef ECHO |
108 |
#undef ECHO |
#undef ECHO |
109 |
#endif |
#endif |
110 |
#define ECHO debug_print("%s", phptext) |
#define ECHO debug_print("%s", LEXTEXT) |
111 |
#ifdef PUT |
#ifdef PUT |
112 |
#undef PUT |
#undef PUT |
113 |
#endif |
#endif |
139 |
ALPHANUM [a-zA-Z_\x80-\xff0-9] |
ALPHANUM [a-zA-Z_\x80-\xff0-9] |
140 |
WORD {ALPHA}{ALPHANUM}* |
WORD {ALPHA}{ALPHANUM}* |
141 |
%start PHP STRING LITERAL |
%start PHP STRING LITERAL |
142 |
%option 8bit caseless noyywrap nounput yylineno prefix="php" |
%option 8bit caseless noyywrap nounput yylineno prefix="php_" |
143 |
%% |
%% |
144 |
\n ECHO; |
\n ECHO; |
145 |
/* Start PHP */ |
/* Start PHP */ |
174 |
die("unexpected end of comment."); |
die("unexpected end of comment."); |
175 |
debug_print(">"); |
debug_print(">"); |
176 |
} |
} |
177 |
<PHP>"//".* debug_print("<%s>", phptext); |
<PHP>"//".* debug_print("<%s>", LEXTEXT); |
178 |
<PHP>"#".* debug_print("<%s>", phptext); |
<PHP>"#".* debug_print("<%s>", LEXTEXT); |
179 |
|
|
180 |
/* String */ |
/* String */ |
181 |
<PHP>\" { strbuf_reset(string); BEGIN STRING; } |
<PHP>\" { strbuf_reset(string); BEGIN STRING; } |
185 |
|
|
186 |
return PHP_STRING; |
return PHP_STRING; |
187 |
} |
} |
188 |
<STRING>\\. strbuf_puts(string, phptext); |
<STRING>\\. strbuf_puts(string, LEXTEXT); |
189 |
<STRING>. strbuf_putc(string, phptext[0]); |
<STRING>. strbuf_putc(string, LEXTEXT[0]); |
190 |
|
|
191 |
/* Literal */ |
/* Literal */ |
192 |
<PHP>\' { strbuf_reset(string); BEGIN LITERAL; } |
<PHP>\' { strbuf_reset(string); BEGIN LITERAL; } |
196 |
|
|
197 |
return PHP_STRING; |
return PHP_STRING; |
198 |
} |
} |
199 |
<LITERAL>\\. strbuf_puts(string, phptext); |
<LITERAL>\\. strbuf_puts(string, LEXTEXT); |
200 |
<LITERAL>. strbuf_putc(string, phptext[0]); |
<LITERAL>. strbuf_putc(string, LEXTEXT[0]); |
201 |
|
|
202 |
/* Cast */ |
/* Cast */ |
203 |
<PHP>\([ \t]*(bool|boolean|int|integer|real|double|float|string|array|object)[ \t]*\) |
<PHP>\([ \t]*(bool|boolean|int|integer|real|double|float|string|array|object)[ \t]*\) |
208 |
* ${abc}\0 |
* ${abc}\0 |
209 |
*/ |
*/ |
210 |
if (YY_START == STRING) |
if (YY_START == STRING) |
211 |
strbuf_puts(string, phptext); |
strbuf_puts(string, LEXTEXT); |
212 |
memcpy(phptext, &phptext[2], phpleng - 3); |
memcpy(LEXTEXT, &LEXTEXT[2], LEXLENG - 3); |
213 |
phptext[phpleng - 3] = '\0'; |
LEXTEXT[LEXLENG - 3] = '\0'; |
214 |
phpleng = phpleng - 3; |
LEXLENG = LEXLENG - 3; |
215 |
debug_print("<V:%s>", phptext); |
debug_print("<V:%s>", LEXTEXT); |
216 |
|
|
217 |
return PHP_VARIABLE; |
return PHP_VARIABLE; |
218 |
} |
} |
222 |
* $abc\0 |
* $abc\0 |
223 |
*/ |
*/ |
224 |
if (YY_START == STRING) |
if (YY_START == STRING) |
225 |
strbuf_puts(string, phptext); |
strbuf_puts(string, LEXTEXT); |
226 |
memcpy(phptext, &phptext[1], phpleng - 1); |
memcpy(LEXTEXT, &LEXTEXT[1], LEXLENG - 1); |
227 |
phptext[phpleng - 1] = '\0'; |
LEXTEXT[LEXLENG - 1] = '\0'; |
228 |
phpleng = phpleng - 1; |
LEXLENG = LEXLENG - 1; |
229 |
debug_print("<V:%s>", phptext); |
debug_print("<V:%s>", LEXTEXT); |
230 |
|
|
231 |
return PHP_VARIABLE; |
return PHP_VARIABLE; |
232 |
} |
} |
233 |
<PHP>{NUMBER} debug_print("<N:%s>", phptext); |
<PHP>{NUMBER} debug_print("<N:%s>", LEXTEXT); |
234 |
<PHP>{WORD} { |
<PHP>{WORD} { |
235 |
int id = php_reserved_word(phptext, phpleng); |
int id = php_reserved_word(LEXTEXT, LEXLENG); |
236 |
if (id) { |
if (id) { |
237 |
debug_print("<Reserved:%s>", phptext); |
debug_print("<Reserved:%s>", LEXTEXT); |
238 |
return id; |
return id; |
239 |
} else { |
} else { |
240 |
debug_print("<T:%s>", phptext); |
debug_print("<T:%s>", LEXTEXT); |
241 |
return PHP_TOKEN; |
return PHP_TOKEN; |
242 |
} |
} |
243 |
} |
} |
244 |
/* Operator */ |
/* Operator */ |
245 |
<PHP>[{}] { |
<PHP>[{}] { |
246 |
int c = phptext[0]; |
int c = LEXTEXT[0]; |
247 |
if (c == PHP_LBRACE) |
if (c == PHP_LBRACE) |
248 |
level++; |
level++; |
249 |
else |
else |
253 |
return c; |
return c; |
254 |
} |
} |
255 |
<PHP>[][()] { |
<PHP>[][()] { |
256 |
return phptext[0]; |
return LEXTEXT[0]; |
257 |
} |
} |
258 |
<PHP>[-+*/%&~^]=? ECHO; |
<PHP>[-+*/%&~^]=? ECHO; |
259 |
<PHP>[=><!]= ECHO; |
<PHP>[=><!]= ECHO; |
278 |
if (linetable_open(file) == -1) |
if (linetable_open(file) == -1) |
279 |
die("'%s' cannot open.", file); |
die("'%s' cannot open.", file); |
280 |
|
|
281 |
yyrestart(NULL); |
LEXRESTART(NULL); |
282 |
while ((token = phplex()) != 0) { |
while ((token = LEXLEX()) != 0) { |
283 |
switch (token) { |
switch (token) { |
284 |
case PHP_DEFINE: |
case PHP_DEFINE: |
285 |
if (phplex() != PHP_LPAREN) |
if (LEXLEX() != PHP_LPAREN) |
286 |
break; |
break; |
287 |
if (phplex() != PHP_STRING) |
if (LEXLEX() != PHP_STRING) |
288 |
break; |
break; |
289 |
if (target == DEF) |
if (target == DEF) |
290 |
PUT(strbuf_value(string), phplineno, file); |
PUT(strbuf_value(string), LEXLINENO, file); |
291 |
break; |
break; |
292 |
case PHP_CLASS: |
case PHP_CLASS: |
293 |
if (phplex() != PHP_TOKEN) |
if (LEXLEX() != PHP_TOKEN) |
294 |
break; |
break; |
295 |
if (target == DEF) |
if (target == DEF) |
296 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
297 |
break; |
break; |
298 |
case PHP_FUNCTION: |
case PHP_FUNCTION: |
299 |
case PHP_CFUNCTION: |
case PHP_CFUNCTION: |
300 |
case PHP_OLD_FUNCTION: |
case PHP_OLD_FUNCTION: |
301 |
if (phplex() != PHP_TOKEN) |
if (LEXLEX() != PHP_TOKEN) |
302 |
break; |
break; |
303 |
if (target == DEF) |
if (target == DEF) |
304 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
305 |
break; |
break; |
306 |
case PHP_VARIABLE: |
case PHP_VARIABLE: |
307 |
if (php_reserved_variable(phptext, phpleng)) { |
if (php_reserved_variable(LEXTEXT, LEXLENG)) { |
308 |
if (target == SYM) |
if (target == SYM) |
309 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
310 |
if (phplex() == PHP_LBRACK && phplex() == PHP_STRING && phplex() == PHP_RBRACK) { |
if (LEXLEX() == PHP_LBRACK && LEXLEX() == PHP_STRING && LEXLEX() == PHP_RBRACK) { |
311 |
char *str = strbuf_value(string); |
char *str = strbuf_value(string); |
312 |
|
|
313 |
if (strchr(str, '$') == 0) |
if (strchr(str, '$') == 0) |
314 |
if (target == SYM) |
if (target == SYM) |
315 |
PUT(str, phplineno, file); |
PUT(str, LEXLINENO, file); |
316 |
} |
} |
317 |
} else if (!strcmp(phptext, "this")) { |
} else if (!strcmp(LEXTEXT, "this")) { |
318 |
; |
; |
319 |
} else { |
} else { |
320 |
if (target == SYM) |
if (target == SYM) |
321 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
322 |
} |
} |
323 |
break; |
break; |
324 |
case PHP_POINTER: |
case PHP_POINTER: |
325 |
if (phplex() != PHP_TOKEN) |
if (LEXLEX() != PHP_TOKEN) |
326 |
break; |
break; |
327 |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
328 |
case PHP_TOKEN: |
case PHP_TOKEN: |
329 |
if (target == REF) { |
if (target == REF) { |
330 |
if (defined(phptext)) |
if (defined(LEXTEXT)) |
331 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
332 |
} else if (target == SYM) { |
} else if (target == SYM) { |
333 |
if (!defined(phptext)) |
if (!defined(LEXTEXT)) |
334 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
335 |
} |
} |
336 |
break; |
break; |
337 |
case PHP_NEW: |
case PHP_NEW: |
338 |
if (phplex() != PHP_TOKEN) |
if (LEXLEX() != PHP_TOKEN) |
339 |
break; |
break; |
340 |
if (target == REF) |
if (target == REF) |
341 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
342 |
break; |
break; |
343 |
/* |
/* |
344 |
* ${x->y} |
* ${x->y} |
345 |
*/ |
*/ |
346 |
case PHP_DOLLAR: |
case PHP_DOLLAR: |
347 |
if (phplex() != PHP_LBRACE) |
if (LEXLEX() != PHP_LBRACE) |
348 |
break; |
break; |
349 |
while ((token = phplex()) != PHP_RBRACE) { |
while ((token = LEXLEX()) != PHP_RBRACE) { |
350 |
if (token == PHP_TOKEN) { |
if (token == PHP_TOKEN) { |
351 |
if (target == REF) { |
if (target == REF) { |
352 |
if (defined(phptext)) |
if (defined(LEXTEXT)) |
353 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
354 |
} else if (target == SYM) { |
} else if (target == SYM) { |
355 |
if (!defined(phptext)) |
if (!defined(LEXTEXT)) |
356 |
PUT(phptext, phplineno, file); |
PUT(LEXTEXT, LEXLINENO, file); |
357 |
} |
} |
358 |
} |
} |
359 |
} |
} |