cmExprParser.y 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. %{
  2. /*============================================================================
  3. CMake - Cross Platform Makefile Generator
  4. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  5. Distributed under the OSI-approved BSD License (the "License");
  6. see accompanying file Copyright.txt for details.
  7. This software is distributed WITHOUT ANY WARRANTY; without even the
  8. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. See the License for more information.
  10. ============================================================================*/
  11. /*
  12. This file must be translated to C and modified to build everywhere.
  13. Run bison like this:
  14. bison --yacc --name-prefix=cmExpr_yy --defines=cmExprParserTokens.h -ocmExprParser.cxx cmExprParser.y
  15. Modify cmExprParser.cxx:
  16. - remove TABs
  17. - add __HP_aCC to the #if test for yyerrorlab warning suppression
  18. */
  19. /* Configure the parser to use a lexer object. */
  20. #define YYPARSE_PARAM yyscanner
  21. #define YYLEX_PARAM yyscanner
  22. #define YYERROR_VERBOSE 1
  23. #define cmExpr_yyerror(x) \
  24. cmExprError(yyscanner, x)
  25. #define yyGetParser (cmExpr_yyget_extra(yyscanner))
  26. /*-------------------------------------------------------------------------*/
  27. #include "cmExprParserHelper.h" /* Interface to parser object. */
  28. #include "cmExprLexer.h" /* Interface to lexer object. */
  29. #include "cmExprParserTokens.h" /* Need YYSTYPE for YY_DECL. */
  30. #include <math.h>
  31. /* Forward declare the lexer entry point. */
  32. YY_DECL;
  33. /* Internal utility functions. */
  34. static void cmExprError(yyscan_t yyscanner, const char* message);
  35. #define YYDEBUG 1
  36. //#define YYMAXDEPTH 100000
  37. //#define YYINITDEPTH 10000
  38. /* Disable some warnings in the generated code. */
  39. #ifdef __BORLANDC__
  40. # pragma warn -8004 /* Variable assigned a value that is not used. */
  41. # pragma warn -8008 /* condition always returns true */
  42. # pragma warn -8060 /* possibly incorrect assignment */
  43. # pragma warn -8066 /* unreachable code */
  44. #endif
  45. #ifdef _MSC_VER
  46. # pragma warning (disable: 4102) /* Unused goto label. */
  47. # pragma warning (disable: 4065) /* Switch statement contains default but no case. */
  48. #endif
  49. %}
  50. /* Generate a reentrant parser object. */
  51. %pure_parser
  52. /*-------------------------------------------------------------------------*/
  53. /* Tokens */
  54. %token exp_PLUS
  55. %token exp_MINUS
  56. %token exp_TIMES
  57. %token exp_DIVIDE
  58. %token exp_MOD
  59. %token exp_SHIFTLEFT
  60. %token exp_SHIFTRIGHT
  61. %token exp_OPENPARENT
  62. %token exp_CLOSEPARENT
  63. %token exp_OR;
  64. %token exp_AND;
  65. %token exp_XOR;
  66. %token exp_NOT;
  67. %token exp_NUMBER;
  68. /*-------------------------------------------------------------------------*/
  69. /* grammar */
  70. %%
  71. Start:
  72. exp
  73. {
  74. yyGetParser->SetResult($<Number>1);
  75. }
  76. exp:
  77. bitwiseor
  78. {$<Number>$ = $<Number>1;}
  79. |
  80. exp exp_OR bitwiseor
  81. {$<Number>$ = $<Number>1 | $<Number>3;}
  82. bitwiseor:
  83. bitwisexor
  84. {$<Number>$ = $<Number>1;}
  85. |
  86. bitwiseor exp_XOR bitwisexor
  87. {$<Number>$ = $<Number>1 ^ $<Number>3;}
  88. bitwisexor:
  89. bitwiseand
  90. {$<Number>$ = $<Number>1;}
  91. |
  92. bitwisexor exp_AND bitwiseand
  93. {$<Number>$ = $<Number>1 & $<Number>3;}
  94. bitwiseand:
  95. shift
  96. {$<Number>$ = $<Number>1;}
  97. |
  98. bitwiseand exp_SHIFTLEFT shift
  99. {$<Number>$ = $<Number>1 << $<Number>3;}
  100. |
  101. bitwiseand exp_SHIFTRIGHT shift
  102. {$<Number>$ = $<Number>1 >> $<Number>3;}
  103. shift:
  104. term
  105. {$<Number>$ = $<Number>1;}
  106. |
  107. shift exp_PLUS term
  108. {$<Number>$ = $<Number>1 + $<Number>3;}
  109. |
  110. shift exp_MINUS term
  111. {$<Number>$ = $<Number>1 - $<Number>3;}
  112. term:
  113. factor
  114. {$<Number>$ = $<Number>1;}
  115. |
  116. term exp_TIMES factor
  117. {$<Number>$ = $<Number>1 * $<Number>3;}
  118. |
  119. term exp_DIVIDE factor
  120. {$<Number>$ = $<Number>1 / $<Number>3;}
  121. |
  122. term exp_MOD factor
  123. {$<Number>$ = $<Number>1 % $<Number>3;}
  124. factor:
  125. exp_NUMBER
  126. {$<Number>$ = $<Number>1;}
  127. |
  128. exp_OPENPARENT exp exp_CLOSEPARENT
  129. {$<Number>$ = $<Number>2;}
  130. ;
  131. %%
  132. /* End of grammar */
  133. /*--------------------------------------------------------------------------*/
  134. void cmExprError(yyscan_t yyscanner, const char* message)
  135. {
  136. yyGetParser->Error(message);
  137. }