2 // ========================================================================
5 // orbsvcs / Extended Trader Constraint Language parser.
11 // Carlos O'Ryan <coryan@uci.edu> based on previous work by
12 // Seth Widoff <sbw1@cs.wustl.edu>
13 // Jeff Parsons <j.parsons@vanderbilt.edu>
15 // ========================================================================
17 #include "ace/ETCL/ETCL_y.h"
18 #include "ace/ETCL/ETCL_constraint.h"
19 #include "ace/ETCL/ETCL_Interpreter.h"
21 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
23 extern int yylex (void);
24 extern void yyflush_current_buffer (void);
26 static void yyerror (const char *)
29 // Ignore error messages
32 ACE_END_VERSIONED_NAMESPACE_DECL
36 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
70 %token ETCL_CONSTRAINT
79 %token ETCL_DISCRIMINANT
85 %type <constraint> ETCL_IDENT
86 %type <constraint> ETCL_BOOLEAN
87 %type <constraint> ETCL_STRING
88 %type <constraint> ETCL_FLOAT
89 %type <constraint> ETCL_INTEGER
90 %type <constraint> expr_in
91 %type <constraint> constraint preference bool_or bool_and bool_compare
92 %type <constraint> expr_in expr_twiddle expr term factor_not factor
93 %type <constraint> union_pos union_val component_array
94 %type <constraint> component_array component_assoc component_pos
95 %type <constraint> component_dot component_ext component
105 preference: ETCL_MIN bool_or
106 { $$ = new ETCL_PREFERENCE_CLASS (ETCL_MIN, $2); }
108 { $$ = new ETCL_PREFERENCE_CLASS (ETCL_MAX, $2); }
110 { $$ = new ETCL_PREFERENCE_CLASS (ETCL_WITH, $2); }
112 { $$ = new ETCL_PREFERENCE_CLASS (ETCL_FIRST); }
114 { $$ = new ETCL_PREFERENCE_CLASS (ETCL_RANDOM); }
117 bool_or: bool_or ETCL_OR bool_and
118 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_OR, $1, $3); }
122 bool_and: bool_and ETCL_AND bool_compare
123 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_AND, $1, $3); }
127 bool_compare: expr_in ETCL_EQ expr_in
128 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_EQ, $1, $3); }
129 | expr_in ETCL_NE expr_in
130 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_NE, $1, $3); }
131 | expr_in ETCL_GT expr_in
132 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_GT, $1, $3); }
133 | expr_in ETCL_GE expr_in
134 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_GE, $1, $3); }
135 | expr_in ETCL_LT expr_in
136 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_LT, $1, $3); }
137 | expr_in ETCL_LE expr_in
138 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_LE, $1, $3); }
142 expr_in: expr_twiddle ETCL_IN component
143 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_IN, $1, $3); }
144 | expr_twiddle ETCL_IN ETCL_DOLLAR component
145 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_IN, $1, $4); }
149 expr_twiddle: expr ETCL_TWIDDLE expr
150 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_TWIDDLE, $1, $3); }
154 expr: expr ETCL_PLUS term
155 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_PLUS, $1, $3); }
156 | expr ETCL_MINUS term
157 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_MINUS, $1, $3); }
161 term: term ETCL_MULT factor_not
162 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_MULT, $1, $3); }
163 | term ETCL_DIV factor_not
164 { $$ = new ETCL_BINARY_EXPR_CLASS (ETCL_DIV, $1, $3); }
168 factor_not: ETCL_NOT factor
169 { $$ = new ETCL_UNARY_EXPR_CLASS (ETCL_NOT, $2); }
173 factor: ETCL_LPAREN bool_or ETCL_RPAREN
177 | ETCL_PLUS ETCL_INTEGER
178 { $$ = new ETCL_UNARY_EXPR_CLASS (ETCL_PLUS, $2); }
179 | ETCL_MINUS ETCL_INTEGER
180 { $$ = new ETCL_UNARY_EXPR_CLASS (ETCL_MINUS, $2); }
183 | ETCL_PLUS ETCL_FLOAT
184 { $$ = new ETCL_UNARY_EXPR_CLASS (ETCL_PLUS, $2); }
185 | ETCL_MINUS ETCL_FLOAT
186 { $$ = new ETCL_UNARY_EXPR_CLASS (ETCL_MINUS, $2); }
191 | ETCL_EXIST ETCL_IDENT
192 { $$ = new ETCL_EXIST_CLASS ($2); }
193 | ETCL_EXIST ETCL_DOLLAR component
194 { $$ = new ETCL_EXIST_CLASS ($3); }
195 | ETCL_DEFAULT ETCL_DOLLAR component
196 { $$ = new ETCL_DEFAULT_CLASS ($3); }
197 | ETCL_DOLLAR component
198 { $$ = new ETCL_EVAL_CLASS ($2); }
203 component: /* empty */
205 | ETCL_DOT component_dot
206 { $$ = new ETCL_DOT_CLASS ($2); }
208 | ETCL_IDENT component_ext
209 { $$ = new ETCL_COMPONENT_CLASS ($1, $2); }
215 component_ext: /* empty */
217 | ETCL_DOT component_dot
218 { $$ = new ETCL_Dot ($2); }
224 component_dot: ETCL_IDENT component_ext
225 { $$ = new ETCL_COMPONENT_CLASS ($1, $2); }
227 { $$ = new ETCL_SPECIAL_CLASS (ETCL_LENGTH); }
229 { $$ = new ETCL_SPECIAL_CLASS (ETCL_DISCRIMINANT); }
231 { $$ = new ETCL_SPECIAL_CLASS (ETCL_TYPE_ID); }
233 { $$ = new ETCL_SPECIAL_CLASS (ETCL_REPOS_ID); }
238 component_array: ETCL_LBRA ETCL_INTEGER ETCL_RBRA component_ext
239 { $$ = new ETCL_COMPONENT_ARRAY_CLASS ($2, $4); }
242 component_assoc: ETCL_LPAREN ETCL_IDENT ETCL_RPAREN component_ext
243 { $$ = new ETCL_COMPONENT_ASSOC_CLASS ($2, $4); }
246 component_pos: ETCL_INTEGER component_ext
247 { $$ = new ETCL_COMPONENT_POS_CLASS ($1, $2); }
250 union_pos: ETCL_LPAREN union_val ETCL_RPAREN component_ext
251 { $$ = new ETCL_UNION_POS_CLASS ($2, $4); }
254 union_val: /* empty */
257 { $$ = new ETCL_UNION_VALUE_CLASS (+1, $1); }
258 | ETCL_PLUS ETCL_INTEGER
259 { $$ = new ETCL_UNION_VALUE_CLASS (+1, $2); }
260 | ETCL_MINUS ETCL_INTEGER
261 { $$ = new ETCL_UNION_VALUE_CLASS (-1, $2); }
263 { $$ = new ETCL_UNION_VALUE_CLASS ($1); }
268 ACE_END_VERSIONED_NAMESPACE_DECL