Add new udafs and RMR support to gsprintconsole_ves
[com/gs-lite.git] / src / ftacmp / ext_fcns.y
1 /* ------------------------------------------------
2 Copyright 2014 AT&T Intellectual Property
3    Licensed under the Apache License, Version 2.0 (the "License");
4    you may not use this file except in compliance with the License.
5    You may obtain a copy of the License at
6
7      http://www.apache.org/licenses/LICENSE-2.0
8
9    Unless required by applicable law or agreed to in writing, software
10    distributed under the License is distributed on an "AS IS" BASIS,
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12    See the License for the specific language governing permissions and
13    limitations under the License.
14  ------------------------------------------- */
15
16 /*
17         MUST COMPILE WITH
18         bison --verbose --defines=ext_fcns.tab.cc.h -p Ext_fcnsParser -o ext_fcns.tab.cc ext_fcns.y
19          
20          (or equivalent).
21 */
22
23 %{
24
25
26 #include <stdio.h>
27
28 /*              Some addn'l includes, necessary but not included by the
29                 bison generated code.
30 */
31
32 #include <stdlib.h>
33
34 /*              prototypes for the parser callbacks.
35 */
36
37 #include "parse_ext_fcns.h"
38
39 /*              Interface to ext_fcns parser    */
40         int yyparse();
41         void yyerror(char *s);
42         int yylex();
43 extern int flex_ext_fcns_lineno, flex_ext_fcns_ch;
44
45 /*              Return value    */
46 extern ext_fcn_list *Ext_fcns;
47
48 #define YYDEBUG 1
49
50 %}
51
52
53         /* symbolic tokens */
54
55 %union {
56         char* strval;
57         ext_fcn_list *ext_fcn_list_t;
58         ext_fcn_def *ext_fcn_t;
59         ext_fcn_param_list *plist_t;
60         param_list *tplist_t;
61         ext_fcn_param *param_t;
62         ext_fcn_modifier_list *modif_t;
63         }
64
65         
66 %token <strval> NAME
67 %token <strval> STRING_TOKEN
68 %token <strval> INTNUM
69
70
71 %type <ext_fcn_t> fcn_def 
72 %type <ext_fcn_list_t> fcn_list
73 %type <plist_t> param_commalist
74 %type <plist_t> opt_param_commalist
75 %type <tplist_t> type_param_commalist
76 %type <tplist_t> opt_type_param_commalist
77 %type <param_t> param
78 %type <modif_t> modifier_list
79         /* operators */
80
81
82         /* literal keyword tokens */
83
84 %token SEMICOLON HANDLE CONST CLASS FUN PRED
85 %token EXTR UDAF STATE SFUN
86
87
88 %%
89
90 result: fcn_list        {Ext_fcns = $1;}
91         ;
92
93 fcn_list:       fcn_def {$$ = new ext_fcn_list($1);}
94         |       fcn_list fcn_def        {$$ = $1->append_ext_fcn_def($2);}
95         ;
96
97 fcn_def:        NAME opt_type_param_commalist FUN '[' modifier_list ']' NAME '(' opt_param_commalist ')' SEMICOLON  {
98                                         $$=new ext_fcn_def($1,$2,$5,$7,$9); delete $5; delete $9; }
99         |       NAME opt_type_param_commalist FUN NAME '(' opt_param_commalist ')' SEMICOLON  {
100                                         $$=new ext_fcn_def($1,$2,NULL,$4,$6); delete $6; }
101         |       PRED '[' modifier_list ']' NAME '[' opt_param_commalist ']' SEMICOLON  {
102                                         $$=new ext_fcn_def($3,$5,$7); delete $3; delete $7; }
103         |       PRED NAME '[' opt_param_commalist ']' SEMICOLON  {
104                                         $$=new ext_fcn_def(NULL,$2,$4); delete $4; }
105         |       NAME opt_type_param_commalist UDAF '[' modifier_list ']' NAME NAME '(' opt_param_commalist ')' SEMICOLON  {
106                                         $$=new ext_fcn_def($1,$2,$5,$7,$8,$10); delete $5; delete $10; }
107         |       NAME opt_type_param_commalist UDAF NAME NAME '(' opt_param_commalist ')' SEMICOLON  {
108                                         $$=new ext_fcn_def($1,$2,NULL,$4,$5, $7); delete $7; }
109         |       NAME opt_type_param_commalist EXTR '[' modifier_list ']' NAME NAME NAME '(' opt_param_commalist ')' SEMICOLON  {
110                                         $$=new ext_fcn_def($1,$2,$5,$7,$8, $9, $11); delete $5; delete $11; }
111         |       NAME opt_type_param_commalist EXTR NAME NAME NAME '(' opt_param_commalist ')' SEMICOLON  {
112                                         $$=new ext_fcn_def($1,$2,NULL,$4,$5, $6, $8); delete $8; }
113         |       NAME opt_type_param_commalist SFUN '[' modifier_list ']' NAME NAME '(' opt_param_commalist ')' SEMICOLON  {
114                                         $$=ext_fcn_def::make_sfun_def($1,$2,$5,$7,$8,$10); delete $10; }
115         |       NAME opt_type_param_commalist SFUN NAME NAME '(' opt_param_commalist ')' SEMICOLON  {
116                                         $$=ext_fcn_def::make_sfun_def($1,$2,NULL,$4,$5,$7); delete $7; }
117         |       NAME STATE NAME SEMICOLON  {
118                                         $$=ext_fcn_def::make_state_def($1,$3); }
119
120         ;
121
122 opt_param_commalist:
123                 /* empty */    {$$ = NULL;}
124         |       param_commalist {$$ = $1;}
125         ;
126         
127 modifier_list:
128                 NAME    {$$ = new ext_fcn_modifier_list($1);}
129         |       NAME NAME       {$$ = new ext_fcn_modifier_list($1, $2);}
130         |       modifier_list ',' NAME  {$$ = $1->append($3);   }       
131         |       modifier_list ',' NAME NAME     {$$ = $1->append($3, $4);       }       
132         ;
133         
134 param_commalist:
135                 param   {$$ = new ext_fcn_param_list($1);}
136         |       param_commalist ',' param {$$ = $1->append($3);}
137         ;
138
139 param:
140                 NAME opt_type_param_commalist HANDLE    { $$ = new ext_fcn_param($1,$2,1,0,0);}
141         |       NAME opt_type_param_commalist CONST     { $$ = new ext_fcn_param($1,$2,0,1,0);}
142         |       NAME opt_type_param_commalist CLASS     { $$ = new ext_fcn_param($1,$2,0,0,1);}
143         |       NAME opt_type_param_commalist HANDLE CLASS      { $$ = new ext_fcn_param($1,$2,1,0,1);}
144         |       NAME opt_type_param_commalist CONST CLASS       { $$ = new ext_fcn_param($1,$2,0,1,1);}
145         |       NAME opt_type_param_commalist
146                                 { $$ = new ext_fcn_param($1,$2,0,0,0);}
147         ;
148
149 opt_type_param_commalist:
150                 /* empty */    {$$ = NULL;}
151         |       '(' type_param_commalist ')' {$$ = $2;}
152         ;
153
154 type_param_commalist:
155                 NAME    {$$ = new param_list($1);}
156         |       NAME NAME       {$$ = new param_list($1,$2);}
157         |       NAME STRING_TOKEN       {$$ = new param_list($1,$2);}
158         |       NAME INTNUM     {$$ = new param_list($1,$2);}
159         |       type_param_commalist ',' NAME {$$ = $1->append($3);}
160         |       type_param_commalist ',' NAME NAME {$$ = $1->append($3,$4);}
161         |       type_param_commalist ',' NAME STRING_TOKEN {$$ = $1->append($3,$4);}
162         |       type_param_commalist ',' NAME INTNUM {$$ = $1->append($3,$4);}
163         ;
164
165
166
167 %%
168