lib: remove unused libnvfru
[unleashed.git] / usr / src / lib / libfru / libfru / nameSyntaxYacc.y
blob34c5aa7ae0f4186b8596c701b848f02b2eb8c7d1
1 %{
2 /*
3 * CDDL HEADER START
5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License, Version 1.0 only
7 * (the "License"). You may not use this file except in compliance
8 * with the License.
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * CDDL HEADER END
23 * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 /* This is the yacc grammar for the libfru NamingSyntax */
30 #include <assert.h>
31 #include <stdio.h>
33 #include "Parser.h"
35 //#define YYDEBUG 1
37 // Parser Globals.
38 extern fru_errno_t gParserErrno;
39 extern char *gParserString;
40 extern Ancestor *gParserAnts;
41 extern PathDef *gParserHead;
42 extern int *gParserAbs;
44 extern void yyerror (const char *msg);
45 extern int yylex (void);
49 %union {
50 int num;
51 char *name;
52 PathDef *pathDef;
55 %token SEPIDENT ITERBEGIN ITEREND
56 %token LAST ADD
57 %token <num> NUMBER
58 %token <name> NAME
60 %type <pathDef> recordpath element
61 %type <num> itercount
63 %left SEPIDENT
66 fullpath : recordpath
68 gParserHead = $1;
69 gParserAnts
70 = Ancestor::listTaggedAncestors((char *)$1->def->name);
74 recordpath : element
76 $$ = $1;
78 | element SEPIDENT recordpath
80 if ($1->def->dataType != FDTYPE_Record)
82 yyerror (NULL);
83 YYABORT;
85 int found = 0;
86 for ( int i=0;i<$1->def->enumCount;i++)
88 if ( strcmp ($3->def->name, $1->def->enumTable[i].text) == 0 )
89 found = 1;
91 if ( !found )
93 yyerror (NULL);
94 YYABORT;
96 // insert it in the list.
97 $1->next = $3;
98 // return the head of the list.
99 $$ = $1;
101 | SEPIDENT recordpath
103 // absolute path definitions MUST start with tagged elements.
104 if ( $2->def->tagType == FRU_X )
106 yyerror ("First Element of absolute path MUST be tagged");
107 YYABORT;
109 *gParserAbs = 1;
110 $$ = $2;
114 element : NAME
116 const fru_regdef_t *def = fru_reg_lookup_def_by_name($1);
117 if ( def == NULL )
119 yyerror (NULL);
120 gParserErrno = FRU_NOREGDEF;
121 free ($1); // the lexer allocates this memory.
122 YYABORT;
124 PathDef *pathDef = new PathDef;
125 pathDef->def = (fru_regdef_t *)def;
126 pathDef->iterIndex = 0;
127 pathDef->next = NULL;
128 free ($1); // the lexer allocates this memory.
129 $$ = pathDef;
131 | NAME ITERBEGIN itercount ITEREND
133 const fru_regdef_t *def = fru_reg_lookup_def_by_name($1);
134 if ( def == NULL )
136 yyerror (NULL);
137 gParserErrno = FRU_NOREGDEF;
138 free ($1); // the lexer allocates this memory.
139 YYABORT;
141 if ( def->iterationType == FRU_NOT_ITERATED )
143 yyerror (NULL);
144 free ($1); // the lexer allocates this memory.
145 YYABORT;
147 if ( ($3 != PathDef::lastIteration) &&
148 ($3 != PathDef::addIteration) )
150 if ( ($3 >= def->iterationCount) || ($3 < 0) )
152 yyerror (NULL);
153 free ($1); // the lexer allocates this memory.
154 YYABORT;
157 PathDef *pathDef = new PathDef;
158 pathDef->def = (fru_regdef_t *)def;
159 pathDef->iterIndex = $3;
160 pathDef->next = NULL;
161 free ($1); // the lexer allocates this memory.
162 $$ = pathDef;
166 itercount : NUMBER
167 { $$ = $1; }
168 | LAST
169 { $$ = PathDef::lastIteration; }
170 | ADD
171 { $$ = PathDef::addIteration; }
176 void
177 yyerror (const char *msg)
179 gParserErrno = FRU_INVALPATH;
182 // just to override what the library should have done.
183 int yywrap (void) { return 1; }