windows.networking.hostname/tests: Add IHostNameFactory::CreateHostName() tests.
[wine.git] / dlls / jscript / cc_parser.y
blob46354f479ee8504cf40a8b8ccc1639f4cc9bf35c
1 /*
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
21 #include "jscript.h"
22 #include "engine.h"
23 #include "parser.h"
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_}
34 %define api.pure
35 %start CCExpr
37 %union {
38 ccval_t ccval;
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)) {
53 WARN("%s\n", str);
54 ctx->hres = JS_E_SYNTAX;
57 return 0;
60 static int cc_parser_lex(void *lval, parser_ctx_t *ctx)
62 int r;
64 r = try_parse_ccval(ctx, lval);
65 if(r)
66 return r > 0 ? tCCValue : -1;
68 switch(*ctx->ptr) {
69 case '(':
70 case ')':
71 case '+':
72 case '-':
73 case '*':
74 case '/':
75 case '~':
76 case '%':
77 case '^':
78 return *ctx->ptr++;
79 case '=':
80 if(*++ctx->ptr == '=') {
81 if(*++ctx->ptr == '=') {
82 ctx->ptr++;
83 return tEQEQ;
85 return tEQ;
87 break;
88 case '!':
89 if(*++ctx->ptr == '=') {
90 if(*++ctx->ptr == '=') {
91 ctx->ptr++;
92 return tNEQEQ;
94 return tNEQ;
96 return '!';
97 case '<':
98 switch(*++ctx->ptr) {
99 case '<':
100 ctx->ptr++;
101 return tLSHIFT;
102 case '=':
103 ctx->ptr++;
104 return tLEQ;
105 default:
106 return '<';
108 case '>':
109 switch(*++ctx->ptr) {
110 case '>':
111 if(*++ctx->ptr == '>') {
112 ctx->ptr++;
113 return tRRSHIFT;
115 return tRSHIFT;
116 case '=':
117 ctx->ptr++;
118 return tGEQ;
119 default:
120 return '>';
122 case '|':
123 if(*++ctx->ptr == '|') {
124 ctx->ptr++;
125 return tOR;
127 return '|';
128 case '&':
129 if(*++ctx->ptr == '&') {
130 ctx->ptr++;
131 return tAND;
133 return '&';
136 WARN("Failed to interpret %s\n", debugstr_w(ctx->ptr));
137 return -1;
144 /* FIXME: Implement missing expressions. */
146 CCExpr
147 : CCUnaryExpression { ctx->ccval = $1; YYACCEPT; }
149 CCUnaryExpression
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; }
182 CCEqualityExpression
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)); }
204 CCShiftExpression
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; }
213 CCAdditiveExpression
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)
233 ctx->hres = S_OK;
234 cc_parser_parse(ctx);
235 return SUCCEEDED(ctx->hres);