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