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