root/sapi/phpdbg/phpdbg_parser.y

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. yyerror
  2. phpdbg_do_parse

   1 %{
   2  
   3 /*
   4  * phpdbg_parser.y
   5  * (from php-src root)
   6  * flex sapi/phpdbg/dev/phpdbg_lexer.l
   7  * bison sapi/phpdbg/dev/phpdbg_parser.y
   8  */
   9  
  10 #include "phpdbg.h"
  11 #include "phpdbg_cmd.h"
  12 #include "phpdbg_utils.h"
  13 #include "phpdbg_cmd.h"
  14 #include "phpdbg_prompt.h"
  15 
  16 #define YYSTYPE phpdbg_param_t
  17 
  18 #include "phpdbg_parser.h"
  19 #include "phpdbg_lexer.h"
  20 
  21 #undef yyerror
  22 static int yyerror(void ***tsrm_ls, const char *msg);
  23 
  24 ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
  25 
  26 %}
  27 
  28 %pure-parser
  29 %error-verbose
  30  
  31 %code requires {
  32 #include "phpdbg.h"
  33 #ifndef YY_TYPEDEF_YY_SCANNER_T
  34 #define YY_TYPEDEF_YY_SCANNER_T
  35 typedef void* yyscan_t;
  36 #endif
  37 }
  38 
  39 %parse-param { void *tsrm_ls }
  40 
  41 %output  "sapi/phpdbg/phpdbg_parser.c"
  42 %defines "sapi/phpdbg/phpdbg_parser.h"
  43 
  44 %token T_EVAL       "eval"
  45 %token T_RUN        "run"
  46 %token T_SHELL      "shell"
  47 %token T_IF         "if (condition)"
  48 %token T_TRUTHY     "truthy (true, on, yes or enabled)"
  49 %token T_FALSY      "falsy (false, off, no or disabled)"
  50 %token T_STRING     "string (some input, perhaps)"
  51 %token T_COLON      ": (colon)"
  52 %token T_DCOLON     ":: (double colon)"
  53 %token T_POUND      "# (pound sign)"
  54 %token T_PROTO      "protocol (file://)"
  55 %token T_DIGITS     "digits (numbers)"
  56 %token T_LITERAL    "literal (string)"
  57 %token T_ADDR       "address"
  58 %token T_OPCODE     "opcode"
  59 %token T_ID         "identifier (command or function name)"
  60 %token T_INPUT      "input (input string or data)"
  61 %token T_UNEXPECTED "input"
  62 
  63 %% /* Rules */
  64 
  65 input
  66         : parameters
  67         | full_expression { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); }
  68         | /* nothing */
  69         ;
  70 
  71 parameters
  72         : parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); }
  73         | parameters parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$2); }
  74         ;
  75 
  76 parameter
  77         : T_ID T_COLON T_DIGITS {       
  78                 $$.type = FILE_PARAM;
  79                 $$.file.name = $2.str;
  80                 $$.file.line = $3.num;
  81         }
  82         | T_ID T_COLON T_POUND T_DIGITS {
  83                 $$.type = NUMERIC_FILE_PARAM;
  84                 $$.file.name = $1.str;
  85                 $$.file.line = $4.num;
  86         }
  87         | T_PROTO T_ID T_COLON T_DIGITS {
  88                 $$.type = FILE_PARAM;
  89                 $$.file.name = malloc($1.len + $2.len + 1);
  90                 if ($$.file.name) {
  91                         memcpy(&$$.file.name[0], $1.str, $1.len);
  92                         memcpy(&$$.file.name[$1.len], $2.str, $2.len);
  93                         $$.file.name[$1.len + $2.len] = '\0';
  94                 }
  95                 $$.file.line = $4.num;
  96         }
  97         | T_PROTO T_ID T_COLON T_POUND T_DIGITS {
  98                 $$.type = NUMERIC_FILE_PARAM;
  99                 $$.file.name = malloc($1.len + $2.len + 1);
 100                 if ($$.file.name) {
 101                         memcpy(&$$.file.name[0], $1.str, $1.len);
 102                         memcpy(&$$.file.name[$1.len], $2.str, $2.len);
 103                         $$.file.name[$1.len + $2.len] = '\0';
 104                 }
 105                 $$.file.line = $5.num;
 106         }
 107         | T_ID T_DCOLON T_ID { 
 108                 $$.type = METHOD_PARAM;
 109                 $$.method.class = $1.str;
 110                 $$.method.name = $3.str;
 111         }
 112         | T_ID T_DCOLON T_ID T_POUND T_DIGITS { 
 113                 $$.type = NUMERIC_METHOD_PARAM;
 114                 $$.method.class = $1.str;
 115                 $$.method.name = $3.str;
 116                 $$.num = $5.num; 
 117         }
 118         | T_ID T_POUND T_DIGITS {
 119                 $$.type = NUMERIC_FUNCTION_PARAM;
 120                 $$.str = $1.str;
 121                 $$.len = $1.len;
 122                 $$.num = $3.num; 
 123         }
 124         | T_IF T_INPUT {
 125                 $$.type = COND_PARAM; 
 126                 $$.str = $2.str;
 127                 $$.len = $2.len;
 128         }
 129         | T_OPCODE { $$ = $1; }
 130         | T_ADDR { $$ = $1; }
 131         | T_LITERAL { $$ = $1; }
 132         | T_TRUTHY { $$ = $1; }
 133         | T_FALSY { $$ = $1; }
 134         | T_DIGITS { $$ = $1; }
 135         | T_ID { $$ = $1; }
 136         ;
 137 
 138 full_expression
 139         : T_EVAL T_INPUT { 
 140                 $$.type = EVAL_PARAM; 
 141                 $$.str = $2.str;
 142                 $$.len = $2.len;
 143         }
 144         | T_SHELL T_INPUT {     
 145                 $$.type = SHELL_PARAM; 
 146                 $$.str = $2.str;
 147                 $$.len = $2.len;
 148         }
 149         | T_RUN {
 150                 $$.type = RUN_PARAM;
 151                 $$.len = 0;
 152         }
 153         | T_RUN T_INPUT {       
 154                 $$.type = RUN_PARAM; 
 155                 $$.str = $2.str;
 156                 $$.len = $2.len;
 157         }
 158         ;
 159 
 160 %%
 161 
 162 static int yyerror(void ***tsrm_ls, const char *msg) {
 163         phpdbg_error("Parse Error: %s", msg);
 164 
 165         {
 166                 const phpdbg_param_t *top = PHPDBG_G(parser_stack);
 167         
 168                 while (top) {
 169                         phpdbg_param_debug(top, "--> ");
 170                         top = top->next;
 171                 }
 172         }
 173         return 0;
 174 }
 175 
 176 int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC) {
 177         phpdbg_init_lexer(stack, input TSRMLS_CC);
 178 
 179 #ifdef ZTS
 180         return yyparse(TSRMLS_C);
 181 #else
 182         return yyparse(NULL);
 183 #endif
 184 }

/* [<][>][^][v][top][bottom][index][help] */