1 /* $NetBSD: config_yacc.y,v 1.3 2003/08/06 22:11:49 jmmv Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name authors may not be used to endorse or promote products
16 * derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
37 __RCSID
("$NetBSD: config_yacc.y,v 1.3 2003/08/06 22:11:49 jmmv Exp $");
41 #include <dev/wscons/wsconsio.h>
53 int yyerror(const char *, ...
);
54 void yyrestart
(FILE *);
55 struct block
*config_parse
(FILE *);
58 static struct block
*Conf
;
63 %token TK_EQUAL TK_LBRACE TK_RBRACE
64 %token TK_STRING TK_MODE TK_MODEPROP
65 %type
<string> TK_STRING TK_MODEPROP
67 %type
<block
> main outermode mode
78 Conf
->b_name
= strdup
("global"); }
81 /* Matches the whole configuration file and constructs a block defining it.
82 Can contain mode properties (common to all modes) and mode definitions. */
84 modeprop
{ struct block
*b
= block_new
(BLOCK_GLOBAL
);
85 block_add_prop
(b
, $1);
87 | main modeprop
{ block_add_prop
($1, $2); }
88 | outermode
{ struct block
*b
= block_new
(BLOCK_GLOBAL
);
89 block_add_child
(b
, $1);
91 | main outermode
{ block_add_child
($1, $2); }
92 |
error TK_EOL
{ yyerrok; }
95 /* Defines the aspect of a mode definition. Returns the block given by the
96 mode definition itself. */
98 TK_MODE TK_STRING TK_LBRACE mode TK_RBRACE
99 { $4->b_name
= strdup
($2);
101 | TK_MODE TK_STRING TK_LBRACE TK_RBRACE
102 { $$
= block_new
(BLOCK_MODE
);
103 $$
->b_name
= strdup
($2); }
106 /* Matches a mode and returns a block defining it. Contains properties */
108 modeprop
{ struct block
*b
= block_new
(BLOCK_MODE
);
109 block_add_prop
(b
, $1);
111 | mode modeprop
{ block_add_prop
($1, $2); }
112 |
error TK_EOL
{ yyerrok; }
115 /* Matches a mode property and returns a prop defining it. */
117 TK_MODEPROP TK_EQUAL TK_STRING TK_EOL
118 { struct prop
*p
= prop_new
();
119 p
->p_name
= strdup
($1);
120 p
->p_value
= strdup
($3);
127 yyerror(const char *fmt
, ...
)
132 fprintf
(stderr
, "%s: ", getprogname
());
133 vfprintf
(stderr
, fmt
, ap
);
134 fprintf
(stderr
, " in line %d\n", yyline
);
140 config_parse
(FILE *f
)