openmohaa/code/parser/parsetree.h

180 lines
4.3 KiB
C
Raw Permalink Normal View History

2016-03-27 11:49:47 +02:00
/*
===========================================================================
2025-04-26 19:22:34 +02:00
Copyright (C) 2025 the OpenMoHAA team
2016-03-27 11:49:47 +02:00
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
2023-04-29 21:56:38 +02:00
#pragma once
#include "str.h"
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
#if defined(GAME_DLL)
# define showopcodes g_showopcodes
#elif defined(CGAME_DLL)
# define showopcodes cg_showopcodes
2016-03-27 11:49:47 +02:00
#else
2023-07-05 21:23:39 +02:00
# define showopcodes g_showopcodes
2016-03-27 11:49:47 +02:00
#endif
2023-07-05 21:23:39 +02:00
typedef enum {
2023-08-12 19:59:40 +02:00
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
2016-03-27 11:49:47 +02:00
} sval_type_e;
union sval_u {
2023-07-05 21:23:39 +02:00
int type;
2023-08-13 03:33:50 +02:00
const char *stringValue;
2023-07-05 21:23:39 +02:00
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;
2016-03-27 11:49:47 +02:00
2023-08-12 19:59:40 +02:00
struct stype_t {
2023-07-05 21:23:39 +02:00
sval_t val;
unsigned int sourcePos;
2023-08-12 19:59:40 +02:00
};
enum parseStage_e {
2023-08-13 03:33:50 +02:00
PS_TYPE,
PS_BODY,
PS_BODY_END
2023-08-12 19:59:40 +02:00
};
2016-03-27 11:49:47 +02:00
2024-04-09 23:22:45 +02:00
enum {
method_game,
method_level,
method_local,
method_parm,
method_self,
method_group,
method_owner,
method_field,
method_array,
};
2023-07-05 21:23:39 +02:00
void parsetree_freeall();
void parsetree_init();
size_t parsetree_length();
char *parsetree_malloc(size_t s);
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
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);
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
sval_u linked_list_end(sval_u val);
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
sval_u node1_(int val1);
sval_u node1b(int val1);
sval_u node_pos(unsigned int pos);
sval_u node_string(char *text);
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
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);
2024-04-09 23:22:45 +02:00
sval_u node_listener(sval_u val1, sval_u val2);
2016-03-27 11:49:47 +02:00
2023-08-12 19:59:40 +02:00
typedef struct parse_pos_s {
int sourcePos;
2023-08-13 03:33:50 +02:00
int first_line;
int first_column;
int last_line;
int last_column;
2023-08-12 19:59:40 +02:00
} parse_pos_t;
2016-03-27 11:49:47 +02:00
struct yyexception {
2023-07-05 21:23:39 +02:00
int yylineno;
str yytext;
str yytoken;
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
yyexception() { yylineno = 0; }
2016-03-27 11:49:47 +02:00
};
struct yyparsedata {
2023-07-05 21:23:39 +02:00
size_t total_length;
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
int braces_count;
int line_count;
unsigned int pos;
sval_t val;
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
char *sourceBuffer;
class GameScript *gameScript;
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
yyexception exc;
2016-03-27 11:49:47 +02:00
2023-07-05 21:23:39 +02:00
yyparsedata()
{
total_length = 0, braces_count = 0, line_count = 0, pos = 0;
val = sval_t();
sourceBuffer = NULL;
gameScript = NULL;
}
2016-03-27 11:49:47 +02:00
};
extern yyparsedata parsedata;