blob: ade5dea65d34331b7ab8fd48681bf455364f584d [file] [log] [blame]
David Gibsonfc14dad2005-06-08 17:18:34 +10001/*
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
24int yylex (void);
25void yyerror (char const *);
26
27extern 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 Gibson4102d842005-06-16 14:36:37 +100050%token <str> DT_LABEL
David Gibson81f2e892005-06-16 17:04:00 +100051%token <str> DT_REF
David Gibsonfc14dad2005-06-08 17:18:34 +100052
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 Gibson4102d842005-06-16 14:36:37 +100062%type <str> label
63%type <str> nodename
64
65%glr-parser
David Gibsonfc14dad2005-06-08 17:18:34 +100066
67%%
68
69devicetree: {
70 assert(device_tree == NULL);
David Gibson4102d842005-06-16 14:36:37 +100071 } '/' nodedef { device_tree = name_node($3, "", NULL); }
David Gibsonfc14dad2005-06-08 17:18:34 +100072 ;
73
74nodedef: '{' proplist subnodes '}' ';' {
75 $$ = build_node($2, $3);
76 }
77 ;
78
79proplist: propdef proplist {
80 $$ = chain_property($1, $2);
81 }
82 | /* empty */ {
83 $$ = NULL;
84 }
85 ;
86
David Gibson4102d842005-06-16 14:36:37 +100087propdef: label DT_PROPNAME '=' propdata ';' {
88 $$ = build_property($2, $4, $1);
David Gibsonfc14dad2005-06-08 17:18:34 +100089 }
David Gibson4102d842005-06-16 14:36:37 +100090 | label DT_PROPNAME ';' {
91 $$ = build_empty_property($2, $1);
David Gibsonfc14dad2005-06-08 17:18:34 +100092 }
93 ;
94
95propdata: DT_STRING { $$ = $1; }
96 | '<' celllist '>' { $$ = $2; }
97 | '[' bytestring ']' { $$ = $2; }
98 ;
99
100celllist: celllist DT_CELL { $$ = data_append_cell($1, $2); }
David Gibson81f2e892005-06-16 17:04:00 +1000101 | celllist DT_REF {
102 $$ = data_append_cell(data_add_fixup($1, $2), -1);
103 }
David Gibsonfc14dad2005-06-08 17:18:34 +1000104 | /* empty */ { $$ = empty_data; }
105 ;
106
107bytestring: bytestring DT_BYTE { $$ = data_append_byte($1, $2); }
108 | /* empty */ { $$ = empty_data; }
109 ;
110
111subnodes: subnode subnodes {
112 $$ = chain_node($1, $2);
113 }
114 | /* empty */ { $$ = NULL; }
115 ;
116
David Gibson4102d842005-06-16 14:36:37 +1000117subnode: label nodename nodedef { $$ = name_node($3, $2, $1); }
118 ;
119
120nodename: DT_NODENAME { $$ = $1; }
121 | DT_PROPNAME { $$ = $1; }
122 ;
123
124label: DT_LABEL { $$ = $1; }
125 | /* empty */ { $$ = NULL; }
David Gibsonfc14dad2005-06-08 17:18:34 +1000126 ;
127
128%%
129
130void yyerror (char const *s)
131{
132 fprintf (stderr, "%s\n", s);
133}