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