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