]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | /* DLGLexerBase.h\r |
2 | *\r | |
3 | * SOFTWARE RIGHTS\r | |
4 | *\r | |
5 | * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r | |
6 | * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r | |
7 | * company may do whatever they wish with source code distributed with\r | |
8 | * PCCTS or the code generated by PCCTS, including the incorporation of\r | |
9 | * PCCTS, or its output, into commerical software.\r | |
10 | *\r | |
11 | * We encourage users to develop software with PCCTS. However, we do ask\r | |
12 | * that credit is given to us for developing PCCTS. By "credit",\r | |
13 | * we mean that if you incorporate our source code into one of your\r | |
14 | * programs (commercial product, research project, or otherwise) that you\r | |
15 | * acknowledge this fact somewhere in the documentation, research report,\r | |
16 | * etc... If you like PCCTS and have developed a nice tool with the\r | |
17 | * output, please mention that you developed it using PCCTS. In\r | |
18 | * addition, we ask that this header remain intact in our source code.\r | |
19 | * As long as these guidelines are kept, we expect to continue enhancing\r | |
20 | * this system and expect to make other tools available as they are\r | |
21 | * completed.\r | |
22 | *\r | |
23 | * ANTLR 1.33\r | |
24 | * Terence Parr\r | |
25 | * Parr Research Corporation\r | |
26 | * with Purdue University and AHPCRC, University of Minnesota\r | |
27 | * 1989-2000\r | |
28 | */\r | |
29 | \r | |
30 | #ifndef DLGX_H\r | |
31 | #define DLGX_H\r | |
32 | \r | |
33 | #include "pcctscfg.h"\r | |
34 | #include "pccts_stdio.h"\r | |
35 | \r | |
36 | PCCTS_NAMESPACE_STD\r | |
37 | \r | |
38 | #include ATOKEN_H\r | |
39 | #include ATOKENSTREAM_H\r | |
40 | \r | |
41 | class ANTLRParser; // MR1\r | |
42 | \r | |
43 | /* must define what a char looks like; can make this a class too */\r | |
44 | typedef char DLGChar;\r | |
45 | \r | |
46 | /* Can have it as a class too: (ack this looks weird; is it right?)\r | |
47 | class DllExportPCCTS DLGChar {\r | |
48 | private:\r | |
49 | int c;\r | |
50 | public:\r | |
51 | DLGChar(int ch) { c = ch; }\r | |
52 | int atom() { return c; }\r | |
53 | };\r | |
54 | */\r | |
55 | \r | |
56 | /* user must subclass this */\r | |
57 | class DllExportPCCTS DLGInputStream {\r | |
58 | public:\r | |
59 | virtual int nextChar() = 0;\r | |
60 | };\r | |
61 | \r | |
62 | /* Predefined char stream: Input from FILE */\r | |
63 | class DllExportPCCTS DLGFileInput : public DLGInputStream {\r | |
64 | private:\r | |
65 | int found_eof;\r | |
66 | FILE *input;\r | |
67 | public:\r | |
68 | DLGFileInput(FILE *f) { input = f; found_eof = 0; }\r | |
69 | int nextChar() {\r | |
70 | int c;\r | |
71 | if ( found_eof ) return EOF;\r | |
72 | else {\r | |
73 | c=getc(input);\r | |
74 | if ( c==EOF ) found_eof = 1;\r | |
75 | return c;\r | |
76 | }\r | |
77 | }\r | |
78 | void DLGFileReset(FILE *f) {input=f; found_eof = 0; }; // MR11\r | |
79 | };\r | |
80 | \r | |
81 | // MR9 Suggested by Bruce Guenter (bruceg@qcc.sk.ca)\r | |
82 | // MR9 Make DLGStringInput const correct\r | |
83 | \r | |
84 | /* Predefined char stream: Input from string */\r | |
85 | class DllExportPCCTS DLGStringInput : public DLGInputStream {\r | |
86 | private:\r | |
87 | const DLGChar *input; // MR9\r | |
88 | const DLGChar *p; // MR9\r | |
89 | public:\r | |
90 | DLGStringInput(const DLGChar *s) { input = s; p = &input[0];} // MR9\r | |
91 | int nextChar()\r | |
92 | {\r | |
93 | if (*p) return (int) (unsigned char) *p++; // MR14\r | |
94 | else return EOF;\r | |
95 | }\r | |
96 | \r | |
97 | void DLGStringReset(const DLGChar *s) {input=s; p= &input[0]; }; // MR11 // MR16\r | |
98 | };\r | |
99 | \r | |
100 | class DllExportPCCTS DLGState {\r | |
101 | public:\r | |
102 | DLGInputStream *input;\r | |
103 | int interactive;\r | |
104 | int track_columns;\r | |
105 | int auto_num;\r | |
106 | int add_erase;\r | |
107 | int lookc;\r | |
108 | int char_full;\r | |
109 | int begcol, endcol;\r | |
110 | int line;\r | |
111 | DLGChar *lextext, *begexpr, *endexpr;\r | |
112 | int bufsize;\r | |
113 | int bufovf;\r | |
114 | DLGChar *nextpos;\r | |
115 | int class_num;\r | |
116 | int debugLexerFlag; // MR1\r | |
117 | ANTLRParser *parser; // MR1\r | |
118 | };\r | |
119 | \r | |
120 | /* user must subclass this */\r | |
121 | class DllExportPCCTS DLGLexerBase : public ANTLRTokenStream {\r | |
77dee0b1 HW |
122 | private:\r |
123 | DLGLexerBase(const DLGLexerBase&); // Prevent copy-construction\r | |
124 | DLGLexerBase& operator=(const DLGLexerBase&); // Prevent assignment\r | |
30fdf114 LG |
125 | public:\r |
126 | virtual ANTLRTokenType erraction();\r | |
127 | \r | |
128 | protected:\r | |
129 | DLGInputStream *input;\r | |
130 | int interactive;\r | |
131 | int track_columns;\r | |
132 | DLGChar *_lextext; /* text of most recently matched token */\r | |
133 | DLGChar *_begexpr; /* beginning of last reg expr recogn. */\r | |
134 | DLGChar *_endexpr; /* beginning of last reg expr recogn. */\r | |
135 | int _bufsize; /* number of characters in lextext */\r | |
136 | int _begcol; /* column that first character of token is in*/\r | |
137 | int _endcol; /* column that last character of token is in */\r | |
138 | int _line; /* line current token is on */\r | |
139 | int ch; /* character to determine next state */\r | |
140 | int bufovf; /* indicates that buffer too small for text */\r | |
141 | int charfull;\r | |
142 | DLGChar *nextpos; /* points to next available position in lextext*/\r | |
143 | int cl;\r | |
144 | int automaton;\r | |
145 | int add_erase;\r | |
146 | DLGChar ebuf[70];\r | |
147 | _ANTLRTokenPtr token_to_fill;\r | |
148 | \r | |
149 | int debugLexerFlag; // MR1\r | |
150 | ANTLRParser *parser; // MR1\r | |
151 | public:\r | |
152 | virtual _ANTLRTokenPtr getToken(); // MR12 public\r | |
153 | virtual void advance(void) = 0;\r | |
154 | void skip(void); /* erase lextext, look for antoher token */\r | |
155 | void more(void); /* keep lextext, look for another token */\r | |
156 | void mode(int k); /* switch to automaton 'k' */\r | |
157 | void saveState(DLGState *);\r | |
158 | void restoreState(DLGState *);\r | |
159 | virtual ANTLRTokenType nextTokenType(void)=0;/* get next token */\r | |
160 | void replchar(DLGChar c); /* replace last recognized reg. expr. with\r | |
161 | a character */\r | |
162 | void replstr(const DLGChar *s); /* replace last recognized reg. expr. with\r | |
163 | a string */ /* MR20 const */\r | |
164 | virtual int err_in(); // MR1\r | |
165 | virtual void errstd(const char *); // MR1 MR20 const\r | |
166 | int line() { return _line; }\r | |
167 | void set_line(int newValue) { _line=newValue; }; // MR1\r | |
168 | virtual void newline() { _line++; }\r | |
169 | DLGChar *lextext() { return _lextext; }\r | |
170 | \r | |
171 | int begcol() { return _begcol; }\r | |
172 | int endcol() { return _endcol; }\r | |
173 | void set_begcol(int a) { _begcol=a; }\r | |
174 | void set_endcol(int a) { _endcol=a; }\r | |
175 | DLGChar *begexpr() { return _begexpr; }\r | |
176 | DLGChar *endexpr() { return _endexpr; }\r | |
177 | int bufsize() { return _bufsize; }\r | |
178 | \r | |
179 | void setToken(ANTLRAbstractToken *t) { token_to_fill = t; }\r | |
180 | \r | |
181 | void setInputStream(DLGInputStream *);\r | |
182 | DLGLexerBase(DLGInputStream *in,\r | |
183 | unsigned bufsize=2000,\r | |
184 | int interactive=0,\r | |
185 | int track_columns=0);\r | |
186 | void reset(); // MR19\r | |
187 | virtual ~DLGLexerBase() { delete [] _lextext; }\r | |
188 | virtual void panic(const char *msg); // MR1 MR20 const\r | |
189 | void trackColumns() {\r | |
190 | track_columns = 1;\r | |
191 | this->_begcol = 0;\r | |
192 | this->_endcol = 0;\r | |
193 | };\r | |
194 | virtual ANTLRParser *setParser(ANTLRParser *p); // MR1\r | |
195 | virtual ANTLRParser *getParser(); // MR1\r | |
196 | virtual int debugLexer(int value); // MR1\r | |
197 | int lexErrCount; // MR12\r | |
198 | virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23\r | |
199 | };\r | |
200 | \r | |
201 | #endif\r |