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