1 // SPDX-License-Identifier: GPL-2.0-or-later << 2 /* 1 /* 3 * (C) Copyright David Gibson <dwg@au1.ibm.com> 2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. >> 3 * >> 4 * >> 5 * This program is free software; you can redistribute it and/or >> 6 * modify it under the terms of the GNU General Public License as >> 7 * published by the Free Software Foundation; either version 2 of the >> 8 * License, or (at your option) any later version. >> 9 * >> 10 * This program is distributed in the hope that it will be useful, >> 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of >> 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> 13 * General Public License for more details. >> 14 * >> 15 * You should have received a copy of the GNU General Public License >> 16 * along with this program; if not, write to the Free Software >> 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 >> 18 * USA 4 */ 19 */ 5 %locations << 6 << 7 %{ 20 %{ 8 #include <stdio.h> 21 #include <stdio.h> 9 #include <inttypes.h> 22 #include <inttypes.h> 10 23 11 #include "dtc.h" 24 #include "dtc.h" 12 #include "srcpos.h" 25 #include "srcpos.h" 13 26 14 extern int yylex(void); 27 extern int yylex(void); 15 extern void yyerror(char const *s); 28 extern void yyerror(char const *s); 16 #define ERROR(loc, ...) \ 29 #define ERROR(loc, ...) \ 17 do { \ 30 do { \ 18 srcpos_error((loc), "Error", _ 31 srcpos_error((loc), "Error", __VA_ARGS__); \ 19 treesource_error = true; \ 32 treesource_error = true; \ 20 } while (0) 33 } while (0) 21 34 22 #define YYERROR_CALL(msg) yyerror(msg) << 23 << 24 extern struct dt_info *parser_output; 35 extern struct dt_info *parser_output; 25 extern bool treesource_error; 36 extern bool treesource_error; 26 << 27 static bool is_ref_relative(const char *ref) << 28 { << 29 return ref[0] != '/' && strchr(&ref[1] << 30 } << 31 << 32 %} 37 %} 33 38 34 %union { 39 %union { 35 char *propnodename; 40 char *propnodename; 36 char *labelref; 41 char *labelref; 37 uint8_t byte; 42 uint8_t byte; 38 struct data data; 43 struct data data; 39 44 40 struct { 45 struct { 41 struct data data; 46 struct data data; 42 int bits; 47 int bits; 43 } array; 48 } array; 44 49 45 struct property *prop; 50 struct property *prop; 46 struct property *proplist; 51 struct property *proplist; 47 struct node *node; 52 struct node *node; 48 struct node *nodelist; 53 struct node *nodelist; 49 struct reserve_info *re; 54 struct reserve_info *re; 50 uint64_t integer; 55 uint64_t integer; 51 unsigned int flags; 56 unsigned int flags; 52 } 57 } 53 58 54 %token DT_V1 59 %token DT_V1 55 %token DT_PLUGIN 60 %token DT_PLUGIN 56 %token DT_MEMRESERVE 61 %token DT_MEMRESERVE 57 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ D 62 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR 58 %token DT_BITS 63 %token DT_BITS 59 %token DT_DEL_PROP 64 %token DT_DEL_PROP 60 %token DT_DEL_NODE 65 %token DT_DEL_NODE 61 %token DT_OMIT_NO_REF << 62 %token <propnodename> DT_PROPNODENAME 66 %token <propnodename> DT_PROPNODENAME 63 %token <integer> DT_LITERAL 67 %token <integer> DT_LITERAL 64 %token <integer> DT_CHAR_LITERAL 68 %token <integer> DT_CHAR_LITERAL 65 %token <byte> DT_BYTE 69 %token <byte> DT_BYTE 66 %token <data> DT_STRING 70 %token <data> DT_STRING 67 %token <labelref> DT_LABEL 71 %token <labelref> DT_LABEL 68 %token <labelref> DT_LABEL_REF !! 72 %token <labelref> DT_REF 69 %token <labelref> DT_PATH_REF << 70 %token DT_INCBIN 73 %token DT_INCBIN 71 74 72 %type <data> propdata 75 %type <data> propdata 73 %type <data> propdataprefix 76 %type <data> propdataprefix 74 %type <flags> header 77 %type <flags> header 75 %type <flags> headers 78 %type <flags> headers 76 %type <re> memreserve 79 %type <re> memreserve 77 %type <re> memreserves 80 %type <re> memreserves 78 %type <array> arrayprefix 81 %type <array> arrayprefix 79 %type <data> bytestring 82 %type <data> bytestring 80 %type <prop> propdef 83 %type <prop> propdef 81 %type <proplist> proplist 84 %type <proplist> proplist 82 %type <labelref> dt_ref << 83 85 84 %type <node> devicetree 86 %type <node> devicetree 85 %type <node> nodedef 87 %type <node> nodedef 86 %type <node> subnode 88 %type <node> subnode 87 %type <nodelist> subnodes 89 %type <nodelist> subnodes 88 90 89 %type <integer> integer_prim 91 %type <integer> integer_prim 90 %type <integer> integer_unary 92 %type <integer> integer_unary 91 %type <integer> integer_mul 93 %type <integer> integer_mul 92 %type <integer> integer_add 94 %type <integer> integer_add 93 %type <integer> integer_shift 95 %type <integer> integer_shift 94 %type <integer> integer_rela 96 %type <integer> integer_rela 95 %type <integer> integer_eq 97 %type <integer> integer_eq 96 %type <integer> integer_bitand 98 %type <integer> integer_bitand 97 %type <integer> integer_bitxor 99 %type <integer> integer_bitxor 98 %type <integer> integer_bitor 100 %type <integer> integer_bitor 99 %type <integer> integer_and 101 %type <integer> integer_and 100 %type <integer> integer_or 102 %type <integer> integer_or 101 %type <integer> integer_trinary 103 %type <integer> integer_trinary 102 %type <integer> integer_expr 104 %type <integer> integer_expr 103 105 104 %% 106 %% 105 107 106 sourcefile: 108 sourcefile: 107 headers memreserves devicetree 109 headers memreserves devicetree 108 { 110 { 109 parser_output = build_ 111 parser_output = build_dt_info($1, $2, $3, 110 112 guess_boot_cpuid($3)); 111 } 113 } 112 ; 114 ; 113 115 114 header: 116 header: 115 DT_V1 ';' 117 DT_V1 ';' 116 { 118 { 117 $$ = DTSF_V1; 119 $$ = DTSF_V1; 118 } 120 } 119 | DT_V1 ';' DT_PLUGIN ';' 121 | DT_V1 ';' DT_PLUGIN ';' 120 { 122 { 121 $$ = DTSF_V1 | DTSF_PL 123 $$ = DTSF_V1 | DTSF_PLUGIN; 122 } 124 } 123 ; 125 ; 124 126 125 headers: 127 headers: 126 header 128 header 127 | header headers 129 | header headers 128 { 130 { 129 if ($2 != $1) 131 if ($2 != $1) 130 ERROR(&@2, "He 132 ERROR(&@2, "Header flags don't match earlier ones"); 131 $$ = $1; 133 $$ = $1; 132 } 134 } 133 ; 135 ; 134 136 135 memreserves: 137 memreserves: 136 /* empty */ 138 /* empty */ 137 { 139 { 138 $$ = NULL; 140 $$ = NULL; 139 } 141 } 140 | memreserve memreserves 142 | memreserve memreserves 141 { 143 { 142 $$ = chain_reserve_ent 144 $$ = chain_reserve_entry($1, $2); 143 } 145 } 144 ; 146 ; 145 147 146 memreserve: 148 memreserve: 147 DT_MEMRESERVE integer_prim integer_p 149 DT_MEMRESERVE integer_prim integer_prim ';' 148 { 150 { 149 $$ = build_reserve_ent 151 $$ = build_reserve_entry($2, $3); 150 } 152 } 151 | DT_LABEL memreserve 153 | DT_LABEL memreserve 152 { 154 { 153 add_label(&$2->labels, 155 add_label(&$2->labels, $1); 154 $$ = $2; 156 $$ = $2; 155 } 157 } 156 ; 158 ; 157 159 158 dt_ref: DT_LABEL_REF | DT_PATH_REF; << 159 << 160 devicetree: 160 devicetree: 161 '/' nodedef 161 '/' nodedef 162 { 162 { 163 $$ = name_node($2, "") 163 $$ = name_node($2, ""); 164 } 164 } 165 | devicetree '/' nodedef 165 | devicetree '/' nodedef 166 { 166 { 167 $$ = merge_nodes($1, $ 167 $$ = merge_nodes($1, $3); 168 } 168 } 169 | dt_ref nodedef !! 169 170 { !! 170 | devicetree DT_LABEL DT_REF nodedef 171 /* << 172 * We rely on the rule << 173 * versioninfo plugi << 174 * so $-1 is what we w << 175 */ << 176 if (!($<flags>-1 & DTS << 177 ERROR(&@2, "La << 178 else if (is_ref_relati << 179 ERROR(&@2, "La << 180 $$ = add_orphan_node( << 181 name_n << 182 << 183 $2, $1 << 184 } << 185 | devicetree DT_LABEL dt_ref nodedef << 186 { 171 { 187 struct node *target = 172 struct node *target = get_node_by_ref($1, $3); 188 173 189 if (($<flags>-1 & DTSF << 190 ERROR(&@2, "La << 191 << 192 if (target) { 174 if (target) { 193 add_label(&tar 175 add_label(&target->labels, $2); 194 merge_nodes(ta 176 merge_nodes(target, $4); 195 } else 177 } else 196 ERROR(&@3, "La 178 ERROR(&@3, "Label or path %s not found", $3); 197 $$ = $1; 179 $$ = $1; 198 } 180 } 199 | devicetree DT_PATH_REF nodedef !! 181 | devicetree DT_REF nodedef 200 { << 201 /* << 202 * We rely on the rule << 203 * versioninfo plugi << 204 * so $-1 is what we w << 205 */ << 206 if ($<flags>-1 & DTSF_ << 207 if (is_ref_rel << 208 ERROR( << 209 add_orphan_nod << 210 } else { << 211 struct node *t << 212 << 213 if (target) << 214 merge_ << 215 else << 216 ERROR( << 217 } << 218 $$ = $1; << 219 } << 220 | devicetree DT_LABEL_REF nodedef << 221 { 182 { 222 struct node *target = 183 struct node *target = get_node_by_ref($1, $2); 223 184 224 if (target) { << 225 merge_nodes(ta << 226 } else { << 227 /* << 228 * We rely on << 229 * versionin << 230 * so $-1 is w << 231 */ << 232 if ($<flags>-1 << 233 add_or << 234 else << 235 ERROR( << 236 } << 237 $$ = $1; << 238 } << 239 | devicetree DT_DEL_NODE dt_ref ';' << 240 { << 241 struct node *target = << 242 << 243 if (target) 185 if (target) 244 delete_node(ta !! 186 merge_nodes(target, $3); 245 else 187 else 246 ERROR(&@3, "La !! 188 ERROR(&@2, "Label or path %s not found", $2); 247 << 248 << 249 $$ = $1; 189 $$ = $1; 250 } 190 } 251 | devicetree DT_OMIT_NO_REF dt_ref ';' !! 191 | devicetree DT_DEL_NODE DT_REF ';' 252 { 192 { 253 struct node *target = 193 struct node *target = get_node_by_ref($1, $3); 254 194 255 if (target) 195 if (target) 256 omit_node_if_u !! 196 delete_node(target); 257 else 197 else 258 ERROR(&@3, "La 198 ERROR(&@3, "Label or path %s not found", $3); 259 199 260 200 261 $$ = $1; 201 $$ = $1; 262 } 202 } 263 ; 203 ; 264 204 265 nodedef: 205 nodedef: 266 '{' proplist subnodes '}' ';' 206 '{' proplist subnodes '}' ';' 267 { 207 { 268 $$ = build_node($2, $3 !! 208 $$ = build_node($2, $3); 269 } 209 } 270 ; 210 ; 271 211 272 proplist: 212 proplist: 273 /* empty */ 213 /* empty */ 274 { 214 { 275 $$ = NULL; 215 $$ = NULL; 276 } 216 } 277 | proplist propdef 217 | proplist propdef 278 { 218 { 279 $$ = chain_property($2 219 $$ = chain_property($2, $1); 280 } 220 } 281 ; 221 ; 282 222 283 propdef: 223 propdef: 284 DT_PROPNODENAME '=' propdata ';' 224 DT_PROPNODENAME '=' propdata ';' 285 { 225 { 286 $$ = build_property($1 !! 226 $$ = build_property($1, $3); 287 free($1); << 288 } 227 } 289 | DT_PROPNODENAME ';' 228 | DT_PROPNODENAME ';' 290 { 229 { 291 $$ = build_property($1 !! 230 $$ = build_property($1, empty_data); 292 free($1); << 293 } 231 } 294 | DT_DEL_PROP DT_PROPNODENAME ';' 232 | DT_DEL_PROP DT_PROPNODENAME ';' 295 { 233 { 296 $$ = build_property_de 234 $$ = build_property_delete($2); 297 free($2); << 298 } 235 } 299 | DT_LABEL propdef 236 | DT_LABEL propdef 300 { 237 { 301 add_label(&$2->labels, 238 add_label(&$2->labels, $1); 302 $$ = $2; 239 $$ = $2; 303 } 240 } 304 ; 241 ; 305 242 306 propdata: 243 propdata: 307 propdataprefix DT_STRING 244 propdataprefix DT_STRING 308 { 245 { 309 $$ = data_merge($1, $2 246 $$ = data_merge($1, $2); 310 } 247 } 311 | propdataprefix arrayprefix '>' 248 | propdataprefix arrayprefix '>' 312 { 249 { 313 $$ = data_merge($1, $2 250 $$ = data_merge($1, $2.data); 314 } 251 } 315 | propdataprefix '[' bytestring ']' 252 | propdataprefix '[' bytestring ']' 316 { 253 { 317 $$ = data_merge($1, $3 254 $$ = data_merge($1, $3); 318 } 255 } 319 | propdataprefix dt_ref !! 256 | propdataprefix DT_REF 320 { 257 { 321 $1 = data_add_marker($ << 322 $$ = data_add_marker($ 258 $$ = data_add_marker($1, REF_PATH, $2); 323 } 259 } 324 | propdataprefix DT_INCBIN '(' DT_STRI 260 | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' 325 { 261 { 326 FILE *f = srcfile_rela 262 FILE *f = srcfile_relative_open($4.val, NULL); 327 struct data d; 263 struct data d; 328 264 329 if ($6 != 0) 265 if ($6 != 0) 330 if (fseek(f, $ 266 if (fseek(f, $6, SEEK_SET) != 0) 331 die("C 267 die("Couldn't seek to offset %llu in \"%s\": %s", 332 (u 268 (unsigned long long)$6, $4.val, 333 st 269 strerror(errno)); 334 270 335 d = data_copy_file(f, 271 d = data_copy_file(f, $8); 336 272 337 $$ = data_merge($1, d) 273 $$ = data_merge($1, d); 338 fclose(f); 274 fclose(f); 339 } 275 } 340 | propdataprefix DT_INCBIN '(' DT_STRI 276 | propdataprefix DT_INCBIN '(' DT_STRING ')' 341 { 277 { 342 FILE *f = srcfile_rela 278 FILE *f = srcfile_relative_open($4.val, NULL); 343 struct data d = empty_ 279 struct data d = empty_data; 344 280 345 d = data_copy_file(f, 281 d = data_copy_file(f, -1); 346 282 347 $$ = data_merge($1, d) 283 $$ = data_merge($1, d); 348 fclose(f); 284 fclose(f); 349 } 285 } 350 | propdata DT_LABEL 286 | propdata DT_LABEL 351 { 287 { 352 $$ = data_add_marker($ 288 $$ = data_add_marker($1, LABEL, $2); 353 } 289 } 354 ; 290 ; 355 291 356 propdataprefix: 292 propdataprefix: 357 /* empty */ 293 /* empty */ 358 { 294 { 359 $$ = empty_data; 295 $$ = empty_data; 360 } 296 } 361 | propdata ',' 297 | propdata ',' 362 { 298 { 363 $$ = $1; 299 $$ = $1; 364 } 300 } 365 | propdataprefix DT_LABEL 301 | propdataprefix DT_LABEL 366 { 302 { 367 $$ = data_add_marker($ 303 $$ = data_add_marker($1, LABEL, $2); 368 } 304 } 369 ; 305 ; 370 306 371 arrayprefix: 307 arrayprefix: 372 DT_BITS DT_LITERAL '<' 308 DT_BITS DT_LITERAL '<' 373 { 309 { 374 unsigned long long bit 310 unsigned long long bits; 375 enum markertype type = << 376 311 377 bits = $2; 312 bits = $2; 378 313 379 switch (bits) { !! 314 if ((bits != 8) && (bits != 16) && 380 case 8: type = TYPE_UI !! 315 (bits != 32) && (bits != 64)) { 381 case 16: type = TYPE_U << 382 case 32: type = TYPE_U << 383 case 64: type = TYPE_U << 384 default: << 385 ERROR(&@2, "Ar 316 ERROR(&@2, "Array elements must be" 386 " 8, 16, 317 " 8, 16, 32 or 64-bits"); 387 bits = 32; 318 bits = 32; 388 } 319 } 389 320 390 $$.data = data_add_mar !! 321 $$.data = empty_data; 391 $$.bits = bits; 322 $$.bits = bits; 392 } 323 } 393 | '<' 324 | '<' 394 { 325 { 395 $$.data = data_add_mar !! 326 $$.data = empty_data; 396 $$.bits = 32; 327 $$.bits = 32; 397 } 328 } 398 | arrayprefix integer_prim 329 | arrayprefix integer_prim 399 { 330 { 400 if ($1.bits < 64) { 331 if ($1.bits < 64) { 401 uint64_t mask 332 uint64_t mask = (1ULL << $1.bits) - 1; 402 /* 333 /* 403 * Bits above 334 * Bits above mask must either be all zero 404 * (positive w 335 * (positive within range of mask) or all one 405 * (negative a 336 * (negative and sign-extended). The second 406 * condition i 337 * condition is true if when we set all bits 407 * within the 338 * within the mask to one (i.e. | in the 408 * mask), all 339 * mask), all bits are one. 409 */ 340 */ 410 if (($2 > mask !! 341 if (($2 > mask) && (($2 | mask) != -1ULL)) 411 char * !! 342 ERROR(&@2, "Value out of range for" 412 fprint !! 343 " %d-bit array element", $1.bits); 413 << 414 << 415 << 416 free(l << 417 } << 418 } 344 } 419 345 420 $$.data = data_append_ 346 $$.data = data_append_integer($1.data, $2, $1.bits); 421 } 347 } 422 | arrayprefix dt_ref !! 348 | arrayprefix DT_REF 423 { 349 { 424 uint64_t val = ~0ULL > 350 uint64_t val = ~0ULL >> (64 - $1.bits); 425 351 426 if ($1.bits == 32) 352 if ($1.bits == 32) 427 $1.data = data 353 $1.data = data_add_marker($1.data, 428 354 REF_PHANDLE, 429 355 $2); 430 else 356 else 431 ERROR(&@2, "Re 357 ERROR(&@2, "References are only allowed in " 432 "a 358 "arrays with 32-bit elements."); 433 359 434 $$.data = data_append_ 360 $$.data = data_append_integer($1.data, val, $1.bits); 435 } 361 } 436 | arrayprefix DT_LABEL 362 | arrayprefix DT_LABEL 437 { 363 { 438 $$.data = data_add_mar 364 $$.data = data_add_marker($1.data, LABEL, $2); 439 } 365 } 440 ; 366 ; 441 367 442 integer_prim: 368 integer_prim: 443 DT_LITERAL 369 DT_LITERAL 444 | DT_CHAR_LITERAL 370 | DT_CHAR_LITERAL 445 | '(' integer_expr ')' 371 | '(' integer_expr ')' 446 { 372 { 447 $$ = $2; 373 $$ = $2; 448 } 374 } 449 ; 375 ; 450 376 451 integer_expr: 377 integer_expr: 452 integer_trinary 378 integer_trinary 453 ; 379 ; 454 380 455 integer_trinary: 381 integer_trinary: 456 integer_or 382 integer_or 457 | integer_or '?' integer_expr ':' inte 383 | integer_or '?' integer_expr ':' integer_trinary { $$ = $1 ? $3 : $5; } 458 ; 384 ; 459 385 460 integer_or: 386 integer_or: 461 integer_and 387 integer_and 462 | integer_or DT_OR integer_and { $$ = 388 | integer_or DT_OR integer_and { $$ = $1 || $3; } 463 ; 389 ; 464 390 465 integer_and: 391 integer_and: 466 integer_bitor 392 integer_bitor 467 | integer_and DT_AND integer_bitor { $ 393 | integer_and DT_AND integer_bitor { $$ = $1 && $3; } 468 ; 394 ; 469 395 470 integer_bitor: 396 integer_bitor: 471 integer_bitxor 397 integer_bitxor 472 | integer_bitor '|' integer_bitxor { $ 398 | integer_bitor '|' integer_bitxor { $$ = $1 | $3; } 473 ; 399 ; 474 400 475 integer_bitxor: 401 integer_bitxor: 476 integer_bitand 402 integer_bitand 477 | integer_bitxor '^' integer_bitand { 403 | integer_bitxor '^' integer_bitand { $$ = $1 ^ $3; } 478 ; 404 ; 479 405 480 integer_bitand: 406 integer_bitand: 481 integer_eq 407 integer_eq 482 | integer_bitand '&' integer_eq { $$ = 408 | integer_bitand '&' integer_eq { $$ = $1 & $3; } 483 ; 409 ; 484 410 485 integer_eq: 411 integer_eq: 486 integer_rela 412 integer_rela 487 | integer_eq DT_EQ integer_rela { $$ = 413 | integer_eq DT_EQ integer_rela { $$ = $1 == $3; } 488 | integer_eq DT_NE integer_rela { $$ = 414 | integer_eq DT_NE integer_rela { $$ = $1 != $3; } 489 ; 415 ; 490 416 491 integer_rela: 417 integer_rela: 492 integer_shift 418 integer_shift 493 | integer_rela '<' integer_shift { $$ 419 | integer_rela '<' integer_shift { $$ = $1 < $3; } 494 | integer_rela '>' integer_shift { $$ 420 | integer_rela '>' integer_shift { $$ = $1 > $3; } 495 | integer_rela DT_LE integer_shift { $ 421 | integer_rela DT_LE integer_shift { $$ = $1 <= $3; } 496 | integer_rela DT_GE integer_shift { $ 422 | integer_rela DT_GE integer_shift { $$ = $1 >= $3; } 497 ; 423 ; 498 424 499 integer_shift: 425 integer_shift: 500 integer_shift DT_LSHIFT integer_add !! 426 integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } 501 | integer_shift DT_RSHIFT integer_add !! 427 | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } 502 | integer_add 428 | integer_add 503 ; 429 ; 504 430 505 integer_add: 431 integer_add: 506 integer_add '+' integer_mul { $$ = $ 432 integer_add '+' integer_mul { $$ = $1 + $3; } 507 | integer_add '-' integer_mul { $$ = $ 433 | integer_add '-' integer_mul { $$ = $1 - $3; } 508 | integer_mul 434 | integer_mul 509 ; 435 ; 510 436 511 integer_mul: 437 integer_mul: 512 integer_mul '*' integer_unary { $$ = 438 integer_mul '*' integer_unary { $$ = $1 * $3; } 513 | integer_mul '/' integer_unary 439 | integer_mul '/' integer_unary 514 { 440 { 515 if ($3 != 0) { 441 if ($3 != 0) { 516 $$ = $1 / $3; 442 $$ = $1 / $3; 517 } else { 443 } else { 518 ERROR(&@$, "Di 444 ERROR(&@$, "Division by zero"); 519 $$ = 0; 445 $$ = 0; 520 } 446 } 521 } 447 } 522 | integer_mul '%' integer_unary 448 | integer_mul '%' integer_unary 523 { 449 { 524 if ($3 != 0) { 450 if ($3 != 0) { 525 $$ = $1 % $3; 451 $$ = $1 % $3; 526 } else { 452 } else { 527 ERROR(&@$, "Di 453 ERROR(&@$, "Division by zero"); 528 $$ = 0; 454 $$ = 0; 529 } 455 } 530 } 456 } 531 | integer_unary 457 | integer_unary 532 ; 458 ; 533 459 534 integer_unary: 460 integer_unary: 535 integer_prim 461 integer_prim 536 | '-' integer_unary { $$ = -$2; } 462 | '-' integer_unary { $$ = -$2; } 537 | '~' integer_unary { $$ = ~$2; } 463 | '~' integer_unary { $$ = ~$2; } 538 | '!' integer_unary { $$ = !$2; } 464 | '!' integer_unary { $$ = !$2; } 539 ; 465 ; 540 466 541 bytestring: 467 bytestring: 542 /* empty */ 468 /* empty */ 543 { 469 { 544 $$ = data_add_marker(e !! 470 $$ = empty_data; 545 } 471 } 546 | bytestring DT_BYTE 472 | bytestring DT_BYTE 547 { 473 { 548 $$ = data_append_byte( 474 $$ = data_append_byte($1, $2); 549 } 475 } 550 | bytestring DT_LABEL 476 | bytestring DT_LABEL 551 { 477 { 552 $$ = data_add_marker($ 478 $$ = data_add_marker($1, LABEL, $2); 553 } 479 } 554 ; 480 ; 555 481 556 subnodes: 482 subnodes: 557 /* empty */ 483 /* empty */ 558 { 484 { 559 $$ = NULL; 485 $$ = NULL; 560 } 486 } 561 | subnode subnodes 487 | subnode subnodes 562 { 488 { 563 $$ = chain_node($1, $2 489 $$ = chain_node($1, $2); 564 } 490 } 565 | subnode propdef 491 | subnode propdef 566 { 492 { 567 ERROR(&@2, "Properties 493 ERROR(&@2, "Properties must precede subnodes"); 568 YYERROR; 494 YYERROR; 569 } 495 } 570 ; 496 ; 571 497 572 subnode: 498 subnode: 573 DT_PROPNODENAME nodedef 499 DT_PROPNODENAME nodedef 574 { 500 { 575 $$ = name_node($2, $1) 501 $$ = name_node($2, $1); 576 free($1); << 577 } 502 } 578 | DT_DEL_NODE DT_PROPNODENAME ';' 503 | DT_DEL_NODE DT_PROPNODENAME ';' 579 { 504 { 580 $$ = name_node(build_n !! 505 $$ = name_node(build_node_delete(), $2); 581 free($2); << 582 } << 583 | DT_OMIT_NO_REF subnode << 584 { << 585 $$ = omit_node_if_unus << 586 } 506 } 587 | DT_LABEL subnode 507 | DT_LABEL subnode 588 { 508 { 589 add_label(&$2->labels, 509 add_label(&$2->labels, $1); 590 $$ = $2; 510 $$ = $2; 591 } 511 } 592 ; 512 ; 593 513 594 %% 514 %% 595 515 596 void yyerror(char const *s) 516 void yyerror(char const *s) 597 { 517 { 598 ERROR(&yylloc, "%s", s); 518 ERROR(&yylloc, "%s", s); 599 } 519 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.