1 /*---------------------------------------------------------------------------- 2 script.h (definitions of script object) 3 This file is a part of topaz systems 4 Copyright: Hisao Kawaura, All rights reserved 5 1997 - 98 6 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 ----------------------------------------------------------------------------*/ 23 24 #if !defined(__script_h) 25 #define __script_h 26 27 #include <stdio.h> 28 #include <string> 29 #include "valbuff.h" 30 #include "tokenbuff.h" 31 #include "graph.h" 32 #include "buffarray.h" 33 34 /* status */ 35 #define MINUS 1 36 #define TIMES 2 37 #define DIVIDE 3 38 #define COLON 5 39 #define CPAREN 7 40 #define NUM 8 41 #define CELL 9 42 #define EOLN 11 43 #define BAD 12 44 #define PREPLUS 14 45 #define PREMINUS 15 46 #define DATAROW 16 47 #define CELLNO 17 48 #define OTHERDATAROW 26 49 #define PARAMDATAROW 27 50 #define SEMICOLON 29 51 #define VARIANT 30 52 #define STR_PLUS 31 53 #define TO_OPERAND 32 54 #define IF 33 55 #define ELSEIF 34 56 #define ELSE 35 57 #define WHILE 36 58 #define UNTIL 37 59 #define FOR 38 60 #define NEXTFOR 39 61 #define TOARRAY 40 62 #define ARRAY 41 63 #define ARRAYVARIANT 42 64 #define IMPLICITSTRPLUS 43 65 #define IMPLICITARRAY 44 // (1,4,2) 66 #define FOREACH 45 67 #define CONTINUE 46 68 #define LAST 47 69 #define NEXT 48 70 #define INTDIVIDE 49 71 #define NOT 50 72 #define BEFORE_INC 51 73 #define AFTER_INC 52 74 #define BEFORE_DEC 53 75 #define AFTER_DEC 54 76 #define STR_EQUAL 55 77 #define STR_NOTEQUAL 56 78 #define STR_LESSTHAN 57 79 #define STR_GREATERTHAN 58 80 #define STR_LESSEQUALTHAN 59 81 #define STR_GREATEREQUALTHAN 60 82 #define OBJ_POINTER 61 83 #define OBJ_MEMBER 62 84 #define OBJ_METHOD 63 85 #define OBJ_TOARRAY 64 86 #define OBJ_ARRAYMEMBER 65 87 #define MATCH 66 88 #define NOTMATCH 67 89 #define TO_ARRAY 68 90 #define READPIPE 69 91 #define NEXTFOREACH 70 92 #define PLUS 71 93 94 95 96 97 #define OPAREN 1001 98 #define COMMA 1002 99 #define EXP 1003 100 #define OR 1004 101 #define AND 1005 102 #define EQUAL 1006 103 #define NOTEQUAL 1007 104 #define SMALLER_THAN 1008 105 #define SMALLER_EQUAL_THAN 1009 106 #define LARGER_THAN 1010 107 #define LARGER_EQUAL_THAN 1011 108 #define SET 1012 109 #define FUNC 1013 110 #define PLUSEQUAL 1014 111 #define MINUSEQUAL 1015 112 #define TIMESEQUAL 1016 113 #define DIVIDEEQUAL 1017 114 #define INTDIVIDEEQUAL 1018 115 #define EXPEQUAL 1019 116 #define STRPLUSEQUAL 1020 117 #define COMMAEQUAL 1021 118 119 120 121 122 123 124 125 126 #define MAXFUNCNAMELEN 5 127 128 129 130 /* priority */ 131 #define PRI_SEMICOLON -30 132 #define PRI_SET -5 133 #define PRI_CPAREN -10 134 135 #define PRI_PRINT 0 136 137 #define PRI_COMMA 10 138 #define PRI_OR 20 139 #define PRI_AND 30 140 #define PRI_STR_EQUAL 35 141 #define PRI_EQUAL 40 142 #define PRI_NOTEQUAL 40 143 #define PRI_STR_LESSTHAN 45 144 #define PRI_SMALLER_THAN 50 145 #define PRI_SMALLER_EQUAL_THAN 50 146 #define PRI_LARGER_THAN 50 147 #define PRI_LARGER_EQUAL_THAN 50 148 #define PRI_FUNCTION 60 149 #define PRI_PRUSMINUS 80 150 #define PRI_MULDIV 90 151 #define PRI_MATCH 93 152 #define PRI_NOT 95 153 #define PRI_EXP 100 154 #define PRI_INCDEC 105 155 #define PRI_OBJPOINTER 108 156 #define PRI_OPERAND 110 157 #define PRI_DATAROW 110 158 #define PRI_PARENFUNCTION 120 159 #define PRI_OPAREN 130 160 161 162 /* string status */ 163 #define STR_NORMAL 0 164 #define STR_SQUOTE 1 165 #define STR_DQUOTE 2 166 #define STR_UQUOTE 3 167 #define STR_REGEX 4 168 #define STRSTATUS_BUFF_LEN 100 169 170 /* brace status */ 171 #define BRC_NORMAL 0 /* this has no meanings */ 172 #define BRC_TOOPERAND 1 173 #define BRC_FOR 2 174 #define BRC_WHILE 3 175 #define BRC_IF 4 176 #define BRC_ELSEIF 5 177 #define BRC_ELSE 6 178 #define BRC_FOREACH 7 179 #define BRC_CONTINUE 8 180 #define BRC_TOARRAY 9 181 #define BRC_TOARRAYVARIANT 10 182 183 /* bracetype */ 184 #define BRC_OPENPAREN 1 185 #define BRC_CLOSEDPAREN 2 186 #define BRC_OPENBRACE 3 187 #define BRC_CLOSEDBRACE 4 188 #define BRC_BRA 5 189 #define BRC_KET 6 190 191 192 193 #define BRACESTATUS_BUFF_LEN 100 194 195 196 #define PARSERSTACKSIZE 100 197 #define MAXINPUT 79 198 #define TOKENBUFFSIZE 10000 199 200 /* maxpoint number in path */ 201 #define MAXPOINT_IN_PATH 1000 202 203 #define exitscriptstatus 2 204 #define NOTEXISTSCRIPT 20 205 206 207 class script 208 { 209 public: 210 script(graph *g); 211 script(graph *g, script *scr); 212 ~script(); 213 214 std::string *scriptname; 215 int errormessage(int lineno, char *mes, const char *com); 216 int execscript(std::string *inputstr, std::string* out, buffarray* arg); 217 int execscriptfile(std::string *inputfile, std::string *out, buffarray* arg); 218 219 // private: 220 221 graph* gra; 222 stackarray *v, *buff; 223 vstackarray *stack , *polish; 224 bool addbuff(int priority, int status, const char *value, const char *label); 225 script *prevscr; 226 227 // int sp1,sp2; 228 VariantBuff *vbuff; 229 230 bool parsetoken(std::string *inputstring); 231 int calc (); 232 int funcs(int); 233 int exectoken(tokenbuff *token); 234 int controltoken(); 235 bool GetValue(tokenbuff *token, std::string *outstring); 236 bool GetImplicitValue(tokenbuff *token, std::string *outstring); 237 void initparse(buffarray* arg, std::string *scrfile); 238 void getenvstring(); 239 240 /* status for strings and braces */ 241 int strstatusbuffpoint; 242 int strstatusbuff[STRSTATUS_BUFF_LEN]; 243 int bracestatusbuffpoint; 244 int bracestatusbuff[BRACESTATUS_BUFF_LEN]; 245 int parentheseslevel; 246 int lineno; 247 int bracetype; 248 }; 249 250 251 #endif 252 253 254 255 256