David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 1 | /* |
| 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 |
| 19 | */ |
| 20 | |
| 21 | %{ |
| 22 | #include "dtc.h" |
| 23 | |
| 24 | int yylex (void); |
| 25 | void yyerror (char const *); |
| 26 | |
| 27 | extern struct node *device_tree; |
| 28 | |
| 29 | %} |
| 30 | |
| 31 | %union { |
| 32 | cell_t cval; |
| 33 | uint8_t byte; |
| 34 | char *str; |
| 35 | struct data data; |
| 36 | struct property *prop; |
| 37 | struct property *proplist; |
| 38 | struct node *node; |
| 39 | struct node *nodelist; |
| 40 | int datalen; |
| 41 | int hexlen; |
| 42 | } |
| 43 | |
| 44 | %token <str> DT_PROPNAME |
| 45 | %token <str> DT_NODENAME |
| 46 | %token <cval> DT_CELL |
| 47 | %token <byte> DT_BYTE |
| 48 | %token <data> DT_STRING |
| 49 | %token <str> DT_UNIT |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 50 | %token <str> DT_LABEL |
David Gibson | 81f2e89 | 2005-06-16 17:04:00 +1000 | [diff] [blame^] | 51 | %token <str> DT_REF |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 52 | |
| 53 | %type <data> propdata |
| 54 | %type <data> celllist |
| 55 | %type <data> bytestring |
| 56 | %type <prop> propdef |
| 57 | %type <proplist> proplist |
| 58 | |
| 59 | %type <node> nodedef |
| 60 | %type <node> subnode |
| 61 | %type <nodelist> subnodes |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 62 | %type <str> label |
| 63 | %type <str> nodename |
| 64 | |
| 65 | %glr-parser |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 66 | |
| 67 | %% |
| 68 | |
| 69 | devicetree: { |
| 70 | assert(device_tree == NULL); |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 71 | } '/' nodedef { device_tree = name_node($3, "", NULL); } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 72 | ; |
| 73 | |
| 74 | nodedef: '{' proplist subnodes '}' ';' { |
| 75 | $$ = build_node($2, $3); |
| 76 | } |
| 77 | ; |
| 78 | |
| 79 | proplist: propdef proplist { |
| 80 | $$ = chain_property($1, $2); |
| 81 | } |
| 82 | | /* empty */ { |
| 83 | $$ = NULL; |
| 84 | } |
| 85 | ; |
| 86 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 87 | propdef: label DT_PROPNAME '=' propdata ';' { |
| 88 | $$ = build_property($2, $4, $1); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 89 | } |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 90 | | label DT_PROPNAME ';' { |
| 91 | $$ = build_empty_property($2, $1); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 92 | } |
| 93 | ; |
| 94 | |
| 95 | propdata: DT_STRING { $$ = $1; } |
| 96 | | '<' celllist '>' { $$ = $2; } |
| 97 | | '[' bytestring ']' { $$ = $2; } |
| 98 | ; |
| 99 | |
| 100 | celllist: celllist DT_CELL { $$ = data_append_cell($1, $2); } |
David Gibson | 81f2e89 | 2005-06-16 17:04:00 +1000 | [diff] [blame^] | 101 | | celllist DT_REF { |
| 102 | $$ = data_append_cell(data_add_fixup($1, $2), -1); |
| 103 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 104 | | /* empty */ { $$ = empty_data; } |
| 105 | ; |
| 106 | |
| 107 | bytestring: bytestring DT_BYTE { $$ = data_append_byte($1, $2); } |
| 108 | | /* empty */ { $$ = empty_data; } |
| 109 | ; |
| 110 | |
| 111 | subnodes: subnode subnodes { |
| 112 | $$ = chain_node($1, $2); |
| 113 | } |
| 114 | | /* empty */ { $$ = NULL; } |
| 115 | ; |
| 116 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 117 | subnode: label nodename nodedef { $$ = name_node($3, $2, $1); } |
| 118 | ; |
| 119 | |
| 120 | nodename: DT_NODENAME { $$ = $1; } |
| 121 | | DT_PROPNAME { $$ = $1; } |
| 122 | ; |
| 123 | |
| 124 | label: DT_LABEL { $$ = $1; } |
| 125 | | /* empty */ { $$ = NULL; } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 126 | ; |
| 127 | |
| 128 | %% |
| 129 | |
| 130 | void yyerror (char const *s) |
| 131 | { |
| 132 | fprintf (stderr, "%s\n", s); |
| 133 | } |