vbscript: Added exp expression parser/compiler implementation.
[wine] / dlls / vbscript / parse.h
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 typedef enum {
20     EXPR_ADD,
21     EXPR_BOOL,
22     EXPR_CONCAT,
23     EXPR_DIV,
24     EXPR_DOUBLE,
25     EXPR_EMPTY,
26     EXPR_EQUAL,
27     EXPR_EXP,
28     EXPR_IDIV,
29     EXPR_MEMBER,
30     EXPR_MOD,
31     EXPR_MUL,
32     EXPR_NEG,
33     EXPR_NEQUAL,
34     EXPR_NOT,
35     EXPR_NULL,
36     EXPR_STRING,
37     EXPR_SUB,
38     EXPR_ULONG,
39     EXPR_USHORT
40 } expression_type_t;
41
42 typedef struct _expression_t {
43     expression_type_t type;
44     struct _expression_t *next;
45 } expression_t;
46
47 typedef struct {
48     expression_t expr;
49     VARIANT_BOOL value;
50 } bool_expression_t;
51
52 typedef struct {
53     expression_t expr;
54     LONG value;
55 } int_expression_t;
56
57 typedef struct {
58     expression_t expr;
59     double value;
60 } double_expression_t;
61
62 typedef struct {
63     expression_t expr;
64     const WCHAR *value;
65 } string_expression_t;
66
67 typedef struct {
68     expression_t expr;
69     expression_t *subexpr;
70 } unary_expression_t;
71
72 typedef struct {
73     expression_t expr;
74     expression_t *left;
75     expression_t *right;
76 } binary_expression_t;
77
78 typedef struct {
79     expression_t expr;
80     expression_t *obj_expr;
81     const WCHAR *identifier;
82     expression_t *args;
83 } member_expression_t;
84
85 typedef enum {
86     STAT_ASSIGN,
87     STAT_CALL,
88     STAT_IF,
89     STAT_DIM
90 } statement_type_t;
91
92 typedef struct _statement_t {
93     statement_type_t type;
94     struct _statement_t *next;
95 } statement_t;
96
97 typedef struct {
98     statement_t stat;
99     member_expression_t *expr;
100 } call_statement_t;
101
102 typedef struct {
103     statement_t stat;
104     member_expression_t *member_expr;
105     expression_t *value_expr;
106 } assign_statement_t;
107
108 typedef struct _dim_decl_t {
109     const WCHAR *name;
110     struct _dim_decl_t *next;
111 } dim_decl_t;
112
113 typedef struct _dim_statement_t {
114     statement_t stat;
115     dim_decl_t *dim_decls;
116 } dim_statement_t;
117
118 typedef struct _elseif_decl_t {
119     expression_t *expr;
120     statement_t *stat;
121     struct _elseif_decl_t *next;
122 } elseif_decl_t;
123
124 typedef struct {
125     statement_t stat;
126     expression_t *expr;
127     statement_t *if_stat;
128     elseif_decl_t *elseifs;
129     statement_t *else_stat;
130 } if_statement_t;
131
132 typedef struct {
133     const WCHAR *code;
134     const WCHAR *ptr;
135     const WCHAR *end;
136
137     BOOL option_explicit;
138     BOOL parse_complete;
139     HRESULT hres;
140
141     int last_token;
142     unsigned last_nl;
143
144     statement_t *stats;
145     statement_t *stats_tail;
146
147     vbsheap_t heap;
148 } parser_ctx_t;
149
150 HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
151 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
152 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
153 void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;