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