Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pli / src / SS_ConfigParser.y
%{
#include <stdio.h>
#include "SS_ConfigObject.h"
SS_ConfigObjectList* config_objects;
%}
%union {
SS_ConfigValue* val;
SS_ConfigFieldList* lst;
SS_ConfigObject* obj;
SS_ConfigObjectList* objlst;
}
%token TOKEN_OBJECT
%token TOKEN_TYPE
%token TOKEN_VAR
%token TOKEN_SYM
%token TOKEN_NUM
%token TOKEN_STR
%%
main : object_star
{
config_objects = $$.objlst;
}
object_star : object_plus
{
$$ = $1;
}
| /* empty */
{
$$.objlst = new SS_ConfigObjectList();
}
;
object_plus : object_plus object
{
$$ = $1;
$$.objlst->object[$2.obj->name] = $2.obj;
}
| object
{
$$.objlst = new SS_ConfigObjectList();
$$.objlst->object[$1.obj->name] = $1.obj;
}
;
object : TOKEN_OBJECT TOKEN_VAR TOKEN_TYPE TOKEN_VAR '{' property_star '}'
{
$$.obj = new SS_ConfigObject($2.val->var()->value,$4.val->var()->value,$6.lst);
}
;
property_star : property_plus
{
$$ = $1;
}
| /* empty */
{
$$.lst = new SS_ConfigFieldList();
}
;
property_plus : property_plus TOKEN_VAR ':' constant
{
$$ = $1;
$$.lst->field[$2.val->var()->value] = $4.val;
delete $2.val;
}
| TOKEN_VAR ':' constant
{
$$.lst = new SS_ConfigFieldList();
$$.lst->field[$1.val->var()->value] = $3.val;
delete $1.val;
}
;
constant : TOKEN_SYM
{
$$ = $1;
}
| TOKEN_VAR
{
$$ = $1;
}
| TOKEN_NUM
{
$$ = $1;
}
| TOKEN_STR
{
$$ = $1;
}
| '(' constant_star ')'
{
$$ = $2;
}
;
constant_star : constant_plus
{
$$ = $1;
}
| /* empty */
{
$$.val = new SS_ConfigValueList();
}
;
constant_plus : constant_plus ',' constant
{
$$ = $1;
$$.val->lst()->value.push_back($3.val);
}
| constant
{
$$.val = new SS_ConfigValueList();
$$.val->lst()->value.push_back($1.val);
}
;
%%
void yyerror( const char *msg )
{
fprintf(stderr,"ConfigParser: %s\n",msg);
}