Home | History | Annotate | Line # | Download | only in compiler
dtcompilerparser.y revision 1.1
      1 %{
      2 /******************************************************************************
      3  *
      4  * Module Name: dtcompilerparser.y - Bison input file for table compiler parser
      5  *
      6  *****************************************************************************/
      7 
      8 /*
      9  * Copyright (C) 2000 - 2019, 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 MERCHANTIBILITY 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 
     47 
     48 #define _COMPONENT          DT_COMPILER
     49         ACPI_MODULE_NAME    ("dtcompilerparser")
     50 
     51 void *                      AslLocalAllocate (unsigned int Size);
     52 
     53 /* Bison/yacc configuration */
     54 
     55 #undef alloca
     56 #define alloca              AslLocalAllocate
     57 
     58 int                         DtCompilerParserlex (void);
     59 int                         DtCompilerParserparse (void);
     60 void                        DtCompilerParsererror (char const *msg);
     61 extern char                 *DtCompilerParsertext;
     62 extern DT_FIELD             *AslGbl_CurrentField;
     63 
     64 extern UINT64               DtCompilerParserResult; /* Expression return value */
     65 extern UINT64               DtCompilerParserlineno; /* Current line number */
     66 
     67 /* Bison/yacc configuration */
     68 
     69 #define yytname             DtCompilerParsername
     70 #define YYDEBUG             1               /* Enable debug output */
     71 #define YYERROR_VERBOSE     1               /* Verbose error messages */
     72 #define YYFLAG              -32768
     73 
     74 /* Define YYMALLOC/YYFREE to prevent redefinition errors  */
     75 
     76 #define YYMALLOC            malloc
     77 #define YYFREE              free
     78 
     79 %}
     80 
     81 %code requires {
     82 
     83     typedef struct YYLTYPE {
     84         int first_line;
     85         int last_line;
     86         int first_column;
     87         int last_column;
     88         int first_byte_offset;
     89     } YYLTYPE;
     90 
     91     #define YYLTYPE_IS_DECLARED 1
     92 }
     93 
     94 
     95 %union {
     96     char                *s;
     97     DT_FIELD            *f;
     98 }
     99 
    100 
    101 %type  <f> Table
    102 %token <s> DT_PARSEOP_DATA
    103 %token <s> DT_PARSEOP_LABEL
    104 %token <s> DT_PARSEOP_STRING_DATA
    105 %token <s> DT_PARSEOP_LINE_CONTINUATION
    106 %type  <s> Data
    107 %type  <s> Datum
    108 %type  <s> MultiLineData
    109 %type  <s> MultiLineDataList
    110 
    111 
    112 %%
    113 
    114 Table
    115     :
    116     FieldList { DtCompilerParserResult = 5;}
    117     ;
    118 
    119 FieldList
    120     : Field FieldList
    121     | Field
    122     ;
    123 
    124 Field
    125     : DT_PARSEOP_LABEL ':' Data { DtCreateField ($1, $3, (@3).first_line, (@1).first_byte_offset, (@1).first_column, (@3).first_column); }
    126     ;
    127 
    128 Data
    129     : MultiLineDataList        { $$ = $1; }
    130     | Datum                    { $$ = $1; }
    131     | Datum MultiLineDataList  { $$ = $1; } /* combine the string with strcat */
    132     ;
    133 
    134 MultiLineDataList
    135     : MultiLineDataList MultiLineData { $$ = AcpiUtStrcat(AcpiUtStrcat($1, " "), $2); } /* combine the strings with strcat */
    136     | MultiLineData                   { $$ = $1; }
    137     ;
    138 
    139 MultiLineData
    140     : DT_PARSEOP_LINE_CONTINUATION Datum { DbgPrint (ASL_PARSE_OUTPUT, "line continuation detected\n"); $$ = $2; }
    141     ;
    142 
    143 Datum
    144     : DT_PARSEOP_DATA        { DbgPrint (ASL_PARSE_OUTPUT, "parser        data: [%s]\n", DtCompilerParserlval.s); $$ = AcpiUtStrdup(DtCompilerParserlval.s); }
    145     | DT_PARSEOP_STRING_DATA { DbgPrint (ASL_PARSE_OUTPUT, "parser string data: [%s]\n", DtCompilerParserlval.s); $$ = AcpiUtStrdup(DtCompilerParserlval.s); }
    146     ;
    147 
    148 
    149 %%
    150 
    151 
    152 /*
    153  * Local support functions, including parser entry point
    154  */
    155 /******************************************************************************
    156  *
    157  * FUNCTION:    DtCompilerParsererror
    158  *
    159  * PARAMETERS:  Message             - Parser-generated error message
    160  *
    161  * RETURN:      None
    162  *
    163  * DESCRIPTION: Handler for parser errors
    164  *
    165  *****************************************************************************/
    166 
    167 void
    168 DtCompilerParsererror (
    169     char const              *Message)
    170 {
    171     DtError (ASL_ERROR, ASL_MSG_SYNTAX,
    172         AslGbl_CurrentField, (char *) Message);
    173 }
    174 
    175 int
    176 DtCompilerParserwrap(void)
    177 {
    178   return (1);
    179 }
    180