proxy: avoid redundant assignment
[amule.git] / src / webserver / src / php_lexer.l
blob271e325bae2d476709bcaa70bc33703936da9f3d
1 %{
2 //
3 // This file is part of the aMule Project.
4 //
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 )
7 //
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
27 #include <string.h>
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);
38 int yywrap(void);
41 #define MAX_INCLUDE_DEPTH 10
42 YY_BUFFER_STATE php_include_stack[MAX_INCLUDE_DEPTH];
43 int php_include_stack_ptr = 0;
45 int yywrap(void)
47         if ( --php_include_stack_ptr < 0 ) {
48                 return 1;
49         } else {
50                 yy_delete_buffer( YY_CURRENT_BUFFER );
51                 yy_switch_to_buffer(php_include_stack[php_include_stack_ptr] );
52         }
53         return 0;
58 %x BLOCK_COMMENT
59 %x LINE_COMMENT
60 %x INCLUDE
62 %option stack
63 %option yylineno
65 DEC_NUM                 [0-9]+
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;
82 "const"                 return CONST;
84 "return"                return RETURN;
86 "if"                    return IF;
87 "else"                  return ELSE;
88 "elseif"                return ELSEIF;
89 "endif"                 return ENDIF;
91 "while"                 return WHILE;
92 "endwhile"              return ENDWHILE;
93 "do"                    return DO;
95 "for"                   return FOR;
96 "endfor"                return ENDFOR;
97 "foreach"               return FOREACH;
98 "as"                    return AS;
99 "endforeach"    return ENDFOREACH;
101 "switch"                return SWITCH;
102 "endswitch"             return ENDSWITCH;
103 "case"                  return CASE;
104 "default"               return DEFAULT;
105 "break"                 return BREAK;
107 "continue"              return CONTINUE;
109 "echo"                  return T_ECHO;
110 "print"                 return PRINT;
112 "new"                   return NEW;
114 "->"                    return OBJECT_OPERATOR;
116 "list"                  return LIST;
117 "array"                 return ARRAY;
119 "++"                    return INC;
120 "--"                    return DEC;
121 "=>"                    return HASH_ASSIGN;
123 "or"                    return LOG_OR;
124 "xor"                   return LOG_XOR;
125 "and"                   return LOG_AND;
126 "||"                    return BOOLEAN_OR;
127 "&&"                    return BOOLEAN_AND;
129 "+="                    return PLUS_EQ;
130 "-="                    return MINUS_EQ;
131 "*="                    return MUL_EQ;
132 "/="                    return DIV_EQ;
133 ".="                    return CONCAT_EQ;
134 "%="                    return MOD_EQ;
135 "&="                    return AND_EQ;
136 "|="                    return OR_EQ;
137 "^="                    return XOR_EQ;
138 "<<="                   return SL_EQ;
139 ">>="                   return SR_EQ;
141 "==="                   return IS_IDENTICAL;
142 "!==="                  return IS_NOIDENTICAL;
143 "=="                    return IS_EQ;
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);
152 <INCLUDE>[ \t]*
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);
157         } else {
158                 php_include_stack[php_include_stack_ptr++] = YY_CURRENT_BUFFER;
159                 yyin = fopen(yytext+1, "r");
160                 if ( !yyin ) {
161                         printf("WARNING: include file [%s] can not be opened\n", yytext+1);
162                 } else {
163                         yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE ));
164                 }
165         }
166         BEGIN(INITIAL);
169 "("[ \t]*("int"|"integer")[ \t]*")" {
170         return INT_CAST;
173 "("[ \t]*("real"|"double"|"float")[ \t]*")" {
174         return DOUBLE_CAST;
177 "("[ \t]*"string"[ \t]*")" {
178         return STRING_CAST;
181 "("[ \t]*("bool"|"boolean")[ \t]*")" {
182         return BOOL_CAST;
185 "#"|"//" {
186                 BEGIN(LINE_COMMENT);
187                 yymore();
188         }
190 <LINE_COMMENT>[^\n\r]+ {
191                 yymore();
192         }
194 <LINE_COMMENT>{EOL} {
195                 BEGIN(INITIAL);
196         }
198 "/*" {
199                 BEGIN(BLOCK_COMMENT);
200                 yymore();
201         }
203 <BLOCK_COMMENT>"*/" {
204                 BEGIN(INITIAL);
205         }
207 "$"{IDENT} {
208         phplval.exp_node = get_var_node(yytext+1);
209         return VARIABLE;
210         }
212 {IDENT} {
213         strcpy(phplval.str_val, yytext);
214         return IDENT;
215         }
217 {HEX_NUM} {
218         int val;
219         sscanf(yytext, "0x%16x", &val);
220         phplval.exp_node = make_const_exp_dnum(val);
221         return DNUMBER;
222         }
224 {DEC_NUM} {
225         phplval.exp_node = make_const_exp_dnum(atoi(yytext));
226         return DNUMBER;
227         }
229 {FLOANUM} {
230         phplval.exp_node = make_const_exp_fnum(atof(yytext));
231         return FNUMBER;
232         }
234 \"(\\.|[^\\"])*\" {
235                 yytext[strlen(yytext)-1] = 0;
236                 phplval.exp_node = make_const_exp_str(yytext+1, 1);
237                 return STRING;
240 \'(\\.|[^\\'])*\' {
241                 yytext[strlen(yytext)-1] = 0;
242                 phplval.exp_node = make_const_exp_str(yytext+1, 0);
243                 return STRING;
246 [ \t\v\n\r\f]           {  }
248 . {
249                 return yytext[0];