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