File: parsetree.h

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (179 lines) | stat: -rw-r--r-- 4,353 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
===========================================================================
Copyright (C) 2008 the OpenMoHAA team

This file is part of OpenMoHAA source code.

OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/

// parsetree.h: Abstract Syntax Layer for Lexer/Parser

#pragma once

#include "str.h"

#if defined(GAME_DLL)
#    define showopcodes g_showopcodes
#elif defined(CGAME_DLL)
#    define showopcodes cg_showopcodes
#else
#    define showopcodes g_showopcodes
#endif

typedef enum {
    ENUM_NOP,
    ENUM_ptr,
    ENUM_statement_list,
    ENUM_labeled_statement,
    ENUM_int_labeled_statement,
    ENUM_neg_int_labeled_statement,
    ENUM_assignment_statement,
    ENUM_if_statement,
    ENUM_if_else_statement,
    ENUM_while_statement,
    ENUM_logical_and,
    ENUM_logical_or,
    ENUM_method_event_statement,
    ENUM_method_event_expr,
    ENUM_cmd_event_statement,
    ENUM_cmd_event_expr,
    ENUM_field,
    ENUM_listener,
    ENUM_string,
    ENUM_integer,
    ENUM_float,
    ENUM_vector,
    ENUM_NULL,
    ENUM_NIL,
    ENUM_func1_expr,
    ENUM_func2_expr,
    ENUM_bool_not,
    ENUM_array_expr,
    ENUM_const_array_expr,
    ENUM_makearray,
    ENUM_try,
    ENUM_switch,
    ENUM_break,
    ENUM_continue,
    ENUM_do,
    ENUM_privatelabel,
    ENUM_define
} sval_type_e;

union sval_u {
    int            type;
    const char    *stringValue;
    float          floatValue;
    int            intValue;
    char           charValue;
    unsigned char  byteValue;
    unsigned char *posValue;
    int            MaxVarStackOffset;
    int            HasExternal;
    union sval_u  *node;
    unsigned int   sourcePosValue;
};

using sval_t = sval_u;

struct stype_t {
    sval_t       val;
    unsigned int sourcePos;
};

enum parseStage_e {
    PS_TYPE,
    PS_BODY,
    PS_BODY_END
};

enum {
    method_game,
    method_level,
    method_local,
    method_parm,
    method_self,
    method_group,
    method_owner,
    method_field,
    method_array,
};

void   parsetree_freeall();
void   parsetree_init();
size_t parsetree_length();
char  *parsetree_malloc(size_t s);

sval_u append_lists(sval_u val1, sval_u val2);
sval_u append_node(sval_u val1, sval_u val2);
sval_u prepend_node(sval_u val1, sval_u val2);

sval_u linked_list_end(sval_u val);

sval_u node1_(int val1);
sval_u node1b(int val1);
sval_u node_pos(unsigned int pos);
sval_u node_string(char *text);

sval_u node0(int type);
sval_u node1(int type, sval_u val1);
sval_u node2(int type, sval_u val1, sval_u val2);
sval_u node3(int type, sval_u val1, sval_u val2, sval_u val3);
sval_u node4(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4);
sval_u node5(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5);
sval_u node6(int type, sval_u val1, sval_u val2, sval_u val3, sval_u val4, sval_u val5, sval_u val6);
sval_u node_listener(sval_u val1, sval_u val2);

typedef struct parse_pos_s {
    int sourcePos;
    int first_line;
    int first_column;
    int last_line;
    int last_column;
} parse_pos_t;

struct yyexception {
    int yylineno;
    str yytext;
    str yytoken;

    yyexception() { yylineno = 0; }
};

struct yyparsedata {
    size_t total_length;

    int          braces_count;
    int          line_count;
    unsigned int pos;
    sval_t       val;

    char             *sourceBuffer;
    class GameScript *gameScript;

    yyexception exc;

    yyparsedata()
    {
        total_length = 0, braces_count = 0, line_count = 0, pos = 0;
        val          = sval_t();
        sourceBuffer = NULL;
        gameScript   = NULL;
    }
};

extern yyparsedata parsedata;