openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

api_grammar.y (4130B)


      1 %{
      2 /*
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7  *
      8  * File:        api_grammar.y
      9  * Purpose:     API mode parser
     10  */
     11 %}
     12 
     13 /* API mode grammar */
     14 
     15 %{
     16 #include "api_mode_yy.h"
     17 extern void api_mode_error(yyltype *loc, yyscan_t yyscanner,
     18                            void *parser, char const *s);
     19 %}
     20 
     21 %right '='
     22 
     23 %define api.pure
     24 %define api.push_pull "both"
     25 %name-prefix="api_mode_"
     26 %locations
     27 %debug
     28 %verbose
     29 %error-verbose
     30 
     31 %lex-param   { yyscan_t yyscanner }
     32 %parse-param { yyscan_t yyscanner }
     33 %parse-param { void *parser }
     34 
     35 %token IDENT
     36 %token KEY
     37 %token CONSTANT
     38 %token AGGREGATE
     39 %token PROMPT
     40 %token EMPTY
     41 %token KEY_VALUE
     42 %token RANGE
     43 %token ITEM
     44 %token ASSIGN
     45 %token VALUE
     46 %token PRINT
     47 %token VAR
     48 %token CREATE
     49 
     50 %%
     51 
     52 statements
     53     : statement
     54       { api_mode_execute(parser, $1); YYACCEPT; }
     55     | statements ';' statement
     56       { $$ = api_mode_append($1, api_mode_append($2,$3)); }
     57     ;
     58 
     59 statement
     60     : executable
     61     | '!'                                       /* set info mode */
     62     | '!' executable
     63         { $$ = api_mode_append($1,$2); }        /* info */
     64     | identifiers '?'                           /* help */
     65         { $$ = api_mode_append($1,$2); }
     66     | PRINT selector_list                       /* print */
     67         { $$ = api_mode_append($1,$2); }
     68     | CREATE identifiers keys                   /* type constructor */
     69         { $$ =  api_mode_append($1,api_mode_append($2,$3)); }
     70     | VAR selector_list '=' argument           /* variable assignment */
     71         { $$ = api_mode_append($1,api_mode_append($2,$4)); }
     72     | VAR selectors PROMPT                      /* prompt-mode assignment */
     73         { $$ = api_mode_append($1,api_mode_append($2,$3)); }
     74     ;
     75 
     76 executable
     77     : identifiers
     78     | identifiers PROMPT                        /* prompt */
     79         { $$ = api_mode_append($1,$2); }
     80     | identifiers positional_arguments          /* execute */
     81         { $$ = api_mode_append($1,$2); }
     82     | identifiers keyword_arguments             /* execute */
     83         { $$ = api_mode_append($1,$2); }
     84     ; 
     85 
     86 identifiers
     87     : IDENT
     88         { $$ = api_mode_mark($1, IS_FIRST); }
     89     | identifiers IDENT
     90         { $$ = api_mode_append($1,$2); }
     91     ;
     92 
     93 selectors
     94     : IDENT
     95         { $$ = api_mode_mark($1, IS_FIRST); }
     96     | selectors '.' IDENT
     97         { $$ = api_mode_sub_append($1,$3); }
     98     ;
     99 
    100 selector_list
    101     : selectors
    102         { $$ = api_mode_mark($1, IS_FIRST); }
    103     | selector_list selectors
    104         { $$ = api_mode_append($1,$2); }
    105     ;
    106 
    107 keys
    108     : KEY
    109         { $$ = api_mode_mark($1, IS_FIRST); }
    110     | keys KEY
    111         { $$ = api_mode_append($1,$2); }
    112     ;
    113 
    114 positional_arguments
    115     : argument
    116         { $$ = api_mode_mark($1, IS_FIRST); }
    117     | positional_arguments argument
    118         { $$ = api_mode_append($1,$2); }
    119     ;
    120 
    121 positional_item
    122     : ITEM
    123     | ITEM '-' ITEM
    124         { $$ = api_mode_range($1, $3, NULL, NULL); }
    125     | ITEM '*' CONSTANT
    126         { $$ = api_mode_range($1, NULL, NULL, $3); }
    127     | ITEM '-' ITEM '/' CONSTANT
    128         { $$ = api_mode_range($1, $3, NULL, $5); }
    129     | ITEM '*' ITEM '/' CONSTANT
    130         { $$ = api_mode_range($1, NULL, $3, $5); }
    131     ;
    132 
    133 positional_list
    134     : positional_item
    135         { $$ = api_mode_mark($1, IS_FIRST); }
    136     | positional_list ',' positional_item
    137         { $$ = api_mode_append($1,$3); }
    138     ;
    139 
    140 keyword_arguments
    141     : keyword_argument
    142         { $$ = api_mode_mark($1, IS_FIRST); }
    143     | keyword_arguments keyword_argument
    144         { $$ = api_mode_append($1,$2); }
    145     ;
    146 
    147 keyword_argument
    148     : KEY '=' argument
    149         { $$ = api_mode_key_value($1,$3); }
    150     ;
    151 
    152 argument
    153     : CONSTANT
    154     | VALUE
    155     | aggregate
    156     ;
    157 
    158 aggregate
    159     : '{' aggregate_arguments '}'
    160         { $$ = api_mode_sub(api_mode_node(parser,"", AGGREGATE), $2); }
    161     | positional_list
    162         { $$ = api_mode_sub(api_mode_node(parser,"", AGGREGATE), $1); }
    163     ;
    164 
    165 aggregate_arguments
    166     : keyword_arguments
    167     | positional_arguments
    168     | '='
    169         { $$ = api_mode_node(parser,"{=}", PROMPT); }
    170     ;
    171