%{ /* +----------------------------------------------------------------------+ | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of one of the following licenses: | | | | A) 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. | | | | B) the PHP License as published by the PHP Development Team and | | included in the distribution in the file: LICENSE | | | | 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 both licenses referred to here. | | If you did not, or have any questions about PHP licensing, please | | contact core@php.net. | +----------------------------------------------------------------------+ | Authors: Andi Gutmans | | Zeev Suraski | +----------------------------------------------------------------------+ */ /* $Id: language-scanner.lex,v 1.12 1998/05/15 10:56:55 zeev Exp $ */ %} %x IN_PHP %x ENCAPS %x SINGLE_QUOTE %{ #include "token_cache.h" #include "language-parser.tab.h" #include "language-scanner.h" #include "main.h" #if WIN32|WINNT #include #include #include #endif #define YY_DECL int lex_scan(pval *phplval) #ifdef __cplusplus # define MY_INPUT yyinput #else # define MY_INPUT input #endif void end_php() { BEGIN(INITIAL); } %} LNUM [0-9]+ DNUM [0-9]*[\.][0-9]+ HNUM "0x"[0-9a-fA-F]+ LABEL [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* WHITESPACE [ \n\r\t]+ TOKENS [;:,.\[\]()|^&+-/*=%!~$<>{}?@] ENCAPSED_TOKENS [\[\]\\$] ESCAPED_AND_WHITESPACE [\n\t\r #`'.:;,()|^&+-/*=%!~<>{}?@]+ %option noyylineno %option noyywrap %% "exit" { return EXIT; } "die" { return EXIT; } "function"|"cfunction" { return FUNCTION; } "return" { return RETURN; } "if" { return IF; } "elseif" { return ELSEIF; } "endif" { return ENDIF; } "else" { return ELSE; } "while" { return WHILE; } "endwhile" { return ENDWHILE; } "do" { return DO; } "for" { return FOR; } "switch" { return SWITCH; } "endswitch" { return ENDSWITCH; } "case" { return CASE; } "default" { return DEFAULT; } "break" { return BREAK; } "continue" { return CONTINUE; } "echo" { return PHPECHO; } "header" { return PHPHEADER; } "class" { return CLASS; } "extends" { return EXTENDS; } "new" { return NEW; } "var" { return VAR; } "(int)" { return INT_CAST; } "(double)" { return DOUBLE_CAST; } "(string)" { return STRING_CAST; } "eval" { return EVAL; } "include" { return INCLUDE; } "_include" { return _INCLUDE; } "show_source" { return SHOW_SOURCE; } "global" { return PHP_GLOBAL; } "isset" { return PHP_ISSET; } "static" { return PHP_STATIC; } "unset" { return PHP_UNSET; } "=>" { return PHP_DOUBLE_ARROW; } "list" { return PHP_LIST; } "array" { return PHP_ARRAY; } "++" { return INCREMENT; } "--" { return DECREMENT; } "==" { return IS_EQUAL; } "!="|"<>" { return IS_NOT_EQUAL; } "<=" { return IS_SMALLER_OR_EQUAL; } ">=" { return IS_GREATER_OR_EQUAL; } "+=" { return PLUS_EQUAL; } "-=" { return MINUS_EQUAL; } "*=" { return MUL_EQUAL; } "/=" { return DIV_EQUAL; } ".=" { return CONCAT_EQUAL; } "%=" { return MOD_EQUAL; } "&=" { return AND_EQUAL; } "|=" { return OR_EQUAL; } "^=" { return XOR_EQUAL; } "||" { return BOOLEAN_OR; } "&&" { return BOOLEAN_AND; } "OR" { return LOGICAL_OR; } "AND" { return LOGICAL_AND; } {TOKENS} { return yytext[0]; } {LNUM}|{HNUM} { phplval->value.lval = strtol(yytext, NULL, 0); phplval->type = IS_LONG; return LNUMBER; } {DNUM} { phplval->value.dval = atof(yytext); phplval->type = IS_DOUBLE; return DNUMBER; } ([^<]|"<"[^?]){1,400} { int i; phplval->value.strval = (char *) estrndup(yytext, yyleng); phplval->strlen = yyleng; phplval->type = IS_STRING; return INLINE_HTML; } ""?>" { return END_PHP3; } {LABEL} { phplval->value.strval = (char *)estrndup(yytext, yyleng); phplval->strlen = yyleng; phplval->type = IS_STRING; return STRING; } [^"\\\n] { phplval->value.strval = (char *)estrndup(yytext, yyleng); phplval->strlen = yyleng; phplval->type = IS_STRING; return STRING; } [^'\\\n] { phplval->value.strval = (char *)estrndup(yytext, yyleng); phplval->strlen = yyleng; phplval->type = IS_STRING; return STRING; } {WHITESPACE} { printf("%s",yytext); } "#"[^\n]*"\n" { /* eat one line comments */ printf("%s",yytext); } "/*"([^*]|[*]+[^/])*"*/"([ ]*";")? { printf(yytext); } ["] { BEGIN(ENCAPS); return '\"'; } ['] { BEGIN(SINGLE_QUOTE); return '\''; } "\\\"" { phplval->value.chval = '"'; return CHAR; } "\\\'" { phplval->value.chval = '\''; return CHAR; } "\\n"|"\\t"|"\\r"|"\\\\"|"\\$"|"\\" { phplval->strlen = yyleng; phplval->value.strval = estrndup(yytext,yyleng); phplval->type = IS_STRING; return STRING; } ["] { BEGIN(IN_PHP); return '\"'; } ['] { BEGIN(IN_PHP); return '\''; } <> { yyterminate(); } . { /*php3_error(E_WARNING,"Unexpected character in input: '%c' (ASCII=%d) state=%d",yytext[0],yytext[0],YYSTATE);*/ }