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