]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/CodeTools/TianoTools/Pccts/h/DLexerBase.h
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / CodeTools / TianoTools / Pccts / h / DLexerBase.h
CommitLineData
878ddf1f 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
36PCCTS_NAMESPACE_STD\r
37\r
38#include ATOKEN_H\r
39#include ATOKENSTREAM_H\r
40\r
41class ANTLRParser; // MR1\r
42\r
43/* must define what a char looks like; can make this a class too */\r
44typedef char DLGChar;\r
45\r
46/* Can have it as a class too: (ack this looks weird; is it right?)\r
47class DllExportPCCTS DLGChar {\r
48private:\r
49 int c;\r
50public:\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
57class DllExportPCCTS DLGInputStream {\r
58public:\r
59 virtual int nextChar() = 0;\r
60};\r
61\r
62/* Predefined char stream: Input from FILE */\r
63class DllExportPCCTS DLGFileInput : public DLGInputStream {\r
64private:\r
65 int found_eof;\r
66 FILE *input;\r
67public:\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
85class DllExportPCCTS DLGStringInput : public DLGInputStream {\r
86private:\r
87 const DLGChar *input; // MR9\r
88 const DLGChar *p; // MR9\r
89public:\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
100class DllExportPCCTS DLGState {\r
101public:\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
121class DllExportPCCTS DLGLexerBase : public ANTLRTokenStream {\r
122public:\r
123 virtual ANTLRTokenType erraction();\r
124\r
125protected:\r
126 DLGInputStream *input;\r
127 int interactive;\r
128 int track_columns;\r
129 DLGChar *_lextext; /* text of most recently matched token */\r
130 DLGChar *_begexpr; /* beginning of last reg expr recogn. */\r
131 DLGChar *_endexpr; /* beginning of last reg expr recogn. */\r
132 int _bufsize; /* number of characters in lextext */\r
133 int _begcol; /* column that first character of token is in*/\r
134 int _endcol; /* column that last character of token is in */\r
135 int _line; /* line current token is on */\r
136 int ch; /* character to determine next state */\r
137 int bufovf; /* indicates that buffer too small for text */\r
138 int charfull;\r
139 DLGChar *nextpos; /* points to next available position in lextext*/\r
140 int cl;\r
141 int automaton;\r
142 int add_erase;\r
143 DLGChar ebuf[70];\r
144 _ANTLRTokenPtr token_to_fill;\r
145\r
146 int debugLexerFlag; // MR1\r
147 ANTLRParser *parser; // MR1\r
148public:\r
149 virtual _ANTLRTokenPtr getToken(); // MR12 public\r
150 virtual void advance(void) = 0;\r
151 void skip(void); /* erase lextext, look for antoher token */\r
152 void more(void); /* keep lextext, look for another token */\r
153 void mode(int k); /* switch to automaton 'k' */\r
154 void saveState(DLGState *);\r
155 void restoreState(DLGState *);\r
156 virtual ANTLRTokenType nextTokenType(void)=0;/* get next token */\r
157 void replchar(DLGChar c); /* replace last recognized reg. expr. with\r
158 a character */\r
159 void replstr(const DLGChar *s); /* replace last recognized reg. expr. with\r
160 a string */ /* MR20 const */\r
161 virtual int err_in(); // MR1\r
162 virtual void errstd(const char *); // MR1 MR20 const\r
163 int line() { return _line; }\r
164 void set_line(int newValue) { _line=newValue; }; // MR1\r
165 virtual void newline() { _line++; }\r
166 DLGChar *lextext() { return _lextext; }\r
167\r
168 int begcol() { return _begcol; }\r
169 int endcol() { return _endcol; }\r
170 void set_begcol(int a) { _begcol=a; }\r
171 void set_endcol(int a) { _endcol=a; }\r
172 DLGChar *begexpr() { return _begexpr; }\r
173 DLGChar *endexpr() { return _endexpr; }\r
174 int bufsize() { return _bufsize; }\r
175\r
176 void setToken(ANTLRAbstractToken *t) { token_to_fill = t; }\r
177\r
178 void setInputStream(DLGInputStream *);\r
179 DLGLexerBase(DLGInputStream *in,\r
180 unsigned bufsize=2000,\r
181 int interactive=0,\r
182 int track_columns=0);\r
183 void reset(); // MR19\r
184 virtual ~DLGLexerBase() { delete [] _lextext; }\r
185 virtual void panic(const char *msg); // MR1 MR20 const\r
186 void trackColumns() {\r
187 track_columns = 1;\r
188 this->_begcol = 0;\r
189 this->_endcol = 0;\r
190 };\r
191 virtual ANTLRParser *setParser(ANTLRParser *p); // MR1\r
192 virtual ANTLRParser *getParser(); // MR1\r
193 virtual int debugLexer(int value); // MR1\r
194 int lexErrCount; // MR12\r
195 virtual int printMessage(FILE* pFile, const char* pFormat, ...); // MR23\r
196};\r
197\r
198#endif\r