d10eb1ad06e7f0e36314d852113f9d8b9a24ee4b
3 ** NetXMS - Network Management System
4 ** NetXMS Scripting Language Interpreter
5 ** Copyright (C) 2005-2009 Victor Kirhenshtein
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <nms_common.h>
35 #define min(a, b) ((a) < (b) ? (a) : (b))
38 #define max(a, b) ((a) > (b) ? (a) : (b))
42 typedef void *yyscan_t
;
49 #define INVALID_ADDRESS ((DWORD)0xFFFFFFFF)
50 #define MAX_STRING_SIZE 8192
54 // Instruction opcodes
58 #define OPCODE_RETURN 1
61 #define OPCODE_CALL_EXTERNAL 4
62 #define OPCODE_PUSH_CONSTANT 5
63 #define OPCODE_PUSH_VARIABLE 6
78 #define OPCODE_BIT_AND 21
79 #define OPCODE_BIT_OR 22
80 #define OPCODE_BIT_XOR 23
83 #define OPCODE_LSHIFT 26
84 #define OPCODE_RSHIFT 27
85 #define OPCODE_RET_NULL 28
87 #define OPCODE_PRINT 30
88 #define OPCODE_CONCAT 31
89 #define OPCODE_BIND 32
94 #define OPCODE_BIT_NOT 37
95 #define OPCODE_CAST 38
96 #define OPCODE_GET_ATTRIBUTE 39
97 #define OPCODE_INCP 40
98 #define OPCODE_DECP 41
100 #define OPCODE_LIKE 43
101 #define OPCODE_ILIKE 44
102 #define OPCODE_MATCH 45
103 #define OPCODE_IMATCH 46
104 #define OPCODE_CASE 47
105 #define OPCODE_ARRAY 48
106 #define OPCODE_GET_ELEMENT 49
107 #define OPCODE_SET_ELEMENT 50
108 #define OPCODE_SET_ATTRIBUTE 51
112 // Modified lexer class
119 friend int yylex(YYSTYPE
*, yyscan_t
);
124 char *m_pszSourceCode
;
125 NXSL_Compiler
*m_pCompiler
;
130 char m_szStr
[MAX_STRING_SIZE
];
134 NXSL_Lexer(NXSL_Compiler
*pCompiler
, const TCHAR
*pszCode
);
135 virtual ~NXSL_Lexer();
137 int lexerInput(char *pBuffer
, int nMaxSize
);
139 int getCurrLine() { return m_nCurrLine
; }
140 void error(const char *pszText
);
142 void setErrorState() { m_bErrorState
= TRUE
; }
143 BOOL
isErrorState() { return m_bErrorState
; }
154 TCHAR
*m_pszErrorText
;
155 NXSL_Lexer
*m_pLexer
;
156 NXSL_Stack
*m_pAddrStack
;
157 NXSL_Stack
*m_pBreakStack
;
164 NXSL_Program
*compile(const TCHAR
*pszSourceCode
);
165 void error(const char *pszMsg
);
167 const TCHAR
*getErrorText() { return CHECK_NULL(m_pszErrorText
); }
169 void pushAddr(DWORD dwAddr
) { m_pAddrStack
->push(CAST_TO_POINTER(dwAddr
, void *)); }
173 void addBreakAddr(DWORD dwAddr
);
174 void closeBreakLevel(NXSL_Program
*pScript
);
175 BOOL
canUseBreak() { return m_pBreakStack
->getSize() > 0; }
176 void newBreakLevel() { m_pBreakStack
->push(new Queue
); }
178 void setIdentifierOperation(int opcode
) { m_idOpCode
= opcode
; }
179 int getIdentifierOperation() { return m_idOpCode
; }
187 extern const char *g_szTypeNames
[];