1 /*****************************************************************************
3 ** Purpose: Header file for Problem Oriented Language Class
4 ** Programmer: Kevin Rosenberg
7 ** This is part of the CTSim program
8 ** Copyright (c) 1983-2001 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
28 #include "hashtable.h"
35 // codes for pol_usefile
37 P_USE_STR = 1, // use string as input source
38 P_USE_FILE, // use file as input source
46 void addSkipWord (const char* const w);
47 void addSkipChar (int c);
48 void addKeyword (const char* const str, int code);
49 bool readWord (const char *search, int nlet);
50 bool readUserToken (char *str, int *code);
51 bool readString (char *str);
52 bool readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2);
53 bool readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2);
56 bool readText (char *str, int lim);
57 void usefile (int source, const char *fn);
62 int get_inputline (FILE *fp);
63 void set_inputline (const char* const line);
67 MAXTOK = 200, // maximum length of a token
68 MAXLINE = 1024, // maximum line length
72 MIN_INT = -2000000000,
78 TT_STRING = 1, // string token
79 TT_INT, // integer token
80 TT_REAL, // floating point token
81 TT_ALPHA, // alphabetic token
82 TT_ALPNUM, // alphanumeric token
85 TT_EOF, // end of file reached
86 TT_ERROR, // error in token, caused by call to wrong type of token reader
87 TT_BLANK, // white space token. pol_tok() skips these
88 TT_USERTOK, // user defined token
94 // codes for pol_int and pol_float
95 // if in reject catagory, get new number from terminal
97 P_FLTINT = 1, // get a real or integer number
98 P_BFLTINT, // get a real or integer number, clip against bounds
99 P_CBFLTINT, // get real or int, reject if outside bounds
100 P_FLT, // get a real number
101 P_BFLT, // get a real, clip against bounds
102 P_CBFLT, // get a floating, reject if outside bounds
103 P_INT, // get a integer number
104 P_BINT, // get a integer, clip against bounds
105 P_CBINT, // get a integer, reject if outside bounds
112 // typedef std::map<std::string,int> KeywordCodeList;
115 int ready; // TRUE if token is ready
116 // std::string tokstr; // token string
117 char tokstr[MAXTOK+1];
118 int type; // type of token 'TT_'
119 int code; // holds code for user defined tokens
120 double fnum; // real value of token
121 int inum; // integer value of token
123 typedef struct token_st TOKEN;
124 struct token_st token; // current token
126 // Tables words stored with install() & found with lookup()
127 KeywordCodeHashTable skiptable; // words to ignore and skip
128 KeywordCodeHashTable cmdtable; // pol parameter commands
129 KeywordCodeHashTable usertable; // user defined symbols
132 char eoc; /* end of command character */
133 char str; /* string delimiter */
134 char com; /* comment character */
135 char cmd; /* pol parameter command character */
136 char prg; /* program load character */
137 char con; /* continuation across newline character */
138 char out; /* character that delimits output to terminal */
139 char ter; /* character indicates insertion of input from terminal */
140 char inb; /* input from graphics device */
144 char m_szSkipChars [MAXSKIPCHAR]; // characters to skip
146 bool m_bNewlineIsEOC;
148 struct KeywordCodeList {
153 static const struct KeywordCodeList cmdlist[];
154 static const unsigned int NUMCMD;
156 // Internal codes for pol commands
182 std::istream* m_pInputStream;
184 char* m_pszInputString;
190 int currentf; /* pointer to current fp */
191 FILE *filep[MAXFILE]; /* == NULL for string input */
192 char *fname[MAXFILE]; /* pointer to filename */
194 char inputline[MAXLINE]; /* current input line */
195 int lineptr; /* current position in inputline */
197 std::stack<int> m_stackPushBackInput;
199 bool skipSingleToken (char term[]);
200 int tok (struct token_st *token);
201 void dumptok (struct token_st *token);
204 int getpol_tok (struct token_st *token);
206 int gettok (TOKEN *tok);
207 void getblank (char *s, int toksiz);
208 int getalpha (char *s, int toksiz);
209 void getquote (char *qs, int toksiz);
210 void getescape (char *s, int delim, int toksiz);
211 int getnumber (char str[], int strsize, double *fnum, int *inum);
214 int getch (FILE *fp);