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-2009 Kevin Rosenberg
10 ** This program is free software; you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License (version 2) as
12 ** published by the Free Software Foundation.
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ******************************************************************************/
26 #include "hashtable.h"
33 // codes for pol_usefile
35 P_USE_STR = 1, // use string as input source
36 P_USE_FILE, // use file as input source
44 void addSkipWord (const char* const w);
45 void addSkipChar (int c);
46 void addKeyword (const char* const str, int code);
47 bool readWord (const char *search, int nlet);
48 bool readUserToken (char *str, int *code);
49 bool readString (char *str);
50 bool readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2);
51 bool readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2);
54 bool readText (char *str, int lim);
55 void usefile (int source, const char *fn);
60 int get_inputline (FILE *fp);
61 void set_inputline (const char* const line);
65 MAXTOK = 200, // maximum length of a token
66 MAXLINE = 1024, // maximum line length
70 MIN_INT = -2000000000,
76 TT_STRING = 1, // string token
77 TT_INT, // integer token
78 TT_REAL, // floating point token
79 TT_ALPHA, // alphabetic token
80 TT_ALPNUM, // alphanumeric token
83 TT_EOF, // end of file reached
84 TT_ERROR, // error in token, caused by call to wrong type of token reader
85 TT_BLANK, // white space token. pol_tok() skips these
86 TT_USERTOK, // user defined token
92 // codes for pol_int and pol_float
93 // if in reject catagory, get new number from terminal
95 P_FLTINT = 1, // get a real or integer number
96 P_BFLTINT, // get a real or integer number, clip against bounds
97 P_CBFLTINT, // get real or int, reject if outside bounds
98 P_FLT, // get a real number
99 P_BFLT, // get a real, clip against bounds
100 P_CBFLT, // get a floating, reject if outside bounds
101 P_INT, // get a integer number
102 P_BINT, // get a integer, clip against bounds
103 P_CBINT, // get a integer, reject if outside bounds
110 // typedef std::map<std::string,int> KeywordCodeList;
113 int ready; // TRUE if token is ready
114 // std::string tokstr; // token string
115 char tokstr[MAXTOK+1];
116 int type; // type of token 'TT_'
117 int code; // holds code for user defined tokens
118 double fnum; // real value of token
119 int inum; // integer value of token
121 typedef struct token_st TOKEN;
122 struct token_st token; // current token
124 // Tables words stored with install() & found with lookup()
125 KeywordCodeHashTable skiptable; // words to ignore and skip
126 KeywordCodeHashTable cmdtable; // pol parameter commands
127 KeywordCodeHashTable usertable; // user defined symbols
130 char eoc; /* end of command character */
131 char str; /* string delimiter */
132 char com; /* comment character */
133 char cmd; /* pol parameter command character */
134 char prg; /* program load character */
135 char con; /* continuation across newline character */
136 char out; /* character that delimits output to terminal */
137 char ter; /* character indicates insertion of input from terminal */
138 char inb; /* input from graphics device */
142 char m_szSkipChars [MAXSKIPCHAR]; // characters to skip
144 bool m_bNewlineIsEOC;
146 struct KeywordCodeList {
151 static const struct KeywordCodeList cmdlist[];
152 static const unsigned int NUMCMD;
154 // Internal codes for pol commands
180 std::istream* m_pInputStream;
182 char* m_pszInputString;
188 int currentf; /* pointer to current fp */
189 FILE *filep[MAXFILE]; /* == NULL for string input */
190 char *fname[MAXFILE]; /* pointer to filename */
192 char inputline[MAXLINE]; /* current input line */
193 int lineptr; /* current position in inputline */
195 std::stack<int> m_stackPushBackInput;
197 bool skipSingleToken (char term[]);
198 int tok (struct token_st *token);
199 void dumptok (struct token_st *token);
202 int getpol_tok (struct token_st *token);
204 int gettok (TOKEN *tok);
205 void getblank (char *s, int toksiz);
206 int getalpha (char *s, int toksiz);
207 void getquote (char *qs, int toksiz);
208 void getescape (char *s, int delim, int toksiz);
209 int getnumber (char str[], int strsize, double *fnum, int *inum);
212 int getch (FILE *fp);