Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / compiler / dtparser.y
blob014e34a9fe5fb039d7c7611de8f1fe08867d946b
1 %{
2 /******************************************************************************
4 * Module Name: dtparser.y - Bison input file for table compiler parser
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2013, Intel Corp.
10 * All rights reserved.
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.
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.
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.
45 #include "aslcompiler.h"
46 #include "dtcompiler.h"
48 #define _COMPONENT DT_COMPILER
49 ACPI_MODULE_NAME ("dtparser")
51 int DtParserlex (void);
52 int DtParserparse (void);
53 void DtParsererror (char const *msg);
54 extern char *DtParsertext;
55 extern DT_FIELD *Gbl_CurrentField;
57 UINT64 DtParserResult; /* Expression return value */
59 /* Bison/yacc configuration */
61 #define yytname DtParsername
62 #define YYDEBUG 1 /* Enable debug output */
63 #define YYERROR_VERBOSE 1 /* Verbose error messages */
64 #define YYFLAG -32768
66 /* Define YYMALLOC/YYFREE to prevent redefinition errors */
68 #define YYMALLOC malloc
69 #define YYFREE free
72 %union
74 UINT64 value;
75 UINT32 op;
78 /*! [Begin] no source code translation */
80 %type <value> Expression
82 %token <op> EXPOP_EOF
83 %token <op> EXPOP_NEW_LINE
84 %token <op> EXPOP_NUMBER
85 %token <op> EXPOP_HEX_NUMBER
86 %token <op> EXPOP_DECIMAL_NUMBER
87 %token <op> EXPOP_LABEL
88 %token <op> EXPOP_PAREN_OPEN
89 %token <op> EXPOP_PAREN_CLOSE
91 %left <op> EXPOP_LOGICAL_OR
92 %left <op> EXPOP_LOGICAL_AND
93 %left <op> EXPOP_OR
94 %left <op> EXPOP_XOR
95 %left <op> EXPOP_AND
96 %left <op> EXPOP_EQUAL EXPOP_NOT_EQUAL
97 %left <op> EXPOP_GREATER EXPOP_LESS EXPOP_GREATER_EQUAL EXPOP_LESS_EQUAL
98 %left <op> EXPOP_SHIFT_RIGHT EXPOP_SHIFT_LEFT
99 %left <op> EXPOP_ADD EXPOP_SUBTRACT
100 %left <op> EXPOP_MULTIPLY EXPOP_DIVIDE EXPOP_MODULO
101 %right <op> EXPOP_ONES_COMPLIMENT EXPOP_LOGICAL_NOT
106 * Operator precedence rules (from K&R)
108 * 1) ( )
109 * 2) ! ~ (unary operators that are supported here)
110 * 3) * / %
111 * 4) + -
112 * 5) >> <<
113 * 6) < > <= >=
114 * 7) == !=
115 * 8) &
116 * 9) ^
117 * 10) |
118 * 11) &&
119 * 12) ||
121 Value
122 : Expression EXPOP_NEW_LINE { DtParserResult=$1; return 0; } /* End of line (newline) */
123 | Expression EXPOP_EOF { DtParserResult=$1; return 0; } /* End of string (0) */
126 Expression
128 /* Unary operators */
130 : EXPOP_LOGICAL_NOT Expression { $$ = DtDoOperator ($2, EXPOP_LOGICAL_NOT, $2);}
131 | EXPOP_ONES_COMPLIMENT Expression { $$ = DtDoOperator ($2, EXPOP_ONES_COMPLIMENT, $2);}
133 /* Binary operators */
135 | Expression EXPOP_MULTIPLY Expression { $$ = DtDoOperator ($1, EXPOP_MULTIPLY, $3);}
136 | Expression EXPOP_DIVIDE Expression { $$ = DtDoOperator ($1, EXPOP_DIVIDE, $3);}
137 | Expression EXPOP_MODULO Expression { $$ = DtDoOperator ($1, EXPOP_MODULO, $3);}
138 | Expression EXPOP_ADD Expression { $$ = DtDoOperator ($1, EXPOP_ADD, $3);}
139 | Expression EXPOP_SUBTRACT Expression { $$ = DtDoOperator ($1, EXPOP_SUBTRACT, $3);}
140 | Expression EXPOP_SHIFT_RIGHT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_RIGHT, $3);}
141 | Expression EXPOP_SHIFT_LEFT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_LEFT, $3);}
142 | Expression EXPOP_GREATER Expression { $$ = DtDoOperator ($1, EXPOP_GREATER, $3);}
143 | Expression EXPOP_LESS Expression { $$ = DtDoOperator ($1, EXPOP_LESS, $3);}
144 | Expression EXPOP_GREATER_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_GREATER_EQUAL, $3);}
145 | Expression EXPOP_LESS_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_LESS_EQUAL, $3);}
146 | Expression EXPOP_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_EQUAL, $3);}
147 | Expression EXPOP_NOT_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_NOT_EQUAL, $3);}
148 | Expression EXPOP_AND Expression { $$ = DtDoOperator ($1, EXPOP_AND, $3);}
149 | Expression EXPOP_XOR Expression { $$ = DtDoOperator ($1, EXPOP_XOR, $3);}
150 | Expression EXPOP_OR Expression { $$ = DtDoOperator ($1, EXPOP_OR, $3);}
151 | Expression EXPOP_LOGICAL_AND Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_AND, $3);}
152 | Expression EXPOP_LOGICAL_OR Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_OR, $3);}
154 /* Parentheses: '(' Expression ')' */
156 | EXPOP_PAREN_OPEN Expression
157 EXPOP_PAREN_CLOSE { $$ = $2;}
159 /* Label references (prefixed with $) */
161 | EXPOP_LABEL { $$ = DtResolveLabel (DtParsertext);}
163 /* Default base for a non-prefixed integer is 16 */
165 | EXPOP_NUMBER { UtStrtoul64 (DtParsertext, 16, &$$);}
167 /* Standard hex number (0x1234) */
169 | EXPOP_HEX_NUMBER { UtStrtoul64 (DtParsertext, 16, &$$);}
171 /* TBD: Decimal number with prefix (0d1234) - Not supported by UtStrtoul64 at this time */
173 | EXPOP_DECIMAL_NUMBER { UtStrtoul64 (DtParsertext, 10, &$$);}
177 /*! [End] no source code translation !*/
180 * Local support functions, including parser entry point
182 #define PR_FIRST_PARSE_OPCODE EXPOP_EOF
183 #define PR_YYTNAME_START 3
186 /******************************************************************************
188 * FUNCTION: DtParsererror
190 * PARAMETERS: Message - Parser-generated error message
192 * RETURN: None
194 * DESCRIPTION: Handler for parser errors
196 *****************************************************************************/
198 void
199 DtParsererror (
200 char const *Message)
202 DtError (ASL_ERROR, ASL_MSG_SYNTAX,
203 Gbl_CurrentField, (char *) Message);
207 /******************************************************************************
209 * FUNCTION: DtGetOpName
211 * PARAMETERS: ParseOpcode - Parser token (EXPOP_*)
213 * RETURN: Pointer to the opcode name
215 * DESCRIPTION: Get the ascii name of the parse opcode for debug output
217 *****************************************************************************/
219 char *
220 DtGetOpName (
221 UINT32 ParseOpcode)
223 #ifdef ASL_YYTNAME_START
225 * First entries (PR_YYTNAME_START) in yytname are special reserved names.
226 * Ignore first 6 characters of name (EXPOP_)
228 return ((char *) yytname
229 [(ParseOpcode - PR_FIRST_PARSE_OPCODE) + PR_YYTNAME_START] + 6);
230 #else
231 return ("[Unknown parser generator]");
232 #endif
236 /******************************************************************************
238 * FUNCTION: DtEvaluateExpression
240 * PARAMETERS: ExprString - Expression to be evaluated. Must be
241 * terminated by either a newline or a NUL
242 * string terminator
244 * RETURN: 64-bit value for the expression
246 * DESCRIPTION: Main entry point for the DT expression parser
248 *****************************************************************************/
250 UINT64
251 DtEvaluateExpression (
252 char *ExprString)
255 DbgPrint (ASL_DEBUG_OUTPUT,
256 "**** Input expression: %s (Base 16)\n", ExprString);
258 /* Point lexer to the input string */
260 if (DtInitLexer (ExprString))
262 DtError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL,
263 Gbl_CurrentField, "Could not initialize lexer");
264 return (0);
267 /* Parse/Evaluate the input string (value returned in DtParserResult) */
269 DtParserparse ();
270 DtTerminateLexer ();
272 DbgPrint (ASL_DEBUG_OUTPUT,
273 "**** Parser returned value: %u (%8.8X%8.8X)\n",
274 (UINT32) DtParserResult, ACPI_FORMAT_UINT64 (DtParserResult));
276 return (DtParserResult);