Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236/* * Copyright 2014 Jacek Caban for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */%{#include "jscript.h"#include "engine.h"#include "parser.h"#include "wine/debug.h"WINE_DEFAULT_DEBUG_CHANNEL(jscript);%}%lex-param { parser_ctx_t *ctx }%parse-param { parser_ctx_t *ctx }%define api.pure%start CCExpr%union { ccval_t ccval;}%token tEQ tEQEQ tNEQ tNEQEQ tLSHIFT tRSHIFT tRRSHIFT tOR tAND tLEQ tGEQ%token <ccval> tCCValue%type <ccval> CCUnaryExpression CCLogicalORExpression CCLogicalANDExpression%type <ccval> CCBitwiseORExpression CCBitwiseXORExpression CCBitwiseANDExpression%type <ccval> CCEqualityExpression CCRelationalExpression CCShiftExpression CCAdditiveExpression CCMultiplicativeExpression%{static int cc_parser_error(parser_ctx_t *ctx, const char *str){ if(SUCCEEDED(ctx->hres)) { WARN("%s\n", str); ctx->hres = JS_E_SYNTAX; } return 0;}static int cc_parser_lex(void *lval, parser_ctx_t *ctx){ int r; r = try_parse_ccval(ctx, lval); if(r) return r > 0 ? tCCValue : -1; switch(*ctx->ptr) { case '(': case ')': case '+': case '-': case '*': case '/': case '~': case '%': case '^': return *ctx->ptr++; case '=': if(*++ctx->ptr == '=') { if(*++ctx->ptr == '=') { ctx->ptr++; return tEQEQ; } return tEQ; } break; case '!': if(*++ctx->ptr == '=') { if(*++ctx->ptr == '=') { ctx->ptr++; return tNEQEQ; } return tNEQ; } return '!'; case '<': switch(*++ctx->ptr) { case '<': ctx->ptr++; return tLSHIFT; case '=': ctx->ptr++; return tLEQ; default: return '<'; } case '>': switch(*++ctx->ptr) { case '>': if(*++ctx->ptr == '>') { ctx->ptr++; return tRRSHIFT; } return tRSHIFT; case '=': ctx->ptr++; return tGEQ; default: return '>'; } case '|': if(*++ctx->ptr == '|') { ctx->ptr++; return tOR; } return '|'; case '&': if(*++ctx->ptr == '&') { ctx->ptr++; return tAND; } return '&'; } WARN("Failed to interpret %s\n", debugstr_w(ctx->ptr)); return -1;}%}%%/* FIXME: Implement missing expressions. */CCExpr : CCUnaryExpression { ctx->ccval = $1; YYACCEPT; }CCUnaryExpression : tCCValue { $$ = $1; } | '(' CCLogicalORExpression ')' { $$ = $2; } | '!' CCUnaryExpression { $$ = ccval_bool(!get_ccbool($2)); }; | '~' CCUnaryExpression { FIXME("'~' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; } | '+' CCUnaryExpression { FIXME("'+' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; } | '-' CCUnaryExpression { FIXME("'-' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCLogicalORExpression : CCLogicalANDExpression { $$ = $1; } | CCLogicalORExpression tOR CCLogicalANDExpression { FIXME("'||' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCLogicalANDExpression : CCBitwiseORExpression { $$ = $1; } | CCBitwiseANDExpression tAND CCBitwiseORExpression { FIXME("'&&' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCBitwiseORExpression : CCBitwiseXORExpression { $$ = $1; } | CCBitwiseORExpression '|' CCBitwiseXORExpression { FIXME("'|' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCBitwiseXORExpression : CCBitwiseANDExpression { $$ = $1; } | CCBitwiseXORExpression '^' CCBitwiseANDExpression { FIXME("'^' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCBitwiseANDExpression : CCEqualityExpression { $$ = $1; } | CCBitwiseANDExpression '&' CCEqualityExpression { FIXME("'&' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCEqualityExpression : CCRelationalExpression { $$ = $1; } | CCEqualityExpression tEQ CCRelationalExpression { $$ = ccval_bool(get_ccnum($1) == get_ccnum($3)); } | CCEqualityExpression tNEQ CCRelationalExpression { $$ = ccval_bool(get_ccnum($1) != get_ccnum($3)); } | CCEqualityExpression tEQEQ CCRelationalExpression { FIXME("'===' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; } | CCEqualityExpression tNEQEQ CCRelationalExpression { FIXME("'!==' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCRelationalExpression : CCShiftExpression { $$ = $1; } | CCRelationalExpression '<' CCShiftExpression { $$ = ccval_bool(get_ccnum($1) < get_ccnum($3)); } | CCRelationalExpression tLEQ CCShiftExpression { $$ = ccval_bool(get_ccnum($1) <= get_ccnum($3)); } | CCRelationalExpression '>' CCShiftExpression { $$ = ccval_bool(get_ccnum($1) > get_ccnum($3)); } | CCRelationalExpression tGEQ CCShiftExpression { $$ = ccval_bool(get_ccnum($1) >= get_ccnum($3)); }CCShiftExpression : CCAdditiveExpression { $$ = $1; } | CCShiftExpression tLSHIFT CCAdditiveExpression { FIXME("'<<' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; } | CCShiftExpression tRSHIFT CCAdditiveExpression { FIXME("'>>' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; } | CCShiftExpression tRRSHIFT CCAdditiveExpression { FIXME("'>>>' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }CCAdditiveExpression : CCMultiplicativeExpression { $$ = $1; } | CCAdditiveExpression '+' CCMultiplicativeExpression { $$ = ccval_num(get_ccnum($1) + get_ccnum($3)); } | CCAdditiveExpression '-' CCMultiplicativeExpression { $$ = ccval_num(get_ccnum($1) - get_ccnum($3)); }CCMultiplicativeExpression : CCUnaryExpression { $$ = $1; } | CCMultiplicativeExpression '*' CCUnaryExpression { $$ = ccval_num(get_ccnum($1) * get_ccnum($3)); } | CCMultiplicativeExpression '/' CCUnaryExpression { $$ = ccval_num(get_ccnum($1) / get_ccnum($3)); } | CCMultiplicativeExpression '%' CCUnaryExpression { FIXME("'%%' expression not implemented\n"); ctx->hres = E_NOTIMPL; YYABORT; }%%BOOL parse_cc_expr(parser_ctx_t *ctx){ ctx->hres = S_OK; cc_parser_parse(ctx); return SUCCEEDED(ctx->hres);}