Debian Codegraph @

include/pol.h

raw
1 /*****************************************************************************
2 ** Name: pol.h
3 ** Purpose: Header file for Problem Oriented Language Class
4 ** Programmer: Kevin Rosenberg
5 ** Date Started: 1984
6 **
7 ** This is part of the CTSim program
8 ** Copyright (c) 1983-2009 Kevin Rosenberg
9 **
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.
13 **
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.
18 **
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 ******************************************************************************/
23 #ifndef __H_POL
24 #define __H_POL
25
26 #include "hashtable.h"
27 #include <stack>
28
29 class POL {
30
31 public:
32
33 // codes for pol_usefile
34 enum {
35 P_USE_STR = 1, // use string as input source
36 P_USE_FILE, // use file as input source
37 };
38
39
40 POL();
41 ~POL();
42
43 void init ();
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);
52 bool skipTokens ();
53 void reader ();
54 bool readText (char *str, int lim);
55 void usefile (int source, const char *fn);
56 void closefile ();
57 int lookchar ();
58 int inchar ();
59 void ungetch (int c);
60 int get_inputline (FILE *fp);
61 void set_inputline (const char* const line);
62
63
64 enum {
65 MAXTOK = 200, // maximum length of a token
66 MAXLINE = 1024, // maximum line length
67 MAXIDENT = 20,
68 MAXSKIPWORD = 20,
69 MAXSKIPCHAR = 20,
70 MIN_INT = -2000000000,
71 MAX_INT = 2000000000,
72 };
73
74 // token types
75 enum {
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
81 TT_NUMALPHA,
82 TT_SPECLCHAR,
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
87 };
88
89
90 private:
91
92 // codes for pol_int and pol_float
93 // if in reject catagory, get new number from terminal
94 enum {
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
104 };
105
106 #define LETTER 'a'
107 #define DIGIT '0'
108
109
110 // typedef std::map<std::string,int> KeywordCodeList;
111
112 struct token_st {
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
120 };
121 typedef struct token_st TOKEN;
122 struct token_st token; // current token
123
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
128
129 struct metachar {
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 */
139 } meta;
140
141
142 char m_szSkipChars [MAXSKIPCHAR]; // characters to skip
143 bool m_bTrace;
144 bool m_bNewlineIsEOC;
145
146 struct KeywordCodeList {
147 const char *keyword;
148 int code;
149 };
150
151 static const struct KeywordCodeList cmdlist[];
152 static const unsigned int NUMCMD;
153
154 // Internal codes for pol commands
155 enum {
156 PC_EOC = 1,
157 PC_STR,
158 PC_COM,
159 PC_CMD,
160 PC_PRG,
161 PC_CON,
162 PC_OUT,
163 PC_TER,
164 PC_INB,
165 PC_NL_EOC,
166 PC_NL_NEOC,
167 PC_TRON,
168 PC_TROFF,
169 PC_FILE,
170 PC_DUMP,
171 };
172
173 enum {
174 INPUT_STREAM = 1,
175 INPUT_FILE,
176 INPUT_STRING,
177 };
178
179 int m_iInputType;
180 std::istream* m_pInputStream;
181 FILE* m_pInputFile;
182 char* m_pszInputString;
183
184 enum {
185 MAXFILE = 8,
186 };
187
188 int currentf; /* pointer to current fp */
189 FILE *filep[MAXFILE]; /* == NULL for string input */
190 char *fname[MAXFILE]; /* pointer to filename */
191
192 char inputline[MAXLINE]; /* current input line */
193 int lineptr; /* current position in inputline */
194
195 std::stack<int> m_stackPushBackInput;
196
197 bool skipSingleToken (char term[]);
198 int tok (struct token_st *token);
199 void dumptok (struct token_st *token);
200
201
202 int getpol_tok (struct token_st *token);
203 int getcmd ();
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);
210 void eatline ();
211 int type (int c);
212 int getch (FILE *fp);
213
214 };
215
216 #endif
217