]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/C/VfrCompile/Pccts/h/DLexer.h
BaseTools: Add Brotli algorithm tool
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / Pccts / h / DLexer.h
CommitLineData
30fdf114
LG
1/* DLexer.h (formerly DLexer.cpp)\r
2 *\r
3 * This was renamed because the use of the .cpp extension caused problems\r
4 * with IDEs.\r
5 *\r
6 * SOFTWARE RIGHTS\r
7 *\r
8 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
9 * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
10 * company may do whatever they wish with source code distributed with\r
11 * PCCTS or the code generated by PCCTS, including the incorporation of\r
12 * PCCTS, or its output, into commerical software.\r
13 *\r
14 * We encourage users to develop software with PCCTS. However, we do ask\r
15 * that credit is given to us for developing PCCTS. By "credit",\r
16 * we mean that if you incorporate our source code into one of your\r
17 * programs (commercial product, research project, or otherwise) that you\r
18 * acknowledge this fact somewhere in the documentation, research report,\r
19 * etc... If you like PCCTS and have developed a nice tool with the\r
20 * output, please mention that you developed it using PCCTS. In\r
21 * addition, we ask that this header remain intact in our source code.\r
22 * As long as these guidelines are kept, we expect to continue enhancing\r
23 * this system and expect to make other tools available as they are\r
24 * completed.\r
25 *\r
26 * ANTLR 1.33\r
27 * Terence Parr\r
28 * Parr Research Corporation\r
29 * with Purdue University and AHPCRC, University of Minnesota\r
30 * 1989-2000\r
31 */\r
32\r
bab5ad2f
HW
33#include <assert.h>\r
34\r
30fdf114
LG
35#define ZZINC {if ( track_columns ) (++_endcol);}\r
36\r
37#define ZZGETC {ch = input->nextChar(); cl = ZZSHIFT(ch);}\r
38\r
39#define ZZNEWSTATE (newstate = dfa[state][cl])\r
40\r
41#ifndef ZZCOPY\r
42#define ZZCOPY \\r
43 /* Truncate matching buffer to size (not an error) */ \\r
44 if (nextpos < lastpos){ \\r
45 *(nextpos++) = ch; \\r
46 }else{ \\r
47 bufovf = 1; \\r
48 }\r
49#endif\r
50\r
51void DLGLexer::\r
52mode( int m )\r
53{\r
54 /* points to base of dfa table */\r
55 if (m<MAX_MODE){\r
56 automaton = m;\r
57 /* have to redo class since using different compression */\r
58 cl = ZZSHIFT(ch);\r
59 }else{\r
60 sprintf((char *)ebuf,"Invalid automaton mode = %d ",m);\r
61 errstd(ebuf);\r
62 }\r
63}\r
64\r
65ANTLRTokenType DLGLexer::\r
66nextTokenType(void)\r
67{\r
68 register int state, newstate;\r
69 /* last space reserved for the null char */\r
70 register DLGChar *lastpos;\r
71 ANTLRTokenType tk;\r
72\r
73skip:\r
74 bufovf = 0;\r
75 lastpos = &_lextext[_bufsize-1];\r
76 nextpos = _lextext;\r
77 _begcol = _endcol+1;\r
78more:\r
79 _begexpr = nextpos;\r
80 if ( interactive ) {\r
81 /* interactive version of automaton */\r
82 /* if there is something in ch, process it */\r
83 state = newstate = dfa_base[automaton];\r
84 if (charfull){\r
85 ZZINC;\r
86 ZZCOPY;\r
87 ZZNEWSTATE;\r
88 }\r
89 while (alternatives[newstate]){\r
90 state = newstate;\r
91 ZZGETC;\r
92 ZZINC;\r
93 ZZCOPY;\r
94 ZZNEWSTATE;\r
95 }\r
96 /* figure out if last character really part of token */\r
97 if ((state != dfa_base[automaton]) && (newstate == DfaStates)){\r
98 charfull = 1;\r
99 --nextpos;\r
100 }else{\r
101 charfull = 0;\r
102 state = newstate;\r
103 }\r
104 *(nextpos) = '\0';\r
105 /* Able to transition out of start state to some non err state?*/\r
106 if ( state == dfa_base[automaton] ){\r
107 /* make sure doesn't get stuck */\r
108 advance();\r
109 }\r
110 }\r
111 else { /* non-interactive version of automaton */\r
112 if (!charfull)\r
113 advance();\r
114 else\r
115 ZZINC;\r
116 state = dfa_base[automaton];\r
117 while (ZZNEWSTATE != DfaStates) {\r
118 state = newstate;\r
bab5ad2f 119 assert(state <= sizeof(dfa)/sizeof(dfa[0]));\r
30fdf114
LG
120 ZZCOPY;\r
121 ZZGETC;\r
122 ZZINC;\r
123 }\r
124 charfull = 1;\r
125 if ( state == dfa_base[automaton] ){\r
126 if (nextpos < lastpos){\r
127 *(nextpos++) = ch;\r
128 }else{\r
129 bufovf = 1;\r
130 }\r
131 *nextpos = '\0';\r
132 /* make sure doesn't get stuck */\r
133 advance();\r
134 }else{\r
135 *nextpos = '\0';\r
136 }\r
137 }\r
138 if ( track_columns ) _endcol -= charfull;\r
139 _endexpr = nextpos -1;\r
140 add_erase = 0;\r
141#ifdef OLD\r
142 tk = (ANTLRTokenType)\r
143 (*actions[accepts[state]])(this); // must pass this manually\r
144 // actions is not a [] of pointers\r
145 // to member functions.\r
146#endif\r
147 tk = (this->*actions[accepts[state]])();\r
148\r
149// MR1\r
150// MR1 11-Apr-97 Help for tracking DLG results\r
151// MR1\r
152\r
153#ifdef DEBUG_LEXER\r
154\r
155/* MR1 */ if (debugLexerFlag) {\r
156/* MR1 */ if (parser != NULL) {\r
157/* MR1 */ /* MR23 */ printMessage(stdout, "\ntoken name=%s",parser->parserTokenName(tk));\r
158/* MR1 */ } else {\r
159/* MR1 */ /* MR23 */ printMessage(stdout, "\ntoken nnumber=%d",tk);\r
160/* MR1 */ };\r
161/* MR1 */ /* MR23 */ printMessage(stdout, " lextext=(%s) mode=%d",\r
162/* MR1 */ (_lextext[0]=='\n' && _lextext[1]==0) ?\r
163/* MR1 */ "newline" : _lextext,\r
164/* MR1 */ automaton);\r
165/* MR1 */ if (interactive && !charfull) {\r
166/* MR1 */ /* MR23 */ printMessage(stdout, " char=empty");\r
167/* MR1 */ } else {\r
168/* MR1 */ if (ch=='\n') {\r
169/* MR1 */ /* MR23 */ printMessage(stdout, " char=newline");\r
170/* MR1 */ } else {\r
171/* MR1 */ /* MR23 */ printMessage(stdout, " char=(%c)",ch);\r
172/* MR1 */ };\r
173/* MR1 */ };\r
174/* MR1 */ /* MR23 */ printMessage(stdout, " %s\n",\r
175/* MR1 */ (add_erase==1 ? "skip()" :\r
176/* MR1 */ add_erase==2 ? "more()" :\r
177/* MR1 */ ""));\r
178/* MR1 */ };\r
179\r
180#endif\r
181\r
182 switch (add_erase) {\r
183 case 1: goto skip;\r
184 case 2: goto more;\r
185 }\r
186 return tk;\r
187}\r
188\r
189void DLGLexer::\r
190advance()\r
191{\r
192 if ( input==NULL ) err_in();\r
193 ZZGETC; charfull = 1; ZZINC;\r
194}\r