Imported Upstream version 2.8.9
[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   - add __HP_aCC to the #if test for yyerrorlab warning suppression
24
25 */
26
27 /* Configure the parser to use a lexer object.  */
28 #define YYPARSE_PARAM yyscanner
29 #define YYLEX_PARAM yyscanner
30 #define YYERROR_VERBOSE 1
31 #define cmExpr_yyerror(x) \
32         cmExprError(yyscanner, x)
33 #define yyGetParser (cmExpr_yyget_extra(yyscanner))
34
35 /*-------------------------------------------------------------------------*/
36 #include "cmExprParserHelper.h" /* Interface to parser object.  */
37 #include "cmExprLexer.h"  /* Interface to lexer object.  */
38 #include "cmExprParserTokens.h" /* Need YYSTYPE for YY_DECL.  */
39
40 #include <math.h>
41
42 /* Forward declare the lexer entry point.  */
43 YY_DECL;
44
45 /* Internal utility functions.  */
46 static void cmExprError(yyscan_t yyscanner, const char* message);
47
48 #define YYDEBUG 1
49 //#define YYMAXDEPTH 100000
50 //#define YYINITDEPTH 10000
51
52
53 /* Disable some warnings in the generated code.  */
54 #ifdef __BORLANDC__
55 # pragma warn -8004 /* Variable assigned a value that is not used.  */
56 # pragma warn -8008 /* condition always returns true */
57 # pragma warn -8060 /* possibly incorrect assignment */
58 # pragma warn -8066 /* unreachable code */
59 #endif
60 #ifdef _MSC_VER
61 # pragma warning (disable: 4102) /* Unused goto label.  */
62 # pragma warning (disable: 4065) /* Switch statement contains default but no case. */
63 #endif
64 %}
65
66 /* Generate a reentrant parser object.  */
67 %pure_parser
68
69 /*-------------------------------------------------------------------------*/
70 /* Tokens */
71 %token exp_PLUS
72 %token exp_MINUS
73 %token exp_TIMES
74 %token exp_DIVIDE
75 %token exp_MOD
76 %token exp_SHIFTLEFT
77 %token exp_SHIFTRIGHT
78 %token exp_OPENPARENT
79 %token exp_CLOSEPARENT
80 %token exp_OR;
81 %token exp_AND;
82 %token exp_XOR;
83 %token exp_NOT;
84 %token exp_NUMBER;
85
86 /*-------------------------------------------------------------------------*/
87 /* grammar */
88 %%
89
90
91 Start:
92 exp
93 {
94   yyGetParser->SetResult($<Number>1);
95 }
96
97 exp:
98 bitwiseor
99 {$<Number>$ = $<Number>1;}
100 |
101 exp exp_OR bitwiseor
102 {$<Number>$ = $<Number>1 | $<Number>3;}
103
104 bitwiseor:
105 bitwisexor
106 {$<Number>$ = $<Number>1;}
107 |
108 bitwiseor exp_XOR bitwisexor
109 {$<Number>$ = $<Number>1 ^ $<Number>3;}
110
111 bitwisexor:
112 bitwiseand
113 {$<Number>$ = $<Number>1;}
114 |
115 bitwisexor exp_AND bitwiseand
116 {$<Number>$ = $<Number>1 & $<Number>3;}
117
118 bitwiseand:
119 shift
120 {$<Number>$ = $<Number>1;}
121 |
122 bitwiseand exp_SHIFTLEFT shift
123 {$<Number>$ = $<Number>1 << $<Number>3;}
124 |
125 bitwiseand exp_SHIFTRIGHT shift
126 {$<Number>$ = $<Number>1 >> $<Number>3;}
127
128
129 shift:
130 term
131 {$<Number>$ = $<Number>1;}
132 |
133 shift exp_PLUS term
134 {$<Number>$ = $<Number>1 + $<Number>3;}
135 |
136 shift exp_MINUS term
137 {$<Number>$ = $<Number>1 - $<Number>3;}
138
139 term:
140 factor
141 {$<Number>$ = $<Number>1;}
142 |
143 term exp_TIMES factor
144 {$<Number>$ = $<Number>1 * $<Number>3;}
145 |
146 term exp_DIVIDE factor
147 {$<Number>$ = $<Number>1 / $<Number>3;}
148 |
149 term exp_MOD factor
150 {$<Number>$ = $<Number>1 % $<Number>3;}
151
152 factor:
153 exp_NUMBER
154 {$<Number>$ = $<Number>1;}
155 |
156 exp_OPENPARENT exp exp_CLOSEPARENT
157 {$<Number>$ = $<Number>2;}
158 ;
159
160
161 %%
162 /* End of grammar */
163
164 /*--------------------------------------------------------------------------*/
165 void cmExprError(yyscan_t yyscanner, const char* message)
166 {
167   yyGetParser->Error(message);
168 }
169