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
}
33 %define api.prefix
{cc_parser_
}
41 %token tEQ tEQEQ tNEQ tNEQEQ tLSHIFT tRSHIFT tRRSHIFT tOR tAND tLEQ tGEQ
42 %token
<ccval
> tCCValue
44 %type
<ccval
> CCUnaryExpression CCLogicalORExpression CCLogicalANDExpression
45 %type
<ccval
> CCBitwiseORExpression CCBitwiseXORExpression CCBitwiseANDExpression
46 %type
<ccval
> CCEqualityExpression CCRelationalExpression CCShiftExpression CCAdditiveExpression CCMultiplicativeExpression
50 static int cc_parser_error
(parser_ctx_t
*ctx
, const char *str
)
52 if
(SUCCEEDED
(ctx
->hres
)) {
54 ctx
->hres
= JS_E_SYNTAX
;
60 static int cc_parser_lex
(void *lval
, parser_ctx_t
*ctx
)
64 r
= try_parse_ccval
(ctx
, lval
);
66 return r
> 0 ? tCCValue
: -1;
80 if
(*++ctx
->ptr
== '=') {
81 if
(*++ctx
->ptr
== '=') {
89 if
(*++ctx
->ptr
== '=') {
90 if
(*++ctx
->ptr
== '=') {
109 switch
(*++ctx
->ptr
) {
111 if
(*++ctx
->ptr
== '>') {
123 if
(*++ctx
->ptr
== '|') {
129 if
(*++ctx
->ptr
== '&') {
136 WARN
("Failed to interpret %s\n", debugstr_w
(ctx
->ptr
));
144 /* FIXME: Implement missing expressions. */
147 : CCUnaryExpression
{ ctx
->ccval
= $1; YYACCEPT; }
150 : tCCValue
{ $$
= $1; }
151 |
'(' CCLogicalORExpression
')' { $$
= $2; }
152 |
'!' CCUnaryExpression
{ $$
= ccval_bool
(!get_ccbool
($2)); };
153 |
'~' CCUnaryExpression
{ FIXME
("'~' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
154 |
'+' CCUnaryExpression
{ FIXME
("'+' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
155 |
'-' CCUnaryExpression
{ FIXME
("'-' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
157 CCLogicalORExpression
158 : CCLogicalANDExpression
{ $$
= $1; }
159 | CCLogicalORExpression tOR CCLogicalANDExpression
160 { FIXME
("'||' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
162 CCLogicalANDExpression
163 : CCBitwiseORExpression
{ $$
= $1; }
164 | CCBitwiseANDExpression tAND CCBitwiseORExpression
165 { $$
= ccval_bool
(get_ccbool
($1) && get_ccbool
($3)); }
167 CCBitwiseORExpression
168 : CCBitwiseXORExpression
{ $$
= $1; }
169 | CCBitwiseORExpression
'|' CCBitwiseXORExpression
170 { FIXME
("'|' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
172 CCBitwiseXORExpression
173 : CCBitwiseANDExpression
{ $$
= $1; }
174 | CCBitwiseXORExpression
'^' CCBitwiseANDExpression
175 { FIXME
("'^' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
177 CCBitwiseANDExpression
178 : CCEqualityExpression
{ $$
= $1; }
179 | CCBitwiseANDExpression
'&' CCEqualityExpression
180 { FIXME
("'&' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
183 : CCRelationalExpression
{ $$
= $1; }
184 | CCEqualityExpression tEQ CCRelationalExpression
185 { $$
= ccval_bool
(get_ccnum
($1) == get_ccnum
($3)); }
186 | CCEqualityExpression tNEQ CCRelationalExpression
187 { $$
= ccval_bool
(get_ccnum
($1) != get_ccnum
($3)); }
188 | CCEqualityExpression tEQEQ CCRelationalExpression
189 { FIXME
("'===' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
190 | CCEqualityExpression tNEQEQ CCRelationalExpression
191 { FIXME
("'!==' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
193 CCRelationalExpression
194 : CCShiftExpression
{ $$
= $1; }
195 | CCRelationalExpression
'<' CCShiftExpression
196 { $$
= ccval_bool
(get_ccnum
($1) < get_ccnum
($3)); }
197 | CCRelationalExpression tLEQ CCShiftExpression
198 { $$
= ccval_bool
(get_ccnum
($1) <= get_ccnum
($3)); }
199 | CCRelationalExpression
'>' CCShiftExpression
200 { $$
= ccval_bool
(get_ccnum
($1) > get_ccnum
($3)); }
201 | CCRelationalExpression tGEQ CCShiftExpression
202 { $$
= ccval_bool
(get_ccnum
($1) >= get_ccnum
($3)); }
205 : CCAdditiveExpression
{ $$
= $1; }
206 | CCShiftExpression tLSHIFT CCAdditiveExpression
207 { FIXME
("'<<' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
208 | CCShiftExpression tRSHIFT CCAdditiveExpression
209 { FIXME
("'>>' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
210 | CCShiftExpression tRRSHIFT CCAdditiveExpression
211 { FIXME
("'>>>' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
214 : CCMultiplicativeExpression
{ $$
= $1; }
215 | CCAdditiveExpression
'+' CCMultiplicativeExpression
216 { $$
= ccval_num
(get_ccnum
($1) + get_ccnum
($3)); }
217 | CCAdditiveExpression
'-' CCMultiplicativeExpression
218 { $$
= ccval_num
(get_ccnum
($1) - get_ccnum
($3)); }
220 CCMultiplicativeExpression
221 : CCUnaryExpression
{ $$
= $1; }
222 | CCMultiplicativeExpression
'*' CCUnaryExpression
223 { $$
= ccval_num
(get_ccnum
($1) * get_ccnum
($3)); }
224 | CCMultiplicativeExpression
'/' CCUnaryExpression
225 { $$
= ccval_num
(get_ccnum
($1) / get_ccnum
($3)); }
226 | CCMultiplicativeExpression
'%' CCUnaryExpression
227 { FIXME
("'%%' expression not implemented\n"); ctx
->hres
= E_NOTIMPL
; YYABORT; }
231 BOOL parse_cc_expr
(parser_ctx_t
*ctx
)
234 cc_parser_parse
(ctx
);
235 return SUCCEEDED
(ctx
->hres
);