2014-02-15 12:52:04 +08:00
|
|
|
%{
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-02-15 12:52:04 +08:00
|
|
|
/*
|
|
|
|
* phpdbg_parser.y
|
2014-02-17 07:17:16 +08:00
|
|
|
* (from php-src root)
|
2014-02-15 12:52:04 +08:00
|
|
|
*/
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-02-15 12:52:04 +08:00
|
|
|
#include "phpdbg.h"
|
|
|
|
#include "phpdbg_cmd.h"
|
2014-02-17 07:12:24 +08:00
|
|
|
#include "phpdbg_utils.h"
|
2014-02-19 04:04:02 +08:00
|
|
|
#include "phpdbg_cmd.h"
|
2014-02-18 06:43:53 +08:00
|
|
|
#include "phpdbg_prompt.h"
|
2014-02-15 12:52:04 +08:00
|
|
|
|
|
|
|
#define YYSTYPE phpdbg_param_t
|
|
|
|
|
2014-02-17 05:38:55 +08:00
|
|
|
#include "phpdbg_parser.h"
|
|
|
|
#include "phpdbg_lexer.h"
|
|
|
|
|
2014-06-09 04:34:30 +08:00
|
|
|
#undef yyerror
|
2014-12-16 19:56:00 +08:00
|
|
|
static int yyerror(const char *msg);
|
2014-06-09 04:34:30 +08:00
|
|
|
|
2016-02-17 06:47:37 +08:00
|
|
|
ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
|
2014-02-17 07:12:24 +08:00
|
|
|
|
2015-08-02 22:26:48 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define YYMALLOC malloc
|
|
|
|
#define YYFREE free
|
|
|
|
#endif
|
|
|
|
|
2014-02-15 12:52:04 +08:00
|
|
|
%}
|
2014-06-09 04:34:30 +08:00
|
|
|
|
|
|
|
%pure-parser
|
|
|
|
%error-verbose
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-02-15 12:52:04 +08:00
|
|
|
%code requires {
|
2014-02-17 07:12:24 +08:00
|
|
|
#include "phpdbg.h"
|
2014-02-15 12:52:04 +08:00
|
|
|
#ifndef YY_TYPEDEF_YY_SCANNER_T
|
|
|
|
#define YY_TYPEDEF_YY_SCANNER_T
|
|
|
|
typedef void* yyscan_t;
|
|
|
|
#endif
|
|
|
|
}
|
2014-06-09 04:34:30 +08:00
|
|
|
|
2014-02-17 06:47:20 +08:00
|
|
|
%output "sapi/phpdbg/phpdbg_parser.c"
|
|
|
|
%defines "sapi/phpdbg/phpdbg_parser.h"
|
2014-06-09 04:34:30 +08:00
|
|
|
|
|
|
|
%token T_EVAL "eval"
|
|
|
|
%token T_RUN "run"
|
|
|
|
%token T_SHELL "shell"
|
|
|
|
%token T_IF "if (condition)"
|
|
|
|
%token T_TRUTHY "truthy (true, on, yes or enabled)"
|
|
|
|
%token T_FALSY "falsy (false, off, no or disabled)"
|
|
|
|
%token T_STRING "string (some input, perhaps)"
|
|
|
|
%token T_COLON ": (colon)"
|
|
|
|
%token T_DCOLON ":: (double colon)"
|
2015-09-18 04:52:55 +08:00
|
|
|
%token T_POUND "# (pound sign followed by digits)"
|
|
|
|
%token T_SEPARATOR "# (pound sign)"
|
2014-06-09 04:34:30 +08:00
|
|
|
%token T_PROTO "protocol (file://)"
|
|
|
|
%token T_DIGITS "digits (numbers)"
|
|
|
|
%token T_LITERAL "literal (string)"
|
|
|
|
%token T_ADDR "address"
|
|
|
|
%token T_OPCODE "opcode"
|
|
|
|
%token T_ID "identifier (command or function name)"
|
|
|
|
%token T_INPUT "input (input string or data)"
|
|
|
|
%token T_UNEXPECTED "input"
|
2014-10-06 17:26:08 +08:00
|
|
|
%token T_REQ_ID "request id (-r %d)"
|
2014-06-09 04:34:30 +08:00
|
|
|
|
|
|
|
%% /* Rules */
|
2014-02-15 12:52:04 +08:00
|
|
|
|
|
|
|
input
|
2015-09-18 04:52:55 +08:00
|
|
|
: command { $$ = $1; }
|
|
|
|
| input T_SEPARATOR command { phpdbg_stack_separate($1.top); $$ = $3; }
|
2014-06-09 04:34:30 +08:00
|
|
|
| /* nothing */
|
|
|
|
;
|
2014-02-15 12:52:04 +08:00
|
|
|
|
2015-09-18 04:52:55 +08:00
|
|
|
command
|
|
|
|
: parameters { $$.top = PHPDBG_G(parser_stack)->top; }
|
|
|
|
| full_expression { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); $$.top = PHPDBG_G(parser_stack)->top; }
|
|
|
|
;
|
|
|
|
|
2014-02-15 12:52:04 +08:00
|
|
|
parameters
|
2015-09-18 04:52:55 +08:00
|
|
|
: parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); $$.top = PHPDBG_G(parser_stack)->top; }
|
|
|
|
| parameters parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$2); $$.top = PHPDBG_G(parser_stack)->top; }
|
2014-10-06 17:26:08 +08:00
|
|
|
| parameters req_id { $$ = $1; }
|
2014-02-15 12:52:04 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
parameter
|
2015-01-03 17:22:58 +08:00
|
|
|
: T_ID T_COLON T_DIGITS {
|
2014-02-21 22:44:16 +08:00
|
|
|
$$.type = FILE_PARAM;
|
2014-02-28 15:41:34 +08:00
|
|
|
$$.file.name = $2.str;
|
2014-02-21 22:44:16 +08:00
|
|
|
$$.file.line = $3.num;
|
|
|
|
}
|
2014-06-09 04:34:30 +08:00
|
|
|
| T_ID T_COLON T_POUND T_DIGITS {
|
2014-02-22 02:01:50 +08:00
|
|
|
$$.type = NUMERIC_FILE_PARAM;
|
|
|
|
$$.file.name = $1.str;
|
|
|
|
$$.file.line = $4.num;
|
|
|
|
}
|
2014-06-09 04:34:30 +08:00
|
|
|
| T_PROTO T_ID T_COLON T_DIGITS {
|
2014-02-28 15:41:34 +08:00
|
|
|
$$.type = FILE_PARAM;
|
2014-06-09 04:34:30 +08:00
|
|
|
$$.file.name = malloc($1.len + $2.len + 1);
|
2014-02-28 15:41:34 +08:00
|
|
|
if ($$.file.name) {
|
|
|
|
memcpy(&$$.file.name[0], $1.str, $1.len);
|
|
|
|
memcpy(&$$.file.name[$1.len], $2.str, $2.len);
|
|
|
|
$$.file.name[$1.len + $2.len] = '\0';
|
|
|
|
}
|
|
|
|
$$.file.line = $4.num;
|
|
|
|
}
|
2014-06-09 04:34:30 +08:00
|
|
|
| T_PROTO T_ID T_COLON T_POUND T_DIGITS {
|
2014-02-28 15:41:34 +08:00
|
|
|
$$.type = NUMERIC_FILE_PARAM;
|
2014-06-09 04:34:30 +08:00
|
|
|
$$.file.name = malloc($1.len + $2.len + 1);
|
2014-02-28 15:41:34 +08:00
|
|
|
if ($$.file.name) {
|
|
|
|
memcpy(&$$.file.name[0], $1.str, $1.len);
|
|
|
|
memcpy(&$$.file.name[$1.len], $2.str, $2.len);
|
|
|
|
$$.file.name[$1.len + $2.len] = '\0';
|
|
|
|
}
|
|
|
|
$$.file.line = $5.num;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
| T_ID T_DCOLON T_ID {
|
2014-02-21 22:44:16 +08:00
|
|
|
$$.type = METHOD_PARAM;
|
|
|
|
$$.method.class = $1.str;
|
2014-02-22 02:52:06 +08:00
|
|
|
$$.method.name = $3.str;
|
2014-02-21 22:44:16 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
| T_ID T_DCOLON T_ID T_POUND T_DIGITS {
|
2014-02-21 22:44:16 +08:00
|
|
|
$$.type = NUMERIC_METHOD_PARAM;
|
|
|
|
$$.method.class = $1.str;
|
|
|
|
$$.method.name = $3.str;
|
2015-01-03 17:22:58 +08:00
|
|
|
$$.num = $5.num;
|
2014-02-21 22:44:16 +08:00
|
|
|
}
|
2014-06-09 04:34:30 +08:00
|
|
|
| T_ID T_POUND T_DIGITS {
|
2014-02-21 22:44:16 +08:00
|
|
|
$$.type = NUMERIC_FUNCTION_PARAM;
|
|
|
|
$$.str = $1.str;
|
|
|
|
$$.len = $1.len;
|
2015-01-03 17:22:58 +08:00
|
|
|
$$.num = $3.num;
|
2014-02-21 22:44:16 +08:00
|
|
|
}
|
2014-06-29 17:40:48 +08:00
|
|
|
| T_IF T_INPUT {
|
2015-01-03 17:22:58 +08:00
|
|
|
$$.type = COND_PARAM;
|
2014-06-29 17:40:48 +08:00
|
|
|
$$.str = $2.str;
|
|
|
|
$$.len = $2.len;
|
|
|
|
}
|
2014-06-09 04:34:30 +08:00
|
|
|
| T_OPCODE { $$ = $1; }
|
|
|
|
| T_ADDR { $$ = $1; }
|
|
|
|
| T_LITERAL { $$ = $1; }
|
|
|
|
| T_TRUTHY { $$ = $1; }
|
|
|
|
| T_FALSY { $$ = $1; }
|
|
|
|
| T_DIGITS { $$ = $1; }
|
|
|
|
| T_ID { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
2014-10-06 17:26:08 +08:00
|
|
|
req_id
|
|
|
|
: T_REQ_ID { PHPDBG_G(req_id) = $1.num; }
|
|
|
|
| /* empty */
|
|
|
|
;
|
|
|
|
|
2014-06-09 04:34:30 +08:00
|
|
|
full_expression
|
2015-01-03 17:22:58 +08:00
|
|
|
: T_EVAL req_id T_INPUT {
|
|
|
|
$$.type = EVAL_PARAM;
|
2014-10-09 20:54:08 +08:00
|
|
|
$$.str = $3.str;
|
|
|
|
$$.len = $3.len;
|
2014-02-21 22:44:16 +08:00
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
| T_SHELL req_id T_INPUT {
|
|
|
|
$$.type = SHELL_PARAM;
|
2014-10-09 20:54:08 +08:00
|
|
|
$$.str = $3.str;
|
|
|
|
$$.len = $3.len;
|
2014-02-21 22:44:16 +08:00
|
|
|
}
|
2014-10-06 17:26:08 +08:00
|
|
|
| T_RUN req_id {
|
2014-04-20 19:28:11 +08:00
|
|
|
$$.type = RUN_PARAM;
|
|
|
|
$$.len = 0;
|
|
|
|
}
|
2015-01-03 17:22:58 +08:00
|
|
|
| T_RUN req_id T_INPUT {
|
|
|
|
$$.type = RUN_PARAM;
|
2014-10-09 20:54:08 +08:00
|
|
|
$$.str = $3.str;
|
|
|
|
$$.len = $3.len;
|
2014-04-16 19:56:26 +08:00
|
|
|
}
|
2014-02-15 12:52:04 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
2014-06-09 04:34:30 +08:00
|
|
|
|
2014-12-16 19:56:00 +08:00
|
|
|
static int yyerror(const char *msg) {
|
2014-10-06 17:26:08 +08:00
|
|
|
phpdbg_error("command", "type=\"parseerror\" msg=\"%s\"", "Parse Error: %s", msg);
|
2014-06-09 04:34:30 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
const phpdbg_param_t *top = PHPDBG_G(parser_stack);
|
2015-01-03 17:22:58 +08:00
|
|
|
|
2014-06-09 04:34:30 +08:00
|
|
|
while (top) {
|
|
|
|
phpdbg_param_debug(top, "--> ");
|
|
|
|
top = top->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
int phpdbg_do_parse(phpdbg_param_t *stack, char *input) {
|
2015-08-04 06:00:10 +08:00
|
|
|
if (!*input) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-02 19:45:20 +08:00
|
|
|
if (PHPDBG_G(cur_command)) {
|
|
|
|
free(PHPDBG_G(cur_command));
|
|
|
|
}
|
|
|
|
PHPDBG_G(cur_command) = strdup(input);
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
phpdbg_init_lexer(stack, input);
|
2014-06-09 04:34:30 +08:00
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
return yyparse();
|
2014-06-09 04:34:30 +08:00
|
|
|
}
|