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