Revision 23b1539b filter/config.Y

View differences:

filter/config.Y
21 21
CF_KEYWORDS(FUNCTION, PRINTDEBUG, PRINT, CONST, PUTS, 
22 22
	ACCEPT, REJECT, ERROR, QUITBIRD,
23 23
	INT, BOOL, IP, PREFIX, PAIR, SET, STRING,
24
	IF, THEN,
24
	IF, THEN, ELSE,
25
	TRUE, FALSE,
25 26
	FILTER
26 27
	)
27 28

  
28
%type <x> term block cmds cmd function_body
29
%type <x> term block cmds cmd function_body ifthen constant print_one print_list
29 30
%type <f> filter filter_body
30 31
%type <i> type break_command
31 32

  
......
127 128
   }
128 129
 ;
129 130

  
131
constant:
132
   CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->arg1 = T_INT; $$->arg2 = $3; }
133
 | NUM    { $$ = f_new_inst(); $$->code = 'c'; $$->arg1 = T_INT;  $$->arg2 = $1; }
134
 | TRUE   { $$ = f_new_inst(); $$->code = 'c'; $$->arg1 = T_BOOL; $$->arg2 = 1;  }
135
 | FALSE  { $$ = f_new_inst(); $$->code = 'c'; $$->arg1 = T_BOOL; $$->arg2 = 0;  }
136
 | TEXT   { $$ = f_new_inst(); $$->code = 'c'; $$->arg1 = T_STRING; $$->arg2 = $1; } 
137
 ;
138

  
130 139
term:
131
   term '+' term {
132
     $$ = f_new_inst();
133
     $$->code = '+';
134
     $$->arg1 = $1;
135
     $$->arg2 = $3;
136
   }
140
   term '+' term     { $$ = f_new_inst(); $$->code = '+';  $$->arg1 = $1; $$->arg2 = $3; }
141

  
142
 | term '=' term     { $$ = f_new_inst(); $$->code = '=='; $$->arg1 = $1; $$->arg2 = $3; }
143
 | term '!' '=' term { $$ = f_new_inst(); $$->code = '!='; $$->arg1 = $1; $$->arg2 = $4; }
144
 | term '<' term     { $$ = f_new_inst(); $$->code = '<';  $$->arg1 = $1; $$->arg2 = $3; }
145
 | term '<' '=' term { $$ = f_new_inst(); $$->code = '<='; $$->arg1 = $1; $$->arg2 = $4; }
146
 | term '>' term     { $$ = f_new_inst(); $$->code = '<';  $$->arg1 = $3; $$->arg2 = $1; }
147
 | term '>' '=' term { $$ = f_new_inst(); $$->code = '<='; $$->arg1 = $4; $$->arg2 = $1; }
148

  
137 149
 | SYM {
138 150
     $$ = f_new_inst();
139 151
     switch ($1->class) {
140 152
       case SYM_VARIABLE | T_INT:
141 153
	 $$->code = 'i';
142
         $$->arg1 = &($1->aux);
154
         $$->arg1 = T_INT;
155
	 $$->arg2 = &($1->aux);
143 156
	 break;
144 157
       default:
145 158
	 cf_error("Can not use this class of symbol as variable" );
146 159
     }
147 160
   }
148
 | CONST '(' expr ')' {
149
     $$ = f_new_inst();
150
     $$->code = 'c';
151
     $$->arg1 = $3;
152
   }
153
 | NUM {
154
     $$ = f_new_inst();
155
     $$->code = 'c';
156
     $$->arg1 = $1
157
   }
161
 | constant { $$ = $1; }
158 162
 ;
159 163

  
160 164
break_command:
......
162 166
 | ACCEPT { $$ = F_ACCEPT }
163 167
 | REJECT { $$ = F_REJECT }
164 168
 | ERROR { $$ = F_ERROR }
169
 | PRINT { $$ = F_NOP }
165 170
 ;
166 171

  
167
cmd:
172
ifthen:
168 173
   IF term THEN block {
169 174
     $$ = f_new_inst();
170 175
     $$->code = '?';
171 176
     $$->arg1 = $2;
172 177
     $$->arg2 = $4;
173 178
   }
179
 ;
180

  
181
print_one:
182
   term { $$ = f_new_inst(); $$->code = 'p'; $$->arg1 = $1; $$->arg2 = NULL; }
183
 ;
184

  
185
print_list: /* EMPTY */ { $$ = NULL; }
186
 | print_one print_list {
187
     if ($1) {
188
       $1->next = $2;
189
       $$ = $1;
190
     } else $$ = $2;
191
   }
192
 ;
193

  
194
cmd:
195
   ifthen { 
196
     $$ = $1;
197
   }
198
	/* FIXME: this leads to shift/reduce conflict. */
199
 | ifthen ELSE block {
200
     $$ = f_new_inst();
201
     $$->code = '?';
202
     $$->arg1 = $1;
203
     $$->arg2 = $3;
204
   }
174 205
 | SYM '=' term ';' {
175 206
     $$ = f_new_inst();
176 207
     printf( "Ook, we'll set value\n" );
177 208
     if (($1->class & ~T_MASK) != SYM_VARIABLE)
178 209
       cf_error( "You may only set variables, and this is %x.\n", $1->class );
179
     $$->code = '=';
210
     $$->code = 's';
180 211
     $$->arg1 = $1;
181 212
     $$->arg2 = $3;
182 213
   }
183
 | PRINT '(' term ')' ';' {
184
     $$ = f_new_inst();
185
     printf( "Ook, we'll print something\n" );
186
     $$->code = 'p';
187
     $$->arg1 = $3;
188
     $$->arg2 = NULL;
189
   }
190
 | PUTS '(' TEXT ')' ';' {
191
     $$ = f_new_inst();
192
     $$->code = 'd';
193
     $$->arg1 = $3;
194
   }
195
 | PRINTDEBUG ';' {
196
     $$ = f_new_inst();
197
     $$->code = 'D';
198
     $$->arg1 = $$->arg2 = NULL;
199
   }
200
 | break_command ';' {
201
     $$ = f_new_inst();
202
     $$->code = '!';
203
     (int) $$->arg1 = $1;
204
   }
214
 | break_command print_list ';' { $$ = f_new_inst(); $$->code = 'p,'; $$->arg1 = $2; $$->arg2 = $1; }
205 215
 ;
206 216

  
207 217
CF_END

Also available in: Unified diff