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