OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
parsetree.h
1/*
2===========================================================================
3Copyright (C) 2025 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// parsetree.h: Abstract Syntax Layer for Lexer/Parser
24
25#pragma once
26
27#include "str.h"
28
29#if defined(GAME_DLL)
30# define showopcodes g_showopcodes
31#elif defined(CGAME_DLL)
32# define showopcodes cg_showopcodes
33#else
34# define showopcodes g_showopcodes
35#endif
36
37typedef enum {
38 ENUM_NOP,
39 ENUM_ptr,
40 ENUM_statement_list,
41 ENUM_labeled_statement,
42 ENUM_int_labeled_statement,
43 ENUM_neg_int_labeled_statement,
44 ENUM_assignment_statement,
45 ENUM_if_statement,
46 ENUM_if_else_statement,
47 ENUM_while_statement,
48 ENUM_logical_and,
49 ENUM_logical_or,
50 ENUM_method_event_statement,
51 ENUM_method_event_expr,
52 ENUM_cmd_event_statement,
53 ENUM_cmd_event_expr,
54 ENUM_field,
55 ENUM_listener,
56 ENUM_string,
57 ENUM_integer,
58 ENUM_float,
59 ENUM_vector,
60 ENUM_NULL,
61 ENUM_NIL,
62 ENUM_func1_expr,
63 ENUM_func2_expr,
64 ENUM_bool_not,
65 ENUM_array_expr,
66 ENUM_const_array_expr,
67 ENUM_makearray,
68 ENUM_try,
69 ENUM_switch,
70 ENUM_break,
71 ENUM_continue,
72 ENUM_do,
73 ENUM_privatelabel,
74 ENUM_define
75} sval_type_e;
76
77union sval_u {
78 int type;
79 const char *stringValue;
80 float floatValue;
81 int intValue;
82 char charValue;
83 unsigned char byteValue;
84 unsigned char *posValue;
85 int MaxVarStackOffset;
86 int HasExternal;
87 union sval_u *node;
88 unsigned int sourcePosValue;
89};
90
91using sval_t = sval_u;
92
93struct stype_t {
94 sval_t val;
95 unsigned int sourcePos;
96};
97
98enum parseStage_e {
99 PS_TYPE,
100 PS_BODY,
101 PS_BODY_END
102};
103
104enum {
105 method_game,
106 method_level,
107 method_local,
108 method_parm,
109 method_self,
110 method_group,
111 method_owner,
112 method_field,
113 method_array,
114};
115
116void parsetree_freeall();
117void parsetree_init();
118size_t parsetree_length();
119char *parsetree_malloc(size_t s);
120
121sval_u append_lists(sval_u val1, sval_u val2);
122sval_u append_node(sval_u val1, sval_u val2);
123sval_u prepend_node(sval_u val1, sval_u val2);
124
125sval_u linked_list_end(sval_u val);
126
127sval_u node1_(int val1);
128sval_u node1b(int val1);
129sval_u node_pos(unsigned int pos);
130sval_u node_string(char *text);
131
132sval_u node0(int type);
133sval_u node1(int type, sval_u val1);
134sval_u node2(int type, sval_u val1, sval_u val2);
135sval_u node3(int type, sval_u val1, sval_u val2, sval_u val3);
136sval_u node4(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4);
137sval_u node5(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5);
138sval_u node6(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5, sval_u val6);
139sval_u node_listener(sval_u val1, sval_u val2);
140
141typedef struct parse_pos_s {
142 int sourcePos;
143 int first_line;
144 int first_column;
145 int last_line;
146 int last_column;
147} parse_pos_t;
148
149struct yyexception {
150 int yylineno;
151 str yytext;
152 str yytoken;
153
154 yyexception() { yylineno = 0; }
155};
156
157struct yyparsedata {
158 size_t total_length;
159
160 int braces_count;
161 int line_count;
162 unsigned int pos;
163 sval_t val;
164
165 char *sourceBuffer;
166 class GameScript *gameScript;
167
168 yyexception exc;
169
170 yyparsedata()
171 {
172 total_length = 0, braces_count = 0, line_count = 0, pos = 0;
173 val = sval_t();
174 sourceBuffer = NULL;
175 gameScript = NULL;
176 }
177};
178
179extern yyparsedata parsedata;
Definition gamescript.h:118
Definition str.h:77
Definition parsetree.h:141
Definition parsetree.h:93
Definition parsetree.h:149
Definition parsetree.h:157
Definition parsetree.h:77