Home | History | Annotate | Download | only in include
      1 /*---------------------------------------------------------------------------*
      2  *  SR_SemprocDefinitions.h  *
      3  *                                                                           *
      4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
      5  *                                                                           *
      6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
      7  *  you may not use this file except in compliance with the License.         *
      8  *                                                                           *
      9  *  You may obtain a copy of the License at                                  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
     11  *                                                                           *
     12  *  Unless required by applicable law or agreed to in writing, software      *
     13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
     15  *  See the License for the specific language governing permissions and      *
     16  *  limitations under the License.                                           *
     17  *                                                                           *
     18  *---------------------------------------------------------------------------*/
     19 
     20 #ifndef __SR_SEMPROCDEFINITIONS_H
     21 #define __SR_SEMPROCDEFINITIONS_H
     22 
     23 
     24 
     25 #include "ptypes.h"
     26 #include "pstdio.h"
     27 
     28 /**
     29  * Whether to display verbose error message when parse fails.
     30  */
     31 #define SEMPROC_VERBOSE_PARSE_ERROR 1
     32 
     33 /**
     34 * Max number of semantic results
     35 */
     36 #define MAX_SEM_RESULTS         1
     37 
     38 /**
     39  * Maximum number of symbols allowed in the Symbol table when parsing a single script
     40  */
     41 #define MAX_SYMBOLS            40
     42 
     43 /**
     44  * Maximum number of special symbols allowed in the Symbol table set before parsing and read during
     45  */
     46 #define MAX_SPECIAL_SYMBOLS     1
     47 
     48 
     49 /**
     50  * Maximum size of strings
     51  */
     52 #define MAX_STRING_LEN        350
     53 
     54 /**
     55  * Maximum length of accumulated scripts
     56  */
     57 #define MAX_SCRIPT_LEN       8192
     58 
     59 /**
     60  * Maximum number of identifiers allowed on the RHS of equal sign
     61  */
     62 #define MAX_RHS_IDENTIFIERS    10
     63 
     64 /**
     65  * Maximum number of function callbacks the may be registered
     66  * fix: 2004-05-20, this was limiting the number of concurrently
     67  * loaded grammars, now patched but source problem not repaired
     68  */
     69 #define MAX_FUNCTION_CALLBACKS 32
     70 
     71 /**
     72  * Max depth of a graph (tokens including scope markers, scripts, words etc)
     73  */
     74 #define MAX_SEM_GRAPH_DEPTH       128
     75 
     76 /**
     77  * Maximum number of partial paths which will be used when parsing
     78  */
     79 #define MAX_SEM_PARTIAL_PATHS     512
     80 
     81 /**
     82  * Maximum number of tokens encountered on all partial paths combined
     83  */
     84 #define MAX_PATH_OLABELS          2048
     85 
     86 /**
     87  * Maximum number of scripts accumulated on a path through grammar
     88  */
     89 #define MAX_SCRIPTS                512
     90 
     91 /**
     92  * Offset used for denoting scripts (since integer used as label in graph)
     93  */
     94 #define SEMGRAPH_SCRIPT_OFFSET  30000
     95 
     96 /**
     97  * Offset used for denoting scope markers (since integer used as label in graph)
     98  */
     99 #define SEMGRAPH_SCOPE_OFFSET   40000
    100 
    101 /**
    102  * Assignment operator
    103  */
    104 #define OP_ASSIGN        L('=')
    105 
    106 /**
    107  * String concatenation operator
    108  */
    109 #define OP_CONCAT        L('+')
    110 
    111 /**
    112  * Left bracket
    113  */
    114 #define LBRACKET         L('(')
    115 
    116 /**
    117  * Delimiter for parameters in a function call
    118  */
    119 #define PARAM_DELIM      L(',')
    120 
    121 /**
    122  * Right bracket
    123  */
    124 #define RBRACKET         L(')')
    125 
    126 /**
    127  * Question mark used in conditional expressions to signify end of condition part
    128  */
    129 #define OP_CONDITION_IFTRUE  L('?')
    130 
    131 /**
    132  * Colon used in conditional expressions to signify the alternative (false) return value
    133  */
    134 #define OP_CONDITION_ELSE    L(':')
    135 
    136 /**
    137  * End of statement operator
    138  */
    139 #define EO_STATEMENT     L(';')
    140 
    141 /**
    142  * Delimiter for constant string identifiers
    143  */
    144 #define STRING_DELIM     L('\'')
    145 
    146 /**
    147  * Dot used for rule property referencing
    148  */
    149 #define DOT              L('.')
    150 
    151 /**
    152  * Underscore sometimes used in identifiers
    153  */
    154 #define USCORE           L('_')
    155 
    156 /**
    157  * Newline character
    158  */
    159 #define NL               L('\n')
    160 
    161 /**
    162  * End of string character
    163  */
    164 #define EO_STRING        L('\0')
    165 
    166 /**
    167  * Escape character.
    168  **/
    169 #define ESC_CHAR L('\\')
    170 /**
    171  * CHAR used for joining (union) multiple meanings for same word
    172  */
    173 #define MULTIPLE_MEANING_JOIN_CHAR L('#')
    174 
    175 /**
    176  * String used for undefined string variables
    177  */
    178 #define UNDEFINED_SYMBOL L("undefined")
    179 
    180 /**
    181  * Boolean symbol true
    182  */
    183 #define TRUE_SYMBOL      L("true")
    184 
    185 /**
    186 * Boolean symbol false
    187 */
    188 #define FALSE_SYMBOL     L("false")
    189 
    190 /**
    191  * markers
    192  */
    193 #define BEGIN_SCOPE_MARKER L('{')
    194 #define END_SCOPE_MARKER   L('}')
    195 #define IS_BEGIN_SCOPE(wW) (wW[0] == BEGIN_SCOPE_MARKER && wW[1] == 0)
    196 #define IS_END_SCOPE(wW) ((_tMp=LSTRCHR(wW,END_SCOPE_MARKER))!=0 && _tMp[1]==0)
    197 #define IS_SCOPE_MARKER(wW) ( IS_BEGIN_SCOPE(wW) || IS_END_SCOPE(wW))
    198 #define IS_SCRIPT_MARKER(wW) (wW[0] == '_' && isnum(&wW[1]))
    199 #define IS_OPERATOR(p) ((*p)==','|| (*p)=='+' || (*p)=='=' || (*p)=='(' || (*p)==')' || (*p)==':' || (*p)=='?')
    200 #define IS_LOCAL_IDENTIFIER(p, len) ( (*p)!=';' && !IS_OPERATOR(p) && *p!='\'' && !LSTRNCHR2(p,'.','(',len))
    201 
    202 
    203 /**
    204  * This macro checks if memory allocation is possible (against internal limit values)
    205  * and returns ESR_OUT_OF_MEMORY otherwise.
    206  */
    207 #define MEMCHK(rc, val, threshold) \
    208   do { \
    209     if(val > threshold) \
    210     { \
    211       rc = ESR_OUT_OF_MEMORY; \
    212       PLogError(L("%s: %d > %d\n"), ESR_rc2str(rc), (val), (threshold)); \
    213       goto CLEANUP; \
    214     } \
    215   } while(0);
    216 #define LENCHK(rc, val, threshold) \
    217   do { \
    218     if(LSTRLEN(val) > threshold) \
    219     { \
    220       rc = ESR_OUT_OF_MEMORY; \
    221       PLogError(L("%s: %s > %d\n"), ESR_rc2str(rc), (val), (threshold)); \
    222       goto CLEANUP; \
    223     } \
    224   } while(0);
    225 
    226 /**
    227  * Base 10 used for ITOA macro
    228  */
    229 #define BASE_10 10
    230 
    231 #endif /* __DEFINTIONS_H */
    232