1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef ARCHETYPE_EXPRESSION
24 #define ARCHETYPE_EXPRESSION
25 
26 #include "glk/archetype/keywords.h"
27 #include "glk/archetype/linked_list.h"
28 #include "glk/archetype/misc.h"
29 
30 namespace Glk {
31 namespace Archetype {
32 
33 const int OP_LPAREN = NUM_OPERS + 1;		// book-keeping operator
34 const int OP_SEND_TO_TYPE = NUM_OPERS + 2;	// for use with interpreter
35 
36 struct ExprNode;
37 
38 struct OperNode {
39 	int8 op_name;
40 	ExprNode *left, *right;
41 };
42 
43 struct MessageTextQuoteNode {
44 	int index;
45 };
46 
47 struct NumericNode {
48 	int acl_int;
49 };
50 
51 struct StrNode {
52 	StringPtr acl_str;
53 };
54 
55 struct AttrNode {
56 	NodePtr acl_attr;
57 };
58 
59 struct ReservedNode {
60 	int8 keyword;
61 };
62 
63 struct IdentNode {
64 	ClassifyType ident_kind;
65 	int ident_int;
66 };
67 
68 union ExprNodeData {
69 	OperNode _oper;
70 	NumericNode _numeric;
71 	MessageTextQuoteNode _msgTextQuote;
72 	StrNode _str;
73 	AttrNode _attr;
74 	ReservedNode _reserved;
75 	IdentNode _ident;
76 };
77 
78 struct ExprNode {
79 	AclType _kind;
80 	ExprNodeData _data;
81 
ExprNodeExprNode82 	ExprNode() : _kind(RESERVED) {
83 		_data._reserved.keyword = RW_UNDEFINED;
84 	}
85 };
86 
87 typedef ExprNode *ExprPtr;
88 typedef ExprPtr ExprTree;
89 
90 // Global variables
91 extern bool Right_Assoc[NUM_OPERS + 2];
92 extern bool Binary[NUM_OPERS + 2];
93 extern int8 Precedence[NUM_OPERS + 2];
94 
95 extern void expression_init();
96 
97 } // End of namespace Archetype
98 } // End of namespace Glk
99 
100 #endif
101