Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pli / src / SS_ConfigParser.y
CommitLineData
920dae64
AT
1%{
2#include <stdio.h>
3#include "SS_ConfigObject.h"
4
5SS_ConfigObjectList* config_objects;
6
7%}
8
9%union {
10 SS_ConfigValue* val;
11 SS_ConfigFieldList* lst;
12 SS_ConfigObject* obj;
13 SS_ConfigObjectList* objlst;
14}
15
16%token TOKEN_OBJECT
17%token TOKEN_TYPE
18%token TOKEN_VAR
19%token TOKEN_SYM
20%token TOKEN_NUM
21%token TOKEN_STR
22
23%%
24
25main : object_star
26{
27 config_objects = $$.objlst;
28}
29
30object_star : object_plus
31{
32 $$ = $1;
33}
34| /* empty */
35{
36 $$.objlst = new SS_ConfigObjectList();
37}
38;
39
40object_plus : object_plus object
41{
42 $$ = $1;
43 $$.objlst->object[$2.obj->name] = $2.obj;
44}
45| object
46{
47 $$.objlst = new SS_ConfigObjectList();
48 $$.objlst->object[$1.obj->name] = $1.obj;
49}
50;
51
52object : TOKEN_OBJECT TOKEN_VAR TOKEN_TYPE TOKEN_VAR '{' property_star '}'
53{
54 $$.obj = new SS_ConfigObject($2.val->var()->value,$4.val->var()->value,$6.lst);
55}
56;
57
58property_star : property_plus
59{
60 $$ = $1;
61}
62| /* empty */
63{
64 $$.lst = new SS_ConfigFieldList();
65}
66;
67
68property_plus : property_plus TOKEN_VAR ':' constant
69{
70 $$ = $1;
71 $$.lst->field[$2.val->var()->value] = $4.val;
72 delete $2.val;
73}
74| TOKEN_VAR ':' constant
75{
76 $$.lst = new SS_ConfigFieldList();
77 $$.lst->field[$1.val->var()->value] = $3.val;
78 delete $1.val;
79}
80;
81
82constant : TOKEN_SYM
83{
84 $$ = $1;
85}
86| TOKEN_VAR
87{
88 $$ = $1;
89}
90| TOKEN_NUM
91{
92 $$ = $1;
93}
94| TOKEN_STR
95{
96 $$ = $1;
97}
98| '(' constant_star ')'
99{
100 $$ = $2;
101}
102;
103
104constant_star : constant_plus
105{
106 $$ = $1;
107}
108| /* empty */
109{
110 $$.val = new SS_ConfigValueList();
111}
112;
113
114constant_plus : constant_plus ',' constant
115{
116 $$ = $1;
117 $$.val->lst()->value.push_back($3.val);
118}
119| constant
120{
121 $$.val = new SS_ConfigValueList();
122 $$.val->lst()->value.push_back($1.val);
123}
124;
125
126%%
127
128void yyerror( const char *msg )
129{
130 fprintf(stderr,"ConfigParser: %s\n",msg);
131}
132
133