3 // This file is part of the aMule Project.
5 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Copyright (c) 2005-2011 Froenchenko Leonid ( lfroen@gmail.com / http://www.amule.org )
8 // Any parts of this program derived from the xMule, lMule or eMule project,
9 // or contributed by third-party developers are copyrighted by their
10 // respective authors.
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "php_syntree.h"
30 #include "php_parser.h"
32 void php_set_input_buffer(char *buf, int len)
34 yy_delete_buffer(YY_CURRENT_BUFFER);
35 yy_scan_bytes(buf, len);
41 #define MAX_INCLUDE_DEPTH 10
42 YY_BUFFER_STATE php_include_stack[MAX_INCLUDE_DEPTH];
43 int php_include_stack_ptr = 0;
47 if ( --php_include_stack_ptr < 0 ) {
50 yy_delete_buffer( YY_CURRENT_BUFFER );
51 yy_switch_to_buffer(php_include_stack[php_include_stack_ptr] );
66 FLOANUM ([0-9]*[\.][0-9]+)|([0-9]+[\.][0-9]*)
67 HEX_NUM "0x"[0-9a-fA-F]+
69 IDENT [a-zA-Z_][a-zA-Z0-9_]*
71 EOL ("\r"|"\n"|"\r\n")
75 "<?php" return START_SCRIPT;
76 "?>" return END_SCRIPT;
78 "exit"|"die" return EXIT;
80 "function" return FUNCTION;
84 "return" return RETURN;
88 "elseif" return ELSEIF;
92 "endwhile" return ENDWHILE;
96 "endfor" return ENDFOR;
97 "foreach" return FOREACH;
99 "endforeach" return ENDFOREACH;
101 "switch" return SWITCH;
102 "endswitch" return ENDSWITCH;
104 "default" return DEFAULT;
105 "break" return BREAK;
107 "continue" return CONTINUE;
109 "echo" return T_ECHO;
110 "print" return PRINT;
114 "->" return OBJECT_OPERATOR;
117 "array" return ARRAY;
121 "=>" return HASH_ASSIGN;
124 "xor" return LOG_XOR;
125 "and" return LOG_AND;
126 "||" return BOOLEAN_OR;
127 "&&" return BOOLEAN_AND;
130 "-=" return MINUS_EQ;
133 ".=" return CONCAT_EQ;
141 "===" return IS_IDENTICAL;
142 "!===" return IS_NOIDENTICAL;
144 "!=" return IS_NOEQUAL;
145 "<=" return IS_SMALLER_OR_EQ;
146 ">=" return IS_GREATER_OR_EQ;
148 "global" return GLOBAL;
149 "static" return STATIC;
151 "include" BEGIN(INCLUDE);
153 <INCLUDE>\'[a-zA-Z_][a-zA-Z0-9_\.\-]*\' {
154 yytext[strlen(yytext)-1] = 0;
155 if ( php_include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
156 fprintf( stderr, "WARNING: maximum include depth (which is %d) exceed", MAX_INCLUDE_DEPTH);
158 php_include_stack[php_include_stack_ptr++] = YY_CURRENT_BUFFER;
159 yyin = fopen(yytext+1, "r");
161 printf("WARNING: include file [%s] can not be opened\n", yytext+1);
163 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE ));
169 "("[ \t]*("int"|"integer")[ \t]*")" {
173 "("[ \t]*("real"|"double"|"float")[ \t]*")" {
177 "("[ \t]*"string"[ \t]*")" {
181 "("[ \t]*("bool"|"boolean")[ \t]*")" {
190 <LINE_COMMENT>[^\n\r]+ {
194 <LINE_COMMENT>{EOL} {
199 BEGIN(BLOCK_COMMENT);
203 <BLOCK_COMMENT>"*/" {
208 phplval.exp_node = get_var_node(yytext+1);
213 strcpy(phplval.str_val, yytext);
219 sscanf(yytext, "0x%16x", &val);
220 phplval.exp_node = make_const_exp_dnum(val);
225 phplval.exp_node = make_const_exp_dnum(atoi(yytext));
230 phplval.exp_node = make_const_exp_fnum(atof(yytext));
235 yytext[strlen(yytext)-1] = 0;
236 phplval.exp_node = make_const_exp_str(yytext+1, 1);
241 yytext[strlen(yytext)-1] = 0;
242 phplval.exp_node = make_const_exp_str(yytext+1, 0);