Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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); |
Marek Gradzki | fa42e25 | 2016-06-15 16:38:33 +0200 | [diff] [blame] | 34 | YYSTYPE add_variable_length_vector_vbl(YYSTYPE, YYSTYPE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 35 | YYSTYPE set_flags(YYSTYPE, YYSTYPE); |
| 36 | %} |
| 37 | |
| 38 | %token NAME RPAR LPAR SEMI LBRACK RBRACK NUMBER PRIMTYPE BARF |
| 39 | %token TPACKED DEFINE LCURLY RCURLY STRING UNION |
| 40 | %token HELPER_STRING COMMA |
Dave Barach | 11b8dbf | 2017-04-24 10:46:54 -0400 | [diff] [blame] | 41 | %token NOVERSION MANUAL_PRINT MANUAL_ENDIAN TYPEONLY DONT_TRACE AUTOREPLY |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | |
| 43 | %% |
| 44 | |
| 45 | pgm: slist {generate ($1);} |
| 46 | ; |
| 47 | |
| 48 | slist: slist stmt {$$ = add_slist ($1, $2);} |
| 49 | | stmt {$$ = $1;} |
| 50 | ; |
| 51 | |
| 52 | stmt: flist defn {$$ = set_flags($1, $2);} |
| 53 | | defn {$$ = $1;} |
| 54 | ; |
| 55 | |
Damjan Marion | 7bee80c | 2017-04-26 15:32:12 +0200 | [diff] [blame] | 56 | flist: flist flag {$$ = (YYSTYPE)(unsigned long) |
| 57 | ((unsigned long) $1 |
| 58 | | (unsigned long) $2);} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | | flag {$$ = $1;} |
| 60 | ; |
| 61 | |
| 62 | flag: |
| 63 | MANUAL_PRINT {$$ = $1;} |
| 64 | | MANUAL_ENDIAN {$$ = $1;} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | | DONT_TRACE {$$ = $1;} |
| 66 | | TYPEONLY {$$ = $1;} |
Dave Barach | 11b8dbf | 2017-04-24 10:46:54 -0400 | [diff] [blame] | 67 | | AUTOREPLY {$$ = $1;} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | ; |
| 69 | |
| 70 | defn: DEFINE NAME LCURLY defbody RCURLY SEMI |
| 71 | {$$ = add_define($2, $4);} |
| 72 | |
| 73 | | NOVERSION SEMI |
| 74 | {$$ = suppress_version();} |
| 75 | ; |
| 76 | |
| 77 | defbody: defbody onedef {$$ = add_defbody($1, $2);} |
| 78 | | onedef {$$ = $1;} |
| 79 | ; |
| 80 | |
| 81 | onedef: PRIMTYPE vbl SEMI {$$ = add_primtype($1, $2, 0);} |
| 82 | | TPACKED PRIMTYPE vbl SEMI {$$ = add_primtype($1, $2, $3);} |
| 83 | | NAME vbl SEMI {$$ = add_complex($1, $2);} |
| 84 | | UNION NAME LCURLY defbody RCURLY SEMI |
| 85 | {$$ = add_union($2, $4);} |
| 86 | ; |
| 87 | |
| 88 | vbl: NAME {$$ = add_scalar_vbl($1);} |
| 89 | | NAME LBRACK NUMBER RBRACK {$$ = add_vector_vbl($1, $3);} |
Marek Gradzki | fa42e25 | 2016-06-15 16:38:33 +0200 | [diff] [blame] | 90 | | NAME LBRACK NAME RBRACK {$$ = add_variable_length_vector_vbl($1, $3);} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | ; |