You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
3.7 KiB

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