** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: pol.h,v 1.7 2000/12/27 03:16:02 kevin Exp $
+** $Id: pol.h,v 1.10 2000/12/29 20:11:42 kevin Exp $
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
******************************************************************************/
#ifndef __H_POL
#define __H_POL
-
+\r
+#include "hashtable.h"\r
+#include <stack>\r
class POL {
public:
- // codes for pol_usefile \r
- enum {\r
- P_USE_STR = 1, // use string as input source \r
+ // codes for pol_usefile \r
+ enum {\r
+ P_USE_STR = 1, // use string as input source \r
P_USE_FILE, // use file as input source \r
- };\r
+ };\r
\r
\r
- POL();
+ POL();
~POL();
void init ();
- void skpword (char *w);
- void skpchar (char *s);
- int installKeyword (char *str, int code);
- int word (char *search, int nlet);
- int usertok (char *str, int *code);
- int string (char *str);
- int integer (int *n, int typecode, int boundcode, int bb1, int bb2);
- bool readfloat (double *n, double typecode, double boundcode, double bb1, double bb2);
- int skip ();
+ void addSkipWord (const char* const w);
+ void addSkipChar (int c);
+ void addKeyword (const char* const str, int code);
+ bool readWord (char *search, int nlet);
+ bool readUserToken (char *str, int *code);
+ bool readString (char *str);
+ bool readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2);
+ bool readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2);
+ bool skipTokens ();
void reader ();
- void gettext (char *str, int lim);
+ bool readText (char *str, int lim);
void usefile (int source, char *fn);
void closefile ();
int lookchar ();
\r
// typedef std::map<std::string,int> KeywordCodeList;\r
\r
- struct symlist {\r
- char *name;\r
- int code;\r
- struct symlist *next;\r
- };\r
- typedef struct symlist SYMBOL;\r
- \r
struct token_st {\r
int ready; // TRUE if token is ready \r
// std::string tokstr; // token string \r
int inum; // integer value of token \r
};\r
typedef struct token_st TOKEN;\r
- \r
- \r
struct token_st token; // current token \r
- enum {\r
- HASHSIZE = 100,\r
- };\r
- \r
+ \r
// Tables words stored with install() & found with lookup() \r
- SYMBOL *skiptable[HASHSIZE]; // words to ignore and skip \r
- SYMBOL *cmdtable[HASHSIZE]; // pol parameter commands \r
- SYMBOL *usertable[HASHSIZE]; // user defined symbols \r
+ KeywordCodeHashTable skiptable; // words to ignore and skip \r
+ KeywordCodeHashTable cmdtable; // pol parameter commands \r
+ KeywordCodeHashTable usertable; // user defined symbols \r
\r
struct metachar {\r
char eoc; /* end of command character */\r
} meta;\r
\r
\r
- // current pol state \r
- struct pol_st {\r
- char skipchars[MAXSKIPCHAR]; // characters to skip \r
- int nl_eoc; // TRUE if newline character ends a command \r
- int trace; // TRUE if trace is on \r
- };\r
- \r
- struct pol_st pol;\r
+ char m_szSkipChars [MAXSKIPCHAR]; // characters to skip\r
+ bool m_bTrace;\r
+ bool m_bNewlineIsEOC;\r
\r
struct KeywordCodeList {\r
char *keyword;\r
};\r
\r
static const struct KeywordCodeList cmdlist[];\r
- static const int NUMCMD;\r
+ static const unsigned int NUMCMD;\r
\r
// Internal codes for pol commands \r
enum {\r
PC_DUMP,\r
};\r
\r
+ enum {\r
+ INPUT_STREAM = 1,\r
+ INPUT_FILE,\r
+ INPUT_STRING,\r
+ };\r
+\r
+ int m_iInputType;\r
+ std::istream* m_pInputStream;\r
+ FILE* m_pInputFile;\r
+ char* m_pszInputString;\r
+\r
enum {\r
MAXFILE = 8,\r
};\r
char inputline[MAXLINE]; /* current input line */\r
int lineptr; /* current position in inputline */\r
\r
- enum {\r
- BUFSIZE = 100,\r
- };\r
- int bp; // pointer to next free position \r
- int buf[BUFSIZE]; // pushed back input characters \r
- \r
- int skiptok(char term[]);\r
- int tok(struct token_st *token);\r
- void dumptok(struct token_st *token);\r
+ std::stack<int> m_stackPushBackInput;\r
+\r
+ bool skipSingleToken (char term[]);\r
+ int tok (struct token_st *token);\r
+ void dumptok (struct token_st *token);\r
\r
\r
- int getpol_tok(struct token_st *token);\r
- int getcmd();\r
+ int getpol_tok (struct token_st *token);\r
+ int getcmd ();\r
int gettok (TOKEN *tok);\r
- void getblank(char *s, int toksiz);\r
- int getalpha(char *s, int toksiz);\r
- void getquote(char *qs, int toksiz);\r
- void getescape(char *s, int delim, int toksiz);\r
+ void getblank (char *s, int toksiz);\r
+ int getalpha (char *s, int toksiz);\r
+ void getquote (char *qs, int toksiz);\r
+ void getescape (char *s, int delim, int toksiz);\r
int getnumber (char str[], int strsize, double *fnum, int *inum);\r
- void eatline();\r
- int type(int c);\r
- void inittable(SYMBOL *table[]);\r
- void freetable(SYMBOL *table[]);\r
- int hash(char *s);\r
- SYMBOL *lookup(SYMBOL *table[], char *s);\r
- SYMBOL *install(SYMBOL *table[], char *s, int def);\r
- int getch(FILE *fp);\r
+ void eatline ();\r
+ int type (int c);\r
+ int getch (FILE *fp);\r
\r
};