Source code of Windows XP (NT5)
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.

127 lines
3.5 KiB

  1. // header file with all the necessary structures and tables for
  2. // the expression evaluator.
  3. //
  4. // Modifications:
  5. //
  6. // 15-Nov-1993 JdR Major speed improvements
  7. // 26-Jul-1988 rj Removed entry defining "^" as bitwise xor. Left the
  8. // BIT_XOR entries in to avoid bothering with rpn.c.
  9. // Then realized it had to go in, so fixed it to handle
  10. // IBM and Microsoft versions properly.
  11. typedef struct rpn_info {
  12. UCHAR type;
  13. INT_PTR valPtr; // value or ptr to string
  14. }RPNINFO;
  15. // The precedence vector is also indexed by the operator/operand type
  16. // code to get the precedence for the operator/operand.
  17. // The precedence is used to determine if an item is to stay on the
  18. // temporary stack or is to be moved to the reverse-polish list.
  19. static UCHAR precVector[] = {
  20. 0, // right paren ')'
  21. 1, // logical or
  22. 2, // logical and
  23. 3, // bit or
  24. 4, // bit xor
  25. 5, // bit and
  26. 6, // equals '!='
  27. 6, // equals '=='
  28. 7, // relation '>'
  29. 7, // relation '<'
  30. 7, // relation '>='
  31. 7, // relation '<='
  32. 8, // shift '>>'
  33. 8, // shift '<<'
  34. 9, // add '-'
  35. 9, // add '+'
  36. 10, // mult '%'
  37. 10, // mult '/'
  38. 10, // mult '*'
  39. 11, // unary '-'
  40. 11, // unary '~'
  41. 11, // unary '!'
  42. 12, // primary int
  43. 12, // primary str
  44. 12, // primary str-sp
  45. 0 // left paren '('
  46. };
  47. // these are the various type codes for the operator/operand tokens
  48. #define RIGHT_PAREN 0
  49. #define LOGICAL_OR 1
  50. #define LOGICAL_AND 2
  51. #define BIT_OR 3
  52. #define BIT_XOR 4
  53. #define BIT_AND 5
  54. #define NOT_EQUAL 6
  55. #define EQUAL 7
  56. #define GREATER_THAN 8
  57. #define LESS_THAN 9
  58. #define GREATER_EQ 10
  59. #define LESS_EQ 11
  60. #define SHFT_RIGHT 12
  61. #define SHFT_LEFT 13
  62. #define BINARY_MINUS 14
  63. #define ADD 15
  64. #define MODULUS 16
  65. #define DIVIDE 17
  66. #define MULTIPLY 18
  67. #define UNARY_MINUS 19
  68. #define COMPLEMENT 20
  69. #define LOGICAL_NOT 21
  70. #define INTEGER 22
  71. #define STR 23
  72. #define PROG_INVOC_STR 24
  73. #define LEFT_PAREN 25
  74. // error table used by the getTok() routines to detect illegal token combinations.
  75. // The table is explained with the routine check_syntax_error()
  76. static UCHAR errTable[5][5] = {
  77. { 0, 1, 0, 0, 1 },
  78. { 1, 0, 1, 1, 0 },
  79. { 1, 0, 0, 1, 0 },
  80. { 1, 0, 1, 1, 0 },
  81. { 0, 1, 0, 0, 1 }
  82. };
  83. // we save space by placing most of the tokens returned to the
  84. // expr-eval parser in a table as shown below. At any time, the
  85. // longest possible token is to be returned, hence the order of
  86. // the strings is very important. eg: '||' is placed BEFORE '|'
  87. typedef struct _tok_tab_rec {
  88. char *op_str;
  89. UCHAR op;
  90. } TOKTABREC;
  91. static TOKTABREC tokTable[] = {
  92. { "(", LEFT_PAREN },
  93. { ")", RIGHT_PAREN },
  94. { "*", MULTIPLY },
  95. { "/", DIVIDE },
  96. { "%", MODULUS },
  97. { "+", ADD },
  98. { "<<", SHFT_LEFT },
  99. { ">>", SHFT_RIGHT },
  100. { "<=", LESS_EQ },
  101. { ">=", GREATER_EQ },
  102. { "<", LESS_THAN },
  103. { ">", GREATER_THAN },
  104. { "==", EQUAL },
  105. { "!=", NOT_EQUAL },
  106. { "&&", LOGICAL_AND },
  107. { "||", LOGICAL_OR },
  108. { "&", BIT_AND },
  109. { "|", BIT_OR },
  110. { "^^", BIT_XOR },
  111. { "~", COMPLEMENT },
  112. { "!", LOGICAL_NOT },
  113. { NULL, 0 }
  114. };