1 %{
2 /******************************************************************************
3 *
4 * Module Name: prparser.l - Flex input file for preprocessor lexer
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2023, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45 #include "aslcompiler.h"
46 #include "prparser.y.h"
47
48 /* Buffer to pass strings to the parser */
49
50 #define STRING_SETUP strcpy (AslGbl_StringBuffer, PrParsertext);\
51 PrParserlval.str = AslGbl_StringBuffer
52
53 #define _COMPONENT ACPI_COMPILER
54 ACPI_MODULE_NAME ("prscanner")
55
56
57 /* Local prototypes */
58
59 static char
60 PrDoCommentType1 (
61 void);
62
63 static char
64 PrDoCommentType2 (
65 void);
66 %}
67
68 %option noyywrap
69
70 Number [0-9a-fA-F]+
71 HexNumber 0[xX][0-9a-fA-F]+
72 WhiteSpace [ \t\v\r]+
73 NewLine [\n]
74 Identifier [a-zA-Z][0-9a-zA-Z]*
75
76 %%
77 "/*" { if (!PrDoCommentType1 ()) {yyterminate ();} }
78 "//" { if (!PrDoCommentType2 ()) {yyterminate ();} }
79
80 \( return (EXPOP_PAREN_OPEN);
81 \) return (EXPOP_PAREN_CLOSE);
82 \~ return (EXPOP_ONES_COMPLIMENT);
83 \! return (EXPOP_LOGICAL_NOT);
84 \* return (EXPOP_MULTIPLY);
85 \/ return (EXPOP_DIVIDE);
86 \% return (EXPOP_MODULO);
87 \+ return (EXPOP_ADD);
88 \- return (EXPOP_SUBTRACT);
89 ">>" return (EXPOP_SHIFT_RIGHT);
90 "<<" return (EXPOP_SHIFT_LEFT);
91 \< return (EXPOP_LESS);
92 \> return (EXPOP_GREATER);
93 "<=" return (EXPOP_LESS_EQUAL);
94 ">=" return (EXPOP_GREATER_EQUAL);
95 "==" return (EXPOP_EQUAL);
96 "!=" return (EXPOP_NOT_EQUAL);
97 \& return (EXPOP_AND);
98 \^ return (EXPOP_XOR);
99 \| return (EXPOP_OR);
100 "&&" return (EXPOP_LOGICAL_AND);
101 "||" return (EXPOP_LOGICAL_OR);
102
103 "defined" return (EXPOP_DEFINE);
104 {Identifier} {STRING_SETUP; return (EXPOP_IDENTIFIER);}
105
106 <<EOF>> return (EXPOP_EOF); /* null end-of-string */
107
108 {Number} return (EXPOP_NUMBER);
109 {HexNumber} return (EXPOP_HEX_NUMBER);
110 {NewLine} return (EXPOP_NEW_LINE);
111 {WhiteSpace} /* Ignore */
112
113 . return (EXPOP_EOF);
114 %%
115
116 /*
117 * Local support functions
118 */
119 static YY_BUFFER_STATE LexBuffer;
120
121
122 /******************************************************************************
123 *
124 * FUNCTION: PrInitLexer
125 *
126 * PARAMETERS: String - Input string to be parsed
127 *
128 * RETURN: TRUE if parser returns NULL. FALSE otherwise.
129 *
130 * DESCRIPTION: Initialization routine for lexer. The lexer needs
131 * a buffer to handle strings instead of a file.
132 *
133 *****************************************************************************/
134
135 int
PrInitLexer(char * String)136 PrInitLexer (
137 char *String)
138 {
139
140 LexBuffer = yy_scan_string (String);
141 return (LexBuffer == NULL);
142 }
143
144
145 /******************************************************************************
146 *
147 * FUNCTION: PrTerminateLexer
148 *
149 * PARAMETERS: None
150 *
151 * RETURN: None
152 *
153 * DESCRIPTION: Termination routine for thelexer.
154 *
155 *****************************************************************************/
156
157 void
PrTerminateLexer(void)158 PrTerminateLexer (
159 void)
160 {
161
162 yy_delete_buffer (LexBuffer);
163 }
164
165
166 /********************************************************************************
167 *
168 * FUNCTION: PrDoCommentType1
169 *
170 * PARAMETERS: none
171 *
172 * RETURN: none
173 *
174 * DESCRIPTION: Process a new legacy comment. Just toss it.
175 *
176 ******************************************************************************/
177
178 static char
PrDoCommentType1(void)179 PrDoCommentType1 (
180 void)
181 {
182 int c;
183
184
185 Loop:
186 while (((c = input ()) != '*') && (c != EOF))
187 {
188 }
189 if (c == EOF)
190 {
191 return (FALSE);
192 }
193
194 if (((c = input ()) != '/') && (c != EOF))
195 {
196 unput (c);
197 goto Loop;
198 }
199 if (c == EOF)
200 {
201 return (FALSE);
202 }
203
204 return (TRUE);
205 }
206
207
208 /********************************************************************************
209 *
210 * FUNCTION: PrDoCommentType2
211 *
212 * PARAMETERS: none
213 *
214 * RETURN: none
215 *
216 * DESCRIPTION: Process a new "//" comment. Just toss it.
217 *
218 ******************************************************************************/
219
220 static char
PrDoCommentType2(void)221 PrDoCommentType2 (
222 void)
223 {
224 int c;
225
226
227 while (((c = input ()) != '\n') && (c != EOF))
228 {
229 }
230 if (c == EOF)
231 {
232 return (FALSE);
233 }
234
235 return (TRUE);
236 }
237