blob: 5c5d46ff4e0f1fde8bf756fbff99f2420d68b461 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001%{
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
19extern void yyerror (char *s);
20extern int yylex (void);
21
22#define YYSTYPE void *
23
24void 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);
Marek Gradzkifa42e252016-06-15 16:38:33 +020034 YYSTYPE add_variable_length_vector_vbl(YYSTYPE, YYSTYPE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070035 YYSTYPE set_flags(YYSTYPE, YYSTYPE);
Dave Barach0d056e52017-09-28 15:11:16 -040036 YYSTYPE add_version(YYSTYPE, YYSTYPE, YYSTYPE);
Ed Warnickecb9cada2015-12-08 15:45:58 -070037%}
38
39%token NAME RPAR LPAR SEMI LBRACK RBRACK NUMBER PRIMTYPE BARF
40%token TPACKED DEFINE LCURLY RCURLY STRING UNION
Dave Barach0d056e52017-09-28 15:11:16 -040041%token HELPER_STRING COMMA DOT VL_API_VERSION
Dave Barach11b8dbf2017-04-24 10:46:54 -040042%token NOVERSION MANUAL_PRINT MANUAL_ENDIAN TYPEONLY DONT_TRACE AUTOREPLY
Ed Warnickecb9cada2015-12-08 15:45:58 -070043
44%%
45
46pgm: slist {generate ($1);}
47 ;
48
49slist: slist stmt {$$ = add_slist ($1, $2);}
50 | stmt {$$ = $1;}
51 ;
52
53stmt: flist defn {$$ = set_flags($1, $2);}
54 | defn {$$ = $1;}
Dave Barach0d056e52017-09-28 15:11:16 -040055 | api_version {$$ = $1;}
Ed Warnickecb9cada2015-12-08 15:45:58 -070056 ;
57
Damjan Marion7bee80c2017-04-26 15:32:12 +020058flist: flist flag {$$ = (YYSTYPE)(unsigned long)
59 ((unsigned long) $1
60 | (unsigned long) $2);}
Ed Warnickecb9cada2015-12-08 15:45:58 -070061 | flag {$$ = $1;}
62 ;
63
64flag:
65 MANUAL_PRINT {$$ = $1;}
66 | MANUAL_ENDIAN {$$ = $1;}
Ed Warnickecb9cada2015-12-08 15:45:58 -070067 | DONT_TRACE {$$ = $1;}
68 | TYPEONLY {$$ = $1;}
Dave Barach11b8dbf2017-04-24 10:46:54 -040069 | AUTOREPLY {$$ = $1;}
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 ;
71
72defn: DEFINE NAME LCURLY defbody RCURLY SEMI
73 {$$ = add_define($2, $4);}
74
75 | NOVERSION SEMI
76 {$$ = suppress_version();}
77 ;
78
79defbody: defbody onedef {$$ = add_defbody($1, $2);}
80 | onedef {$$ = $1;}
81 ;
82
83onedef: PRIMTYPE vbl SEMI {$$ = add_primtype($1, $2, 0);}
84 | TPACKED PRIMTYPE vbl SEMI {$$ = add_primtype($1, $2, $3);}
85 | NAME vbl SEMI {$$ = add_complex($1, $2);}
86 | UNION NAME LCURLY defbody RCURLY SEMI
87 {$$ = add_union($2, $4);}
88 ;
89
90vbl: NAME {$$ = add_scalar_vbl($1);}
91 | NAME LBRACK NUMBER RBRACK {$$ = add_vector_vbl($1, $3);}
Marek Gradzkifa42e252016-06-15 16:38:33 +020092 | NAME LBRACK NAME RBRACK {$$ = add_variable_length_vector_vbl($1, $3);}
Ed Warnickecb9cada2015-12-08 15:45:58 -070093 ;
Dave Barach0d056e52017-09-28 15:11:16 -040094
95api_version: VL_API_VERSION NUMBER DOT NUMBER DOT NUMBER
96 {$$ = add_version ($2, $4, $6);}