2 * Copyright 2014 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL
(jscript
);
31 %lex
-param
{ parser_ctx_t
*ctx
}
32 %parse
-param
{ parser_ctx_t
*ctx
}
40 %token tEQ tEQEQ tNEQ tNEQEQ tLSHIFT tRSHIFT tRRSHIFT tOR tAND tLEQ tGEQ
41 %token
<ccval
> tCCValue
43 %type
<ccval
> CCUnaryExpression CCLogicalORExpression CCLogicalANDExpression
44 %type
<ccval
> CCBitwiseORExpression CCBitwiseXORExpression CCBitwiseANDExpression
45 %type
<ccval
> CCEqualityExpression CCRelationalExpression CCShiftExpression CCAdditiveExpression CCMultiplicativeExpression
49 static int cc_parser_error
(parser_ctx_t
*ctx
, const char *str
)
51 if
(SUCCEEDED
(ctx
->hres
)) {
53 ctx
->hres
= JS_E_SYNTAX
;
59 static int cc_parser_lex
(void *lval
, parser_ctx_t
*ctx
)
63 r
= try_parse_ccval
(ctx
, lval
);
65 return r
> 0 ? tCCValue
: -1;
79 if
(*++ctx
->ptr
== '=') {
80 if
(*++ctx
->ptr
== '=') {
88 if
(*++ctx
->ptr
== '=') {
89 if
(*++ctx
->ptr
== '=') {
108 switch
(*++ctx
->ptr
) {
110 if
(*++ctx
->ptr
== '>') {
122 if
(*++ctx
->ptr
== '|') {
128 if
(*++ctx
->ptr
== '&') {
135 WARN
("Failed to interpret %s\n", debugstr_w
(ctx
->ptr
));
143 /* FIXME: Implement missing expressions. */
146 : CCUnaryExpression
{ ctx
->ccval
= $1; YYACCEPT; }
149 : tCCValue
{ $$
= $1; }
150 |
'(' CCLogicalORExpression
')' { $$
= $2; }
151 |
'!' CCUnaryExpression
{ $$
= ccval_bool
(!get_ccbool
($2)); };
152 |
'~' CCUnaryExpression
{ FIXME
("'~' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
153 |
'+' CCUnaryExpression
{ FIXME
("'+' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
154 |
'-' CCUnaryExpression
{ FIXME
("'-' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
156 CCLogicalORExpression
157 : CCLogicalANDExpression
{ $$
= $1; }
158 | CCLogicalORExpression tOR CCLogicalANDExpression
159 { FIXME
("'||' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
161 CCLogicalANDExpression
162 : CCBitwiseORExpression
{ $$
= $1; }
163 | CCBitwiseANDExpression tAND CCBitwiseORExpression
164 { FIXME
("'&&' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
166 CCBitwiseORExpression
167 : CCBitwiseXORExpression
{ $$
= $1; }
168 | CCBitwiseORExpression
'|' CCBitwiseXORExpression
169 { FIXME
("'|' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
171 CCBitwiseXORExpression
172 : CCBitwiseANDExpression
{ $$
= $1; }
173 | CCBitwiseXORExpression
'^' CCBitwiseANDExpression
174 { FIXME
("'^' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
176 CCBitwiseANDExpression
177 : CCEqualityExpression
{ $$
= $1; }
178 | CCBitwiseANDExpression
'&' CCEqualityExpression
179 { FIXME
("'&' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
182 : CCRelationalExpression
{ $$
= $1; }
183 | CCEqualityExpression tEQ CCRelationalExpression
184 { $$
= ccval_bool
(get_ccnum
($1) == get_ccnum
($3)); }
185 | CCEqualityExpression tNEQ CCRelationalExpression
186 { $$
= ccval_bool
(get_ccnum
($1) != get_ccnum
($3)); }
187 | CCEqualityExpression tEQEQ CCRelationalExpression
188 { FIXME
("'===' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
189 | CCEqualityExpression tNEQEQ CCRelationalExpression
190 { FIXME
("'!==' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
192 CCRelationalExpression
193 : CCShiftExpression
{ $$
= $1; }
194 | CCRelationalExpression
'<' CCShiftExpression
195 { FIXME
("'<' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
196 | CCRelationalExpression tLEQ CCShiftExpression
197 { FIXME
("'<=' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
198 | CCRelationalExpression
'>' CCShiftExpression
199 { FIXME
("'>' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
200 | CCRelationalExpression tGEQ CCShiftExpression
201 { FIXME
("'>=' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
204 : CCAdditiveExpression
{ $$
= $1; }
205 | CCShiftExpression tLSHIFT CCAdditiveExpression
206 { FIXME
("'<<' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
207 | CCShiftExpression tRSHIFT CCAdditiveExpression
208 { FIXME
("'>>' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
209 | CCShiftExpression tRRSHIFT CCAdditiveExpression
210 { FIXME
("'>>>' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
213 : CCMultiplicativeExpression
{ $$
= $1; }
214 | CCAdditiveExpression
'+' CCMultiplicativeExpression
215 { $$
= ccval_num
(get_ccnum
($1) + get_ccnum
($3)); }
216 | CCAdditiveExpression
'-' CCMultiplicativeExpression
217 { $$
= ccval_num
(get_ccnum
($1) - get_ccnum
($3)); }
219 CCMultiplicativeExpression
220 : CCUnaryExpression
{ $$
= $1; }
221 | CCMultiplicativeExpression
'*' CCUnaryExpression
222 { $$
= ccval_num
(get_ccnum
($1) * get_ccnum
($3)); }
223 | CCMultiplicativeExpression
'/' CCUnaryExpression
224 { $$
= ccval_num
(get_ccnum
($1) / get_ccnum
($3)); }
225 | CCMultiplicativeExpression
'%' CCUnaryExpression
226 { FIXME
("'%%' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
230 BOOL parse_cc_expr
(parser_ctx_t
*ctx
)
233 cc_parser_parse
(ctx
);
234 return SUCCEEDED
(ctx
->hres
);