]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/CodeTools/Source/Pccts/h/DLexer.h
More renames for Tool Packages
[mirror_edk2.git] / Tools / CodeTools / Source / Pccts / h / DLexer.h
CommitLineData
878ddf1f 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
33#define ZZINC {if ( track_columns ) (++_endcol);}\r
34\r
35#define ZZGETC {ch = input->nextChar(); cl = ZZSHIFT(ch);}\r
36\r
37#define ZZNEWSTATE (newstate = dfa[state][cl])\r
38\r
39#ifndef ZZCOPY\r
40#define ZZCOPY \\r
41 /* Truncate matching buffer to size (not an error) */ \\r
42 if (nextpos < lastpos){ \\r
43 *(nextpos++) = ch; \\r
44 }else{ \\r
45 bufovf = 1; \\r
46 }\r
47#endif\r
48\r
49void DLGLexer::\r
50mode( int m )\r
51{\r
52 /* points to base of dfa table */\r
53 if (m<MAX_MODE){\r
54 automaton = m;\r
55 /* have to redo class since using different compression */\r
56 cl = ZZSHIFT(ch);\r
57 }else{\r
58 sprintf((char *)ebuf,"Invalid automaton mode = %d ",m);\r
59 errstd(ebuf);\r
60 }\r
61}\r
62\r
63ANTLRTokenType DLGLexer::\r
64nextTokenType(void)\r
65{\r
66 register int state, newstate;\r
67 /* last space reserved for the null char */\r
68 register DLGChar *lastpos;\r
69 ANTLRTokenType tk;\r
70\r
71skip:\r
72 bufovf = 0;\r
73 lastpos = &_lextext[_bufsize-1];\r
74 nextpos = _lextext;\r
75 _begcol = _endcol+1;\r
76more:\r
77 _begexpr = nextpos;\r
78 if ( interactive ) {\r
79 /* interactive version of automaton */\r
80 /* if there is something in ch, process it */\r
81 state = newstate = dfa_base[automaton];\r
82 if (charfull){\r
83 ZZINC;\r
84 ZZCOPY;\r
85 ZZNEWSTATE;\r
86 }\r
87 while (alternatives[newstate]){\r
88 state = newstate;\r
89 ZZGETC;\r
90 ZZINC;\r
91 ZZCOPY;\r
92 ZZNEWSTATE;\r
93 }\r
94 /* figure out if last character really part of token */\r
95 if ((state != dfa_base[automaton]) && (newstate == DfaStates)){\r
96 charfull = 1;\r
97 --nextpos;\r
98 }else{\r
99 charfull = 0;\r
100 state = newstate;\r
101 }\r
102 *(nextpos) = '\0';\r
103 /* Able to transition out of start state to some non err state?*/\r
104 if ( state == dfa_base[automaton] ){\r
105 /* make sure doesn't get stuck */\r
106 advance();\r
107 }\r
108 }\r
109 else { /* non-interactive version of automaton */\r
110 if (!charfull)\r
111 advance();\r
112 else\r
113 ZZINC;\r
114 state = dfa_base[automaton];\r
115 while (ZZNEWSTATE != DfaStates) {\r
116 state = newstate;\r
117 ZZCOPY;\r
118 ZZGETC;\r
119 ZZINC;\r
120 }\r
121 charfull = 1;\r
122 if ( state == dfa_base[automaton] ){\r
123 if (nextpos < lastpos){\r
124 *(nextpos++) = ch;\r
125 }else{\r
126 bufovf = 1;\r
127 }\r
128 *nextpos = '\0';\r
129 /* make sure doesn't get stuck */\r
130 advance();\r
131 }else{\r
132 *nextpos = '\0';\r
133 }\r
134 }\r
135 if ( track_columns ) _endcol -= charfull;\r
136 _endexpr = nextpos -1;\r
137 add_erase = 0;\r
138#ifdef OLD\r
139 tk = (ANTLRTokenType)\r
140 (*actions[accepts[state]])(this); // must pass this manually\r
141 // actions is not a [] of pointers\r
142 // to member functions.\r
143#endif\r
144 tk = (this->*actions[accepts[state]])();\r
145\r
146// MR1\r
147// MR1 11-Apr-97 Help for tracking DLG results\r
148// MR1\r
149\r
150#ifdef DEBUG_LEXER\r
151\r
152/* MR1 */ if (debugLexerFlag) {\r
153/* MR1 */ if (parser != NULL) {\r
154/* MR1 */ /* MR23 */ printMessage(stdout, "\ntoken name=%s",parser->parserTokenName(tk));\r
155/* MR1 */ } else {\r
156/* MR1 */ /* MR23 */ printMessage(stdout, "\ntoken nnumber=%d",tk);\r
157/* MR1 */ };\r
158/* MR1 */ /* MR23 */ printMessage(stdout, " lextext=(%s) mode=%d",\r
159/* MR1 */ (_lextext[0]=='\n' && _lextext[1]==0) ?\r
160/* MR1 */ "newline" : _lextext,\r
161/* MR1 */ automaton);\r
162/* MR1 */ if (interactive && !charfull) {\r
163/* MR1 */ /* MR23 */ printMessage(stdout, " char=empty");\r
164/* MR1 */ } else {\r
165/* MR1 */ if (ch=='\n') {\r
166/* MR1 */ /* MR23 */ printMessage(stdout, " char=newline");\r
167/* MR1 */ } else {\r
168/* MR1 */ /* MR23 */ printMessage(stdout, " char=(%c)",ch);\r
169/* MR1 */ };\r
170/* MR1 */ };\r
171/* MR1 */ /* MR23 */ printMessage(stdout, " %s\n",\r
172/* MR1 */ (add_erase==1 ? "skip()" :\r
173/* MR1 */ add_erase==2 ? "more()" :\r
174/* MR1 */ ""));\r
175/* MR1 */ };\r
176\r
177#endif\r
178\r
179 switch (add_erase) {\r
180 case 1: goto skip;\r
181 case 2: goto more;\r
182 }\r
183 return tk;\r
184}\r
185\r
186void DLGLexer::\r
187advance()\r
188{\r
189 if ( input==NULL ) err_in();\r
190 ZZGETC; charfull = 1; ZZINC;\r
191}\r