1233237Sjkim%{
2233237Sjkim/******************************************************************************
3233237Sjkim *
4233237Sjkim * Module Name: prparser.l - Flex input file for preprocessor lexer
5233237Sjkim *
6233237Sjkim *****************************************************************************/
7233237Sjkim
8233237Sjkim/*
9306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp.
10233237Sjkim * All rights reserved.
11233237Sjkim *
12233237Sjkim * Redistribution and use in source and binary forms, with or without
13233237Sjkim * modification, are permitted provided that the following conditions
14233237Sjkim * are met:
15233237Sjkim * 1. Redistributions of source code must retain the above copyright
16233237Sjkim *    notice, this list of conditions, and the following disclaimer,
17233237Sjkim *    without modification.
18233237Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19233237Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
20233237Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
21233237Sjkim *    including a substantially similar Disclaimer requirement for further
22233237Sjkim *    binary redistribution.
23233237Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
24233237Sjkim *    of any contributors may be used to endorse or promote products derived
25233237Sjkim *    from this software without specific prior written permission.
26233237Sjkim *
27233237Sjkim * Alternatively, this software may be distributed under the terms of the
28233237Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
29233237Sjkim * Software Foundation.
30233237Sjkim *
31233237Sjkim * NO WARRANTY
32233237Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33233237Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34233237Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35233237Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36233237Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37233237Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38233237Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39233237Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40233237Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41233237Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42233237Sjkim * POSSIBILITY OF SUCH DAMAGES.
43233237Sjkim */
44233237Sjkim
45233250Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
46233237Sjkim#include "prparser.y.h"
47233237Sjkim
48233237Sjkim/* Buffer to pass strings to the parser */
49233237Sjkim
50233237Sjkim#define STRING_SETUP    strcpy (StringBuffer, PrParsertext);\
51233237Sjkim    PrParserlval.str = StringBuffer
52233237Sjkim
53233237Sjkim#define _COMPONENT          ACPI_COMPILER
54233237Sjkim        ACPI_MODULE_NAME    ("prscanner")
55306536Sjkim
56306536Sjkim
57306536Sjkim/* Local prototypes */
58306536Sjkim
59306536Sjkimstatic char
60306536SjkimPrDoCommentType1 (
61306536Sjkim    void);
62306536Sjkim
63306536Sjkimstatic char
64306536SjkimPrDoCommentType2 (
65306536Sjkim    void);
66233237Sjkim%}
67233237Sjkim
68233237Sjkim%option noyywrap
69233237Sjkim
70233237SjkimNumber          [0-9a-fA-F]+
71233237SjkimHexNumber       0[xX][0-9a-fA-F]+
72233237SjkimWhiteSpace      [ \t\v\r]+
73233237SjkimNewLine         [\n]
74233237SjkimIdentifier      [a-zA-Z][0-9a-zA-Z]*
75233237Sjkim
76233237Sjkim%%
77306536Sjkim"/*"            { if (!PrDoCommentType1 ()) {yyterminate ();} }
78306536Sjkim"//"            { if (!PrDoCommentType2 ()) {yyterminate ();} }
79233237Sjkim
80233237Sjkim\(              return (EXPOP_PAREN_OPEN);
81233237Sjkim\)              return (EXPOP_PAREN_CLOSE);
82233237Sjkim\~              return (EXPOP_ONES_COMPLIMENT);
83233237Sjkim\!              return (EXPOP_LOGICAL_NOT);
84233237Sjkim\*              return (EXPOP_MULTIPLY);
85233237Sjkim\/              return (EXPOP_DIVIDE);
86233237Sjkim\%              return (EXPOP_MODULO);
87233237Sjkim\+              return (EXPOP_ADD);
88233237Sjkim\-              return (EXPOP_SUBTRACT);
89233237Sjkim">>"            return (EXPOP_SHIFT_RIGHT);
90233237Sjkim"<<"            return (EXPOP_SHIFT_LEFT);
91233237Sjkim\<              return (EXPOP_LESS);
92233237Sjkim\>              return (EXPOP_GREATER);
93233237Sjkim"<="            return (EXPOP_LESS_EQUAL);
94233237Sjkim">="            return (EXPOP_GREATER_EQUAL);
95233237Sjkim"=="            return (EXPOP_EQUAL);
96233237Sjkim"!="            return (EXPOP_NOT_EQUAL);
97233237Sjkim\&              return (EXPOP_AND);
98233237Sjkim\^              return (EXPOP_XOR);
99233237Sjkim\|              return (EXPOP_OR);
100233237Sjkim"&&"            return (EXPOP_LOGICAL_AND);
101233237Sjkim"||"            return (EXPOP_LOGICAL_OR);
102233237Sjkim
103233237Sjkim"defined"       return (EXPOP_DEFINE);
104233237Sjkim{Identifier}    {STRING_SETUP; return (EXPOP_IDENTIFIER);}
105233237Sjkim
106233237Sjkim<<EOF>>         return (EXPOP_EOF); /* null end-of-string */
107233237Sjkim
108233237Sjkim{Number}        return (EXPOP_NUMBER);
109233237Sjkim{HexNumber}     return (EXPOP_HEX_NUMBER);
110233237Sjkim{NewLine}       return (EXPOP_NEW_LINE);
111233237Sjkim{WhiteSpace}    /* Ignore */
112233237Sjkim
113233237Sjkim.               return (EXPOP_EOF);
114233237Sjkim%%
115233237Sjkim
116233237Sjkim/*
117233237Sjkim * Local support functions
118233237Sjkim */
119233237SjkimYY_BUFFER_STATE         LexBuffer;
120233237Sjkim
121233237Sjkim
122233237Sjkim/******************************************************************************
123233237Sjkim *
124233237Sjkim * FUNCTION:    PrInitLexer
125233237Sjkim *
126233237Sjkim * PARAMETERS:  String              - Input string to be parsed
127233237Sjkim *
128233237Sjkim * RETURN:      TRUE if parser returns NULL. FALSE otherwise.
129233237Sjkim *
130233237Sjkim * DESCRIPTION: Initialization routine for lexer. The lexer needs
131233237Sjkim *              a buffer to handle strings instead of a file.
132233237Sjkim *
133233237Sjkim *****************************************************************************/
134233237Sjkim
135233237Sjkimint
136233237SjkimPrInitLexer (
137233237Sjkim    char                    *String)
138233237Sjkim{
139233237Sjkim
140233237Sjkim    LexBuffer = yy_scan_string (String);
141233237Sjkim    return (LexBuffer == NULL);
142233237Sjkim}
143233237Sjkim
144233237Sjkim
145233237Sjkim/******************************************************************************
146233237Sjkim *
147233237Sjkim * FUNCTION:    PrTerminateLexer
148233237Sjkim *
149233237Sjkim * PARAMETERS:  None
150233237Sjkim *
151233237Sjkim * RETURN:      None
152233237Sjkim *
153233237Sjkim * DESCRIPTION: Termination routine for thelexer.
154233237Sjkim *
155233237Sjkim *****************************************************************************/
156233237Sjkim
157233237Sjkimvoid
158233237SjkimPrTerminateLexer (
159233237Sjkim    void)
160233237Sjkim{
161233237Sjkim
162233237Sjkim    yy_delete_buffer (LexBuffer);
163233237Sjkim}
164306536Sjkim
165306536Sjkim
166306536Sjkim/********************************************************************************
167306536Sjkim *
168306536Sjkim * FUNCTION:    PrDoCommentType1
169306536Sjkim *
170306536Sjkim * PARAMETERS:  none
171306536Sjkim *
172306536Sjkim * RETURN:      none
173306536Sjkim *
174306536Sjkim * DESCRIPTION: Process a new legacy comment. Just toss it.
175306536Sjkim *
176306536Sjkim ******************************************************************************/
177306536Sjkim
178306536Sjkimstatic char
179306536SjkimPrDoCommentType1 (
180306536Sjkim    void)
181306536Sjkim{
182306536Sjkim    int                 c;
183306536Sjkim
184306536Sjkim
185306536SjkimLoop:
186306536Sjkim    while (((c = input ()) != '*') && (c != EOF))
187306536Sjkim    {
188306536Sjkim    }
189306536Sjkim    if (c == EOF)
190306536Sjkim    {
191306536Sjkim        return (FALSE);
192306536Sjkim    }
193306536Sjkim
194306536Sjkim    if (((c = input ()) != '/') && (c != EOF))
195306536Sjkim    {
196306536Sjkim        unput (c);
197306536Sjkim        goto Loop;
198306536Sjkim    }
199306536Sjkim    if (c == EOF)
200306536Sjkim    {
201306536Sjkim        return (FALSE);
202306536Sjkim    }
203306536Sjkim
204306536Sjkim    return (TRUE);
205306536Sjkim}
206306536Sjkim
207306536Sjkim
208306536Sjkim/********************************************************************************
209306536Sjkim *
210306536Sjkim * FUNCTION:    PrDoCommentType2
211306536Sjkim *
212306536Sjkim * PARAMETERS:  none
213306536Sjkim *
214306536Sjkim * RETURN:      none
215306536Sjkim *
216306536Sjkim * DESCRIPTION: Process a new "//" comment. Just toss it.
217306536Sjkim *
218306536Sjkim ******************************************************************************/
219306536Sjkim
220306536Sjkimstatic char
221306536SjkimPrDoCommentType2 (
222306536Sjkim    void)
223306536Sjkim{
224306536Sjkim    int                 c;
225306536Sjkim
226306536Sjkim
227306536Sjkim    while (((c = input ()) != '\n') && (c != EOF))
228306536Sjkim    {
229306536Sjkim    }
230306536Sjkim    if (c == EOF)
231306536Sjkim    {
232306536Sjkim        return (FALSE);
233306536Sjkim    }
234306536Sjkim
235306536Sjkim    return (TRUE);
236306536Sjkim}
237