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