Sun Mar 11 02:56:25 2012 UTC ()
Write out the expression grammar for dependency constraints instead of
using precedence rules. Precedence rules (besides being a hack) often
lead to unexpected/unwanted behavior in corner cases.


(dholland)
diff -r1.29 -r1.30 src/usr.bin/config/gram.y

cvs diff -r1.29 -r1.30 src/usr.bin/config/gram.y (expand / switch to unified diff)

--- src/usr.bin/config/gram.y 2012/03/11 02:43:33 1.29
+++ src/usr.bin/config/gram.y 2012/03/11 02:56:25 1.30
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: gram.y,v 1.29 2012/03/11 02:43:33 dholland Exp $ */ 2/* $NetBSD: gram.y,v 1.30 2012/03/11 02:56:25 dholland Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1992, 1993 5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This software was developed by the Computer Systems Engineering group 8 * This software was developed by the Computer Systems Engineering group
9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 * contributed to Berkeley. 10 * contributed to Berkeley.
11 * 11 *
12 * All advertising materials mentioning features or use of this software 12 * All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement: 13 * must display the following acknowledgement:
14 * This product includes software developed by the University of 14 * This product includes software developed by the University of
15 * California, Lawrence Berkeley Laboratories. 15 * California, Lawrence Berkeley Laboratories.
@@ -113,30 +113,28 @@ static struct nvlist *mk_ns(const char * @@ -113,30 +113,28 @@ static struct nvlist *mk_ns(const char *
113%token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR 113%token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
114%token NEEDS_COUNT NEEDS_FLAG NO 114%token NEEDS_COUNT NEEDS_FLAG NO
115%token XOBJECT OBSOLETE ON OPTIONS 115%token XOBJECT OBSOLETE ON OPTIONS
116%token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE PSEUDO_ROOT 116%token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE PSEUDO_ROOT
117%token ROOT 117%token ROOT
118%token SINGLE SOURCE 118%token SINGLE SOURCE
119%token TYPE 119%token TYPE
120%token VECTOR VERSION 120%token VECTOR VERSION
121%token WITH 121%token WITH
122%token <num> NUMBER 122%token <num> NUMBER
123%token <str> PATHNAME QSTRING WORD EMPTYSTRING 123%token <str> PATHNAME QSTRING WORD EMPTYSTRING
124%token ENDDEFS 124%token ENDDEFS
125 125
126%left '|' 
127%left '&' 
128 
129%type <list> fopts fexpr fatom 126%type <list> fopts fexpr fatom
 127%type <list> f_or_expr f_and_expr f_prefix_expr f_base_expr
130%type <str> fs_spec 128%type <str> fs_spec
131%type <val> fflgs fflag oflgs oflag 129%type <val> fflgs fflag oflgs oflag
132%type <str> rule 130%type <str> rule
133%type <attr> attr 131%type <attr> attr
134%type <devb> devbase 132%type <devb> devbase
135%type <deva> devattach_opt 133%type <deva> devattach_opt
136%type <list> atlist interface_opt 134%type <list> atlist interface_opt
137%type <str> atname 135%type <str> atname
138%type <list> loclist locdef 136%type <list> loclist locdef
139%type <str> locdefault 137%type <str> locdefault
140%type <list> values locdefaults 138%type <list> values locdefaults
141%type <list> attrs_opt attrs 139%type <list> attrs_opt attrs
142%type <list> locators locator 140%type <list> locators locator
@@ -745,32 +743,49 @@ device_flags: @@ -745,32 +743,49 @@ device_flags:
745 743
746/* 744/*
747 * dependency logic 745 * dependency logic
748 */ 746 */
749 747
750 748
751/* 749/*
752 * order of options is important, must use right recursion 750 * order of options is important, must use right recursion
753 * 751 *
754 * dholland 20120310: wut? 752 * dholland 20120310: wut?
755 */ 753 */
756 754
757/* expression of config elements */ 755/* expression of config elements */
758/* XXX this should use a real expression grammar */ 
759fexpr: 756fexpr:
 757 f_or_expr
 758;
 759
 760f_or_expr:
 761 f_and_expr
 762 | f_or_expr '|' f_and_expr { $$ = fx_or($1, $3); }
 763;
 764
 765f_and_expr:
 766 f_prefix_expr
 767 | f_and_expr '&' f_prefix_expr { $$ = fx_and($1, $3); }
 768;
 769
 770f_prefix_expr:
 771 f_base_expr
 772/* XXX notyet - need to strengthen downstream first */
 773/* | '!' f_prefix_expr { $$ = fx_not($2); } */
 774;
 775
 776f_base_expr:
760 fatom { $$ = $1; } 777 fatom { $$ = $1; }
761 | '!' fatom { $$ = fx_not($2); } 778 | '!' fatom { $$ = fx_not($2); }
762 | fexpr '&' fexpr { $$ = fx_and($1, $3); } 
763 | fexpr '|' fexpr { $$ = fx_or($1, $3); } 
764 | '(' fexpr ')' { $$ = $2; } 779 | '(' fexpr ')' { $$ = $2; }
765; 780;
766 781
767/* basic element of config element expression: a config element */ 782/* basic element of config element expression: a config element */
768fatom: 783fatom:
769 WORD { $$ = fx_atom($1); } 784 WORD { $$ = fx_atom($1); }
770; 785;
771 786
772/************************************************************/ 787/************************************************************/
773 788
774/* 789/*
775 * Various nonterminals shared between the grammars. 790 * Various nonterminals shared between the grammars.
776 */ 791 */