2N/A%{
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A *
2N/A * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/* This is the yacc grammar for the libfru NamingSyntax */
2N/A#include <assert.h>
2N/A#include <stdio.h>
2N/A
2N/A#include "Parser.h"
2N/A
2N/A//#define YYDEBUG 1
2N/A
2N/A// Parser Globals.
2N/Aextern fru_errno_t gParserErrno;
2N/Aextern char *gParserString;
2N/Aextern Ancestor *gParserAnts;
2N/Aextern PathDef *gParserHead;
2N/Aextern int *gParserAbs;
2N/A
2N/Aextern void yyerror (const char *msg);
2N/Aextern int yylex (void);
2N/A
2N/A%}
2N/A
2N/A%union {
2N/A int num;
2N/A char *name;
2N/A PathDef *pathDef;
2N/A}
2N/A
2N/A%token SEPIDENT ITERBEGIN ITEREND
2N/A%token LAST ADD
2N/A%token <num> NUMBER
2N/A%token <name> NAME
2N/A
2N/A%type <pathDef> recordpath element
2N/A%type <num> itercount
2N/A
2N/A%left SEPIDENT
2N/A
2N/A%%
2N/Afullpath : recordpath
2N/A {
2N/A gParserHead = $1;
2N/A gParserAnts
2N/A = Ancestor::listTaggedAncestors((char *)$1->def->name);
2N/A }
2N/A ;
2N/A
2N/Arecordpath : element
2N/A {
2N/A $$ = $1;
2N/A }
2N/A | element SEPIDENT recordpath
2N/A {
2N/A if ($1->def->dataType != FDTYPE_Record)
2N/A {
2N/A yyerror (NULL);
2N/A YYABORT;
2N/A }
2N/A int found = 0;
2N/A for ( int i=0;i<$1->def->enumCount;i++)
2N/A {
2N/A if ( strcmp ($3->def->name, $1->def->enumTable[i].text) == 0 )
2N/A found = 1;
2N/A }
2N/A if ( !found )
2N/A {
2N/A yyerror (NULL);
2N/A YYABORT;
2N/A }
2N/A // insert it in the list.
2N/A $1->next = $3;
2N/A // return the head of the list.
2N/A $$ = $1;
2N/A }
2N/A | SEPIDENT recordpath
2N/A {
2N/A // absolute path definitions MUST start with tagged elements.
2N/A if ( $2->def->tagType == FRU_X )
2N/A {
2N/A yyerror ("First Element of absolute path MUST be tagged");
2N/A YYABORT;
2N/A }
2N/A *gParserAbs = 1;
2N/A $$ = $2;
2N/A }
2N/A ;
2N/A
2N/Aelement : NAME
2N/A {
2N/A const fru_regdef_t *def = fru_reg_lookup_def_by_name($1);
2N/A if ( def == NULL )
2N/A {
2N/A yyerror (NULL);
2N/A gParserErrno = FRU_NOREGDEF;
2N/A free ($1); // the lexer allocates this memory.
2N/A YYABORT;
2N/A }
2N/A PathDef *pathDef = new PathDef;
2N/A pathDef->def = (fru_regdef_t *)def;
2N/A pathDef->iterIndex = 0;
2N/A pathDef->next = NULL;
2N/A free ($1); // the lexer allocates this memory.
2N/A $$ = pathDef;
2N/A }
2N/A | NAME ITERBEGIN itercount ITEREND
2N/A {
2N/A const fru_regdef_t *def = fru_reg_lookup_def_by_name($1);
2N/A if ( def == NULL )
2N/A {
2N/A yyerror (NULL);
2N/A gParserErrno = FRU_NOREGDEF;
2N/A free ($1); // the lexer allocates this memory.
2N/A YYABORT;
2N/A }
2N/A if ( def->iterationType == FRU_NOT_ITERATED )
2N/A {
2N/A yyerror (NULL);
2N/A free ($1); // the lexer allocates this memory.
2N/A YYABORT;
2N/A }
2N/A if ( ($3 != PathDef::lastIteration) &&
2N/A ($3 != PathDef::addIteration) )
2N/A {
2N/A if ( ($3 >= def->iterationCount) || ($3 < 0) )
2N/A {
2N/A yyerror (NULL);
2N/A free ($1); // the lexer allocates this memory.
2N/A YYABORT;
2N/A }
2N/A }
2N/A PathDef *pathDef = new PathDef;
2N/A pathDef->def = (fru_regdef_t *)def;
2N/A pathDef->iterIndex = $3;
2N/A pathDef->next = NULL;
2N/A free ($1); // the lexer allocates this memory.
2N/A $$ = pathDef;
2N/A }
2N/A ;
2N/A
2N/Aitercount : NUMBER
2N/A { $$ = $1; }
2N/A | LAST
2N/A { $$ = PathDef::lastIteration; }
2N/A | ADD
2N/A { $$ = PathDef::addIteration; }
2N/A ;
2N/A
2N/A%%
2N/A
2N/Avoid
2N/Ayyerror (const char *msg)
2N/A{
2N/A gParserErrno = FRU_INVALPATH;
2N/A}
2N/A
2N/A// just to override what the library should have done.
2N/Aint yywrap (void) { return 1; }
2N/A