Initial commit of vpp code.
[vpp.git] / vppapigen / gram.y
1 %{
2 /*
3  * gram.y - message definition language
4  *
5  * Copyright (c) 2009 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 extern void yyerror (char *s);
20 extern int yylex (void);
21     
22 #define YYSTYPE void *
23     
24 void generate (YYSTYPE);
25  YYSTYPE add_slist(YYSTYPE, YYSTYPE);
26  YYSTYPE add_define(YYSTYPE, YYSTYPE);
27  YYSTYPE suppress_version(void);
28  YYSTYPE add_defbody(YYSTYPE, YYSTYPE);
29  YYSTYPE add_primtype(YYSTYPE, YYSTYPE, YYSTYPE);
30  YYSTYPE add_complex(YYSTYPE, YYSTYPE);
31  YYSTYPE add_union(YYSTYPE, YYSTYPE);
32  YYSTYPE add_scalar_vbl(YYSTYPE);
33  YYSTYPE add_vector_vbl(YYSTYPE, YYSTYPE);
34  YYSTYPE set_flags(YYSTYPE, YYSTYPE);
35 %}
36
37 %token NAME RPAR LPAR SEMI LBRACK RBRACK NUMBER PRIMTYPE BARF
38 %token TPACKED DEFINE LCURLY RCURLY STRING UNION
39 %token HELPER_STRING COMMA 
40 %token NOVERSION MANUAL_PRINT MANUAL_ENDIAN MANUAL_JAVA TYPEONLY DONT_TRACE
41
42 %%
43
44 pgm:      slist                 {generate ($1);}
45           ;
46
47 slist:    slist stmt            {$$ = add_slist ($1, $2);}
48         | stmt                  {$$ = $1;}
49           ;
50
51 stmt:     flist defn            {$$ = set_flags($1, $2);}
52         | defn                  {$$ = $1;}
53           ;
54
55 flist:    flist flag            {$$ = (YYSTYPE)(unsigned long long)
56                                      ((unsigned long long) $1 
57                                     | (unsigned long long) $2);}
58         | flag                  {$$ = $1;}
59           ;
60
61 flag:   
62           MANUAL_PRINT          {$$ = $1;}
63         | MANUAL_ENDIAN         {$$ = $1;}
64         | MANUAL_JAVA           {$$ = $1;}
65         | DONT_TRACE            {$$ = $1;}
66         | TYPEONLY              {$$ = $1;}
67           ;
68
69 defn:     DEFINE NAME LCURLY defbody RCURLY SEMI 
70                                 {$$ = add_define($2, $4);}
71
72         | NOVERSION SEMI
73                                 {$$ = suppress_version();}
74           ;
75
76 defbody:  defbody onedef        {$$ = add_defbody($1, $2);}
77         | onedef                {$$ = $1;}
78           ;
79
80 onedef:   PRIMTYPE vbl SEMI      {$$ = add_primtype($1, $2, 0);}
81         | TPACKED PRIMTYPE vbl SEMI {$$ = add_primtype($1, $2, $3);}
82         | NAME vbl SEMI          {$$ = add_complex($1, $2);}
83         | UNION NAME LCURLY defbody RCURLY SEMI 
84                                  {$$ = add_union($2, $4);}
85           ;
86
87 vbl:      NAME                      {$$ = add_scalar_vbl($1);}
88         | NAME LBRACK NUMBER RBRACK {$$ = add_vector_vbl($1, $3);}
89           ;