Home | History | Annotate | Line # | Download | only in compiler
dtcompilerparser.y revision 1.1.1.6
      1 %{
      2 /******************************************************************************
      3  *
      4  * Module Name: dtcompilerparser.y - Bison input file for table compiler parser
      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 
     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 int                  DtLabelByteOffset;
     65 extern UINT64               DtCompilerParserlineno; /* Current line number */
     66 
     67 extern UINT32               DtTokenFirstLine;
     68 extern UINT32               DtTokenFirstColumn;
     69 
     70 /* Bison/yacc configuration */
     71 
     72 #define yytname             DtCompilerParsername
     73 #define YYDEBUG             1               /* Enable debug output */
     74 #define YYERROR_VERBOSE     1               /* Verbose error messages */
     75 #define YYFLAG              -32768
     76 
     77 /* Define YYMALLOC/YYFREE to prevent redefinition errors  */
     78 
     79 #define YYMALLOC            malloc
     80 #define YYFREE              free
     81 
     82 %}
     83 
     84 
     85 %union {
     86     char                *s;
     87     DT_FIELD            *f;
     88     DT_TABLE_UNIT       *u;
     89 }
     90 
     91 
     92 %type  <f> Table
     93 %token <u> DT_PARSEOP_DATA
     94 %token <u> DT_PARSEOP_LABEL
     95 %token <u> DT_PARSEOP_STRING_DATA
     96 %token <u> DT_PARSEOP_LINE_CONTINUATION
     97 %type  <u> Data
     98 %type  <u> Datum
     99 %type  <u> MultiLineData
    100 %type  <u> MultiLineDataList
    101 
    102 
    103 %%
    104 
    105 Table
    106     :
    107     FieldList { }
    108     ;
    109 
    110 FieldList
    111     : Field FieldList
    112     | Field
    113     ;
    114 
    115 Field
    116     : DT_PARSEOP_LABEL ':' Data { DtCreateField ($1, $3, DtLabelByteOffset); }
    117     ;
    118 
    119 Data
    120     : MultiLineDataList        { $$ = $1; }
    121     | Datum                    { $$ = $1; }
    122     | Datum MultiLineDataList  { $$ = $1; } /* combine the string with strcat */
    123     ;
    124 
    125 MultiLineDataList
    126     : MultiLineDataList MultiLineData { $$ = DtCreateTableUnit (AcpiUtStrcat(AcpiUtStrcat($1->Value, " "), $2->Value), $1->Line, $1->Column); } /* combine the strings with strcat */
    127     | MultiLineData                   { $$ = $1; }
    128     ;
    129 
    130 MultiLineData
    131     : DT_PARSEOP_LINE_CONTINUATION Datum { DbgPrint (ASL_PARSE_OUTPUT, "line continuation detected\n"); $$ = $2; }
    132     ;
    133 
    134 Datum
    135     : DT_PARSEOP_DATA        {
    136                                  DbgPrint (ASL_PARSE_OUTPUT, "parser        data: [%s]\n", DtCompilerParserlval.s);
    137                                  $$ = DtCreateTableUnit (AcpiUtStrdup(DtCompilerParserlval.s), DtTokenFirstLine, DtTokenFirstColumn);
    138                              }
    139     | DT_PARSEOP_STRING_DATA {
    140                                  DbgPrint (ASL_PARSE_OUTPUT, "parser string data: [%s]\n", DtCompilerParserlval.s);
    141                                  $$ = DtCreateTableUnit (AcpiUtStrdup(DtCompilerParserlval.s), DtTokenFirstLine, DtTokenFirstColumn);
    142                              }
    143     ;
    144 
    145 
    146 %%
    147 
    148 
    149 /*
    150  * Local support functions, including parser entry point
    151  */
    152 /******************************************************************************
    153  *
    154  * FUNCTION:    DtCompilerParsererror
    155  *
    156  * PARAMETERS:  Message             - Parser-generated error message
    157  *
    158  * RETURN:      None
    159  *
    160  * DESCRIPTION: Handler for parser errors
    161  *
    162  *****************************************************************************/
    163 
    164 void
    165 DtCompilerParsererror (
    166     char const              *Message)
    167 {
    168     DtError (ASL_ERROR, ASL_MSG_SYNTAX,
    169         AslGbl_CurrentField, (char *) Message);
    170 }
    171 
    172 int
    173 DtCompilerParserwrap(void)
    174 {
    175   return (1);
    176 }
    177