2 * Copyright 2011 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
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
29 #define YYLEX_PARAM ctx
30 #define YYPARSE_PARAM ctx
32 static int parser_error(const char*);
34 static void parse_complete(parser_ctx_t*);
36 static void source_add_statement(parser_ctx_t*,statement_t*);
38 static member_expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
40 static statement_t *new_call_statement(parser_ctx_t*,member_expression_t*);
49 statement_t *statement;
50 member_expression_t *member;
54 %token <string> tIdentifier
56 %type <statement> Statement StatementNl
57 %type <member> MemberExpression
62 : SourceElements tEOF { parse_complete(ctx); }
66 | SourceElements StatementNl { source_add_statement(ctx, $2); }
69 : Statement tNL { $$ = $1; }
72 : MemberExpression /* FIXME: Arguments_opt */ { $$ = new_call_statement(ctx, $1); }
75 : tIdentifier { $$ = new_member_expression(ctx, NULL, $1); }
76 /* FIXME: MemberExpressionArgs '.' tIdentifier */
80 static int parser_error(const char *str)
85 static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
88 ctx->stats_tail->next = stat;
89 ctx->stats_tail = stat;
91 ctx->stats = ctx->stats_tail = stat;
95 static void parse_complete(parser_ctx_t *ctx)
97 ctx->parse_complete = TRUE;
100 static void *new_expression(parser_ctx_t *ctx, expression_type_t type, unsigned size)
104 expr = parser_alloc(ctx, size ? size : sizeof(*expr));
113 static member_expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *obj_expr, const WCHAR *identifier)
115 member_expression_t *expr;
117 expr = new_expression(ctx, EXPR_MEMBER, sizeof(*expr));
121 expr->obj_expr = obj_expr;
122 expr->identifier = identifier;
127 static void *new_statement(parser_ctx_t *ctx, statement_type_t type, unsigned size)
131 stat = parser_alloc(ctx, size);
140 static statement_t *new_call_statement(parser_ctx_t *ctx, member_expression_t *expr)
142 call_statement_t *stat;
144 stat = new_statement(ctx, STAT_CALL, sizeof(*stat));
152 void *parser_alloc(parser_ctx_t *ctx, size_t size)
157 ret = heap_alloc(size);
159 ctx->hres = E_OUTOFMEMORY;
163 HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
165 ctx->code = ctx->ptr = code;
166 ctx->end = ctx->code + strlenW(ctx->code);
168 ctx->parse_complete = FALSE;
171 ctx->last_token = tNL;
173 ctx->stats = ctx->stats_tail = NULL;
177 if(FAILED(ctx->hres))
179 if(!ctx->parse_complete) {
180 FIXME("parser failed on parsing %s\n", debugstr_w(ctx->ptr));