summaryrefslogtreecommitdiff
path: root/srec/Semproc/include/SR_SemprocDefinitions.h
blob: 48f28f915e853b74c200d7ed5461a51a021a3699 (plain)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/*---------------------------------------------------------------------------*
 *  SR_SemprocDefinitions.h  *
 *                                                                           *
 *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
 *                                                                           *
 *  Licensed under the Apache License, Version 2.0 (the 'License');          *
 *  you may not use this file except in compliance with the License.         *
 *                                                                           *
 *  You may obtain a copy of the License at                                  *
 *      http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                           *
 *  Unless required by applicable law or agreed to in writing, software      *
 *  distributed under the License is distributed on an 'AS IS' BASIS,        *
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 
 *  See the License for the specific language governing permissions and      *
 *  limitations under the License.                                           *
 *                                                                           *
 *---------------------------------------------------------------------------*/

#ifndef __SR_SEMPROCDEFINITIONS_H
#define __SR_SEMPROCDEFINITIONS_H



#include "ptypes.h"
#include "pstdio.h"

/**
 * Whether to display verbose error message when parse fails.
 */
#define SEMPROC_VERBOSE_PARSE_ERROR 1

/**
* Max number of semantic results
*/
#define MAX_SEM_RESULTS         1

/**
 * Maximum number of symbols allowed in the Symbol table when parsing a single script
 */
#define MAX_SYMBOLS            40

/**
 * Maximum number of special symbols allowed in the Symbol table set before parsing and read during
 */
#define MAX_SPECIAL_SYMBOLS     1


/**
 * Maximum size of strings
 */
#define MAX_STRING_LEN        350

/**
 * Maximum length of accumulated scripts
 */
#define MAX_SCRIPT_LEN       8192

/**
 * Maximum number of identifiers allowed on the RHS of equal sign
 */
#define MAX_RHS_IDENTIFIERS    10

/**
 * Maximum number of function callbacks the may be registered
 * fix: 2004-05-20, this was limiting the number of concurrently
 * loaded grammars, now patched but source problem not repaired
 */
#define MAX_FUNCTION_CALLBACKS 32

/**
 * Max depth of a graph (tokens including scope markers, scripts, words etc)
 */
#define MAX_SEM_GRAPH_DEPTH       128

/**
 * Maximum number of partial paths which will be used when parsing
 */
#define MAX_SEM_PARTIAL_PATHS     512

/**
 * Maximum number of tokens encountered on all partial paths combined
 */
#define MAX_PATH_OLABELS          2048

/**
 * Maximum number of scripts accumulated on a path through grammar
 */
#define MAX_SCRIPTS                512

/**
 * Offset used for denoting scripts (since integer used as label in graph)
 */
#define SEMGRAPH_SCRIPT_OFFSET  30000

/**
 * Offset used for denoting scope markers (since integer used as label in graph)
 */
#define SEMGRAPH_SCOPE_OFFSET   40000

/**
 * Assignment operator
 */
#define OP_ASSIGN        L('=')

/**
 * String concatenation operator
 */
#define OP_CONCAT        L('+')

/**
 * Left bracket
 */
#define LBRACKET         L('(')

/**
 * Delimiter for parameters in a function call
 */
#define PARAM_DELIM      L(',')

/**
 * Right bracket
 */
#define RBRACKET         L(')')

/**
 * Question mark used in conditional expressions to signify end of condition part
 */
#define OP_CONDITION_IFTRUE  L('?')

/**
 * Colon used in conditional expressions to signify the alternative (false) return value
 */
#define OP_CONDITION_ELSE    L(':')

/**
 * End of statement operator
 */
#define EO_STATEMENT     L(';')

/**
 * Delimiter for constant string identifiers
 */
#define STRING_DELIM     L('\'')

/**
 * Dot used for rule property referencing
 */
#define DOT              L('.')

/**
 * Underscore sometimes used in identifiers
 */
#define USCORE           L('_')

/**
 * Newline character
 */
#define NL               L('\n')

/**
 * End of string character
 */
#define EO_STRING        L('\0')

/**
 * Escape character.
 **/
#define ESC_CHAR L('\\')
/**
 * CHAR used for joining (union) multiple meanings for same word
 */
#define MULTIPLE_MEANING_JOIN_CHAR L('#')

/**
 * String used for undefined string variables
 */
#define UNDEFINED_SYMBOL L("undefined")

/**
 * Boolean symbol true
 */
#define TRUE_SYMBOL      L("true")

/**
* Boolean symbol false
*/
#define FALSE_SYMBOL     L("false")

/** 
 * markers
 */
#define BEGIN_SCOPE_MARKER L('{')
#define END_SCOPE_MARKER   L('}')
#define IS_BEGIN_SCOPE(wW) (wW[0] == BEGIN_SCOPE_MARKER && wW[1] == 0)
#define IS_END_SCOPE(wW) ((_tMp=LSTRCHR(wW,END_SCOPE_MARKER))!=0 && _tMp[1]==0)
#define IS_SCOPE_MARKER(wW) ( IS_BEGIN_SCOPE(wW) || IS_END_SCOPE(wW))
#define IS_SCRIPT_MARKER(wW) (wW[0] == '_' && isnum(&wW[1]))
#define IS_OPERATOR(p) ((*p)==','|| (*p)=='+' || (*p)=='=' || (*p)=='(' || (*p)==')' || (*p)==':' || (*p)=='?')
#define IS_LOCAL_IDENTIFIER(p, len) ( (*p)!=';' && !IS_OPERATOR(p) && *p!='\'' && !LSTRNCHR2(p,'.','(',len))


/**
 * This macro checks if memory allocation is possible (against internal limit values)
 * and returns ESR_OUT_OF_MEMORY otherwise.
 */
#define MEMCHK(rc, val, threshold) \
  do { \
    if(val > threshold) \
    { \
      rc = ESR_OUT_OF_MEMORY; \
      PLogError(L("%s: %d > %d\n"), ESR_rc2str(rc), (val), (threshold)); \
      goto CLEANUP; \
    } \
  } while(0);
#define LENCHK(rc, val, threshold) \
  do { \
    if(LSTRLEN(val) > threshold) \
    { \
      rc = ESR_OUT_OF_MEMORY; \
      PLogError(L("%s: %s > %d\n"), ESR_rc2str(rc), (val), (threshold)); \
      goto CLEANUP; \
    } \
  } while(0);

/**
 * Base 10 used for ITOA macro
 */
#define BASE_10 10

#endif /* __DEFINTIONS_H */