00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __KSCRIPT_PARSENODE_H__
00021 #define __KSCRIPT_PARSENODE_H__
00022
00023 #include <qstring.h>
00024
00025 #include "koscript_types.h"
00026 #include <koffice_export.h>
00027
00028 #define MAX_NODE_SIZE 255
00029
00030 typedef enum
00031 {
00032 definitions = 0,
00033 exports,
00034 t_vertical_line,
00035 t_circumflex,
00036 t_ampersand,
00037 t_shiftright,
00038 t_shiftleft,
00039 t_plus_sign,
00040 t_minus_sign,
00041 t_asterik,
00042 t_solidus,
00043 t_percent_sign,
00044 t_tilde,
00045 t_integer_literal,
00046 t_string_literal,
00047 t_character_literal,
00048 t_floating_pt_literal,
00049 t_boolean_literal,
00050 scoped_name,
00051 const_dcl,
00052 func_dcl,
00053 func_lines,
00054 assign_expr,
00055 t_equal,
00056 t_notequal,
00057 t_less_or_equal,
00058 t_greater_or_equal,
00059 t_array,
00060 t_dict,
00061 func_params,
00062 func_param_in,
00063 func_param_out,
00064 func_param_inout,
00065 t_func_call,
00066 member_expr,
00067 t_array_const,
00068 t_array_element,
00069 t_dict_const,
00070 t_dict_element,
00071 t_while,
00072 t_do,
00073 t_for,
00074 t_if,
00075 t_incr,
00076 t_decr,
00077 t_less,
00078 t_greater,
00079 t_foreach,
00080 t_match,
00081 t_subst,
00082 t_not,
00083 func_call_params,
00084 t_return,
00085 destructor_dcl,
00086 import,
00087 t_struct,
00088 t_struct_members,
00089 t_qualified_names,
00090 t_scope,
00091 t_try,
00092 t_catch,
00093 t_catch_default,
00094 t_raise,
00095 t_cell,
00096 t_range,
00097 from,
00098 plus_assign,
00099 minus_assign,
00100 bool_or,
00101 bool_and,
00102 t_regexp_group,
00103 t_input,
00104 t_line,
00105 t_match_line
00106 } KSParseNodeType;
00107
00108 class KSContext;
00109
00114 class KSParseNodeExtra
00115 {
00116 public:
00117 virtual ~KSParseNodeExtra() { }
00118 };
00119
00120 class KOSCRIPT_EXPORT KSParseNode
00121 {
00122 private:
00123 KSParseNode &operator=(const KSParseNode &rhs);
00124 KSParseNode(const KSParseNode &rhs);
00125
00126 KSParseNodeType type;
00127 QString ident;
00128
00129 QString fname;
00130 long line_no;
00131 bool bIsToplevel;
00132
00133 union u {
00134 KScript::Long _int;
00135 KScript::Boolean _bool;
00136 KScript::Double _float;
00137 ushort _char;
00138 } _u;
00139 QString* str;
00140
00141 KSParseNodeExtra* m_extra;
00142 KSParseNode *b1;
00143 KSParseNode *b2;
00144 KSParseNode *b3;
00145 KSParseNode *b4;
00146 KSParseNode *b5;
00147
00148 void printBranch( int indent, const char *tag, bool detailed );
00149
00150 public:
00151 KSParseNode( KSParseNodeType aType, KSParseNode *one = NULL,
00152 KSParseNode *two = NULL, KSParseNode *three = NULL,
00153 KSParseNode *four = NULL, KSParseNode *five = NULL );
00154 ~KSParseNode();
00155 void clear();
00156
00157 bool eval( KSContext& );
00158
00159 KSParseNodeType getType() const;
00160 void setIdent( const char *anIdent );
00161 void setIdent( QString* anIdent );
00162 void setIdent( const QString& anIdent );
00163 QString getIdent();
00164 QString getFname();
00165 long getLineNo();
00166 bool isToplevel();
00167
00168 void setIntegerLiteral( KScript::Long l );
00169 KScript::Long getIntegerLiteral();
00170 void setStringLiteral( const char *s );
00171 void setStringLiteral( const QString& s );
00172 void setStringLiteral( QString* s );
00173 QString getStringLiteral();
00174 void setCharacterLiteral( const KScript::Char& c );
00175 KScript::Char getCharacterLiteral();
00176 void setFloatingPtLiteral( KScript::Double f );
00177 KScript::Double getFloatingPtLiteral();
00178 void setBooleanLiteral( KScript::Boolean b );
00179 KScript::Boolean getBooleanLiteral();
00180
00181 KSParseNode *branch1() { return b1; }
00182 KSParseNode *branch2() { return b2; }
00183 KSParseNode *branch3() { return b3; }
00184 KSParseNode *branch4() { return b4; }
00185 KSParseNode *branch5() { return b5; }
00186 KSParseNode *getBranch( int i );
00187 void setBranch( int i, KSParseNode *node );
00188
00189 KSParseNodeExtra* extra();
00190 void setExtra( KSParseNodeExtra* e );
00191
00192 void print( bool detailed = false );
00193 };
00194
00195 #endif