-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval.y
6401 lines (5780 loc) · 199 KB
/
eval.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************/
/* */
/* CFITSIO Lexical Parser */
/* */
/* All functions preceeded by fits_parser_yy for uniqueness */
%define api.prefix {fits_parser_yy}
/* Pure reentrant parser */
%define api.pure full
/* Lexer called with extra state variable */
%param { yyscan_t scanner }
/* Parser called with extra parse state variable */
%parse-param { ParseData *lParse }
%{
/* This file is one of 3 files containing code which parses an */
/* arithmetic expression and evaluates it in the context of an input */
/* FITS file table extension. The CFITSIO lexical parser is divided */
/* into the following 3 parts/files: the CFITSIO "front-end", */
/* eval_f.c, contains the interface between the user/CFITSIO and the */
/* real core of the parser; the FLEX interpreter, eval_l.c, takes the */
/* input string and parses it into tokens and identifies the FITS */
/* information required to evaluate the expression (ie, keywords and */
/* columns); and, the BISON grammar and evaluation routines, eval_y.c, */
/* receives the FLEX output and determines and performs the actual */
/* operations. The files eval_l.c and eval_y.c are produced from */
/* running flex and bison on the files eval.l and eval.y, respectively. */
/* (flex and bison are available from any GNU archive: see www.gnu.org) */
/* */
/* The grammar rules, rather than evaluating the expression in situ, */
/* builds a tree, or Nodal, structure mapping out the order of */
/* operations and expression dependencies. This "compilation" process */
/* allows for much faster processing of multiple rows. This technique */
/* was developed by Uwe Lammers of the XMM Science Analysis System, */
/* although the CFITSIO implementation is entirely code original. */
/* */
/* */
/* Modification History: */
/* */
/* Kent Blackburn c1992 Original parser code developed for the */
/* FTOOLS software package, in particular, */
/* the fselect task. */
/* Kent Blackburn c1995 BIT column support added */
/* Peter D Wilson Feb 1998 Vector column support added */
/* Peter D Wilson May 1998 Ported to CFITSIO library. User */
/* interface routines written, in essence */
/* making fselect, fcalc, and maketime */
/* capabilities available to all tools */
/* via single function calls. */
/* Peter D Wilson Jun 1998 Major rewrite of parser core, so as to */
/* create a run-time evaluation tree, */
/* inspired by the work of Uwe Lammers, */
/* resulting in a speed increase of */
/* 10-100 times. */
/* Peter D Wilson Jul 1998 gtifilter(a,b,c,d) function added */
/* Peter D Wilson Aug 1998 regfilter(a,b,c,d) function added */
/* Peter D Wilson Jul 1999 Make parser fitsfile-independent, */
/* allowing a purely vector-based usage */
/* Craig B Markwardt Jun 2004 Add MEDIAN() function */
/* Craig B Markwardt Jun 2004 Add SUM(), and MIN/MAX() for bit arrays */
/* Craig B Markwardt Jun 2004 Allow subscripting of nX bit arrays */
/* Craig B Markwardt Jun 2004 Implement statistical functions */
/* NVALID(), AVERAGE(), and STDDEV() */
/* for integer and floating point vectors */
/* Craig B Markwardt Jun 2004 Use NULL values for range errors instead*/
/* of throwing a parse error */
/* Craig B Markwardt Oct 2004 Add ACCUM() and SEQDIFF() functions */
/* Craig B Markwardt Feb 2005 Add ANGSEP() function */
/* Craig B Markwardt Aug 2005 CIRCLE, BOX, ELLIPSE, NEAR and REGFILTER*/
/* functions now accept vector arguments */
/* Craig B Markwardt Sum 2006 Add RANDOMN() and RANDOMP() functions */
/* Craig B Markwardt Mar 2007 Allow arguments to RANDOM and RANDOMN to*/
/* determine the output dimensions */
/* Craig B Markwardt Aug 2009 Add substring STRMID() and string search*/
/* STRSTR() functions; more overflow checks*/
/* Craig B Markwardt Dec 2019 Add bit/hex/oct literal strings and */
/* bitwise operatiosn between integers */
/* Craig B Markwardt Mar 2021 Add SETNULL() function */
/* */
/************************************************************************/
#define APPROX 1.0e-7
#include "eval_defs.h"
#include "region.h"
#include <time.h>
#include <stdlib.h>
#ifndef alloca
#define alloca malloc
#endif
/* Random number generators for various distributions */
#include "simplerng.h"
/* Shrink the initial stack depth to keep local data <32K (mac limit) */
/* yacc will allocate more space if needed, though. */
#define YYINITDEPTH 100
/***************************************************************/
/* Replace Bison's BACKUP macro with one that fixes a bug -- */
/* must update state after popping the stack -- and allows */
/* popping multiple terms at one time. */
/***************************************************************/
#define YYNEWBACKUP(token, value) \
do \
if (yychar == YYEMPTY ) \
{ yychar = (token); \
memcpy( &yylval, &(value), sizeof(value) ); \
yychar1 = YYTRANSLATE (yychar); \
while (yylen--) YYPOPSTACK; \
yystate = *yyssp; \
goto yybackup; \
} \
else \
{ yyerror ("syntax error: cannot back up"); YYERROR; } \
while (0)
/***************************************************************/
/* Useful macros for accessing/testing Nodes */
/***************************************************************/
#define TEST(a) if( (a)<0 ) YYERROR
#define SIZE(a) lParse->Nodes[ a ].value.nelem
#define TYPE(a) lParse->Nodes[ a ].type
#define OPER(a) lParse->Nodes[ a ].operation
#define PROMOTE(a,b) if( TYPE(a) > TYPE(b) ) \
b = New_Unary( lParse, TYPE(a), 0, b ); \
else if( TYPE(a) < TYPE(b) ) \
a = New_Unary( lParse, TYPE(b), 0, a );
/***** Internal functions *****/
#ifdef __cplusplus
extern "C" {
#endif
static int Alloc_Node ( ParseData * );
static void Free_Last_Node( ParseData * );
static void Evaluate_Node ( ParseData *, int thisNode );
static int New_Const ( ParseData *, int returnType, void *value, long len );
static int New_Column( ParseData *, int ColNum );
static int New_Offset( ParseData *, int ColNum, int offset );
static int New_Unary ( ParseData *, int returnType, int Op, int Node1 );
static int New_BinOp ( ParseData *, int returnType, int Node1, int Op, int Node2 );
static int New_Func ( ParseData *, int returnType, funcOp Op, int nNodes,
int Node1, int Node2, int Node3, int Node4,
int Node5, int Node6, int Node7 );
static int New_FuncSize( ParseData *, int returnType, funcOp Op, int nNodes,
int Node1, int Node2, int Node3, int Node4,
int Node5, int Node6, int Node7, int Size);
static int New_Deref ( ParseData *, int Var, int nDim,
int Dim1, int Dim2, int Dim3, int Dim4, int Dim5 );
static int New_GTI ( ParseData *, funcOp Op, char *fname, int Node1, int Node2, char *start, char *stop );
static int New_REG ( ParseData *, char *fname, int NodeX, int NodeY, char *colNames );
static int New_Vector( ParseData *, int subNode );
static int Close_Vec ( ParseData *, int vecNode );
static int New_Array( ParseData *, int valueNode, int dimNode );
static int Locate_Col( ParseData *, Node *this );
static int Test_Dims ( ParseData *, int Node1, int Node2 );
static void Copy_Dims ( ParseData *, int Node1, int Node2 );
static void Allocate_Ptrs( ParseData *, Node *this );
static void Do_Unary ( ParseData *, Node *this );
static void Do_Offset ( ParseData *, Node *this );
static void Do_BinOp_bit ( ParseData *, Node *this );
static void Do_BinOp_str ( ParseData *, Node *this );
static void Do_BinOp_log ( ParseData *, Node *this );
static void Do_BinOp_lng ( ParseData *, Node *this );
static void Do_BinOp_dbl ( ParseData *, Node *this );
static void Do_Func ( ParseData *, Node *this );
static void Do_Deref ( ParseData *, Node *this );
static void Do_GTI ( ParseData *, Node *this );
static void Do_GTI_Over ( ParseData *, Node *this );
static void Do_REG ( ParseData *, Node *this );
static void Do_Vector ( ParseData *, Node *this );
static void Do_Array ( ParseData *, Node *this );
static long Search_GTI ( double evtTime, long nGTI, double *start,
double *stop, int ordered, long *nextGTI );
static double GTI_Over(double evtStart, double evtStop,
long nGTI, double *start, double *stop,
long *gtiout);
static char saobox (double xcen, double ycen, double xwid, double ywid,
double rot, double xcol, double ycol);
static char ellipse(double xcen, double ycen, double xrad, double yrad,
double rot, double xcol, double ycol);
static char circle (double xcen, double ycen, double rad,
double xcol, double ycol);
static char bnear (double x, double y, double tolerance);
static char bitcmp (char *bitstrm1, char *bitstrm2);
static char bitlgte(char *bits1, int oper, char *bits2);
static void bitand(char *result, char *bitstrm1, char *bitstrm2);
static void bitor (char *result, char *bitstrm1, char *bitstrm2);
static void bitnot(char *result, char *bits);
static int cstrmid(ParseData *lParse, char *dest_str, int dest_len,
char *src_str, int src_len, int pos);
static void yyerror(yyscan_t scanner, ParseData *lParse, char *s);
#ifdef __cplusplus
}
#endif
%}
%union {
int Node; /* Index of Node */
double dbl; /* real value */
long lng; /* integer value */
char log; /* logical value */
char str[MAX_STRLEN]; /* string value */
}
%token <log> BOOLEAN /* First 3 must be in order of */
%token <lng> LONG /* increasing promotion for later use */
%token <dbl> DOUBLE
%token <str> STRING
%token <str> BITSTR
%token <str> FUNCTION
%token <str> BFUNCTION /* Bit function */
%token <str> IFUNCTION /* Integer function */
%token <str> GTIFILTER
%token <str> GTIOVERLAP
%token <str> GTIFIND
%token <str> REGFILTER
%token <lng> COLUMN
%token <lng> BCOLUMN
%token <lng> SCOLUMN
%token <lng> BITCOL
%token <lng> ROWREF
%token <lng> NULLREF
%token <lng> SNULLREF
%type <Node> expr
%type <Node> bexpr
%type <Node> sexpr
%type <Node> bits
%type <Node> vector
%type <Node> bvector
%left ',' '=' ':' '{' '}'
%right '?'
%left OR
%left AND
%left EQ NE '~'
%left GT LT LTE GTE
%left '+' '-' '%'
%left '*' '/'
%left '|' '&' XOR
%right POWER
%left NOT
%left INTCAST FLTCAST
%left UMINUS
%left '['
%right ACCUM DIFF
%%
lines: /* nothing ; was | lines line */
| lines line
;
line: '\n' {}
| expr '\n'
{ if( $1<0 ) {
yyerror(scanner, lParse, "Couldn't build node structure: out of memory?");
YYERROR; }
lParse->resultNode = $1;
}
| bexpr '\n'
{ if( $1<0 ) {
yyerror(scanner, lParse, "Couldn't build node structure: out of memory?");
YYERROR; }
lParse->resultNode = $1;
}
| sexpr '\n'
{ if( $1<0 ) {
yyerror(scanner, lParse, "Couldn't build node structure: out of memory?");
YYERROR; }
lParse->resultNode = $1;
}
| bits '\n'
{ if( $1<0 ) {
yyerror(scanner, lParse, "Couldn't build node structure: out of memory?");
YYERROR; }
lParse->resultNode = $1;
}
| error '\n' { yyerrok; }
;
bvector: '{' bexpr
{ $$ = New_Vector(lParse, $2 ); TEST($$); }
| bvector ',' bexpr
{
if( lParse->Nodes[$1].nSubNodes >= MAXSUBS ) {
$1 = Close_Vec(lParse, $1 ); TEST($1);
$$ = New_Vector(lParse, $1 ); TEST($$);
} else {
$$ = $1;
}
lParse->Nodes[$$].SubNodes[ lParse->Nodes[$$].nSubNodes++ ]
= $3;
}
;
vector: '{' expr
{ $$ = New_Vector(lParse, $2 ); TEST($$); }
| vector ',' expr
{
if( TYPE($1) < TYPE($3) )
TYPE($1) = TYPE($3);
if( lParse->Nodes[$1].nSubNodes >= MAXSUBS ) {
$1 = Close_Vec(lParse, $1 ); TEST($1);
$$ = New_Vector(lParse, $1 ); TEST($$);
} else {
$$ = $1;
}
lParse->Nodes[$$].SubNodes[ lParse->Nodes[$$].nSubNodes++ ]
= $3;
}
| vector ',' bexpr
{
if( lParse->Nodes[$1].nSubNodes >= MAXSUBS ) {
$1 = Close_Vec(lParse, $1 ); TEST($1);
$$ = New_Vector(lParse, $1 ); TEST($$);
} else {
$$ = $1;
}
lParse->Nodes[$$].SubNodes[ lParse->Nodes[$$].nSubNodes++ ]
= $3;
}
| bvector ',' expr
{
TYPE($1) = TYPE($3);
if( lParse->Nodes[$1].nSubNodes >= MAXSUBS ) {
$1 = Close_Vec(lParse, $1 ); TEST($1);
$$ = New_Vector(lParse, $1 ); TEST($$);
} else {
$$ = $1;
}
lParse->Nodes[$$].SubNodes[ lParse->Nodes[$$].nSubNodes++ ]
= $3;
}
;
expr: vector '}'
{ $$ = Close_Vec(lParse, $1 ); TEST($$); }
;
bexpr: bvector '}'
{ $$ = Close_Vec(lParse, $1 ); TEST($$); }
;
bits: BITSTR
{
$$ = New_Const(lParse, BITSTR, $1, strlen($1)+1 ); TEST($$);
SIZE($$) = strlen($1); }
| BITCOL
{ $$ = New_Column(lParse, $1 ); TEST($$); }
| BITCOL '{' expr '}'
{
if( TYPE($3) != LONG
|| OPER($3) != CONST_OP ) {
yyerror(scanner, lParse, "Offset argument must be a constant integer");
YYERROR;
}
$$ = New_Offset(lParse, $1, $3 ); TEST($$);
}
| bits '&' bits
{ $$ = New_BinOp(lParse, BITSTR, $1, '&', $3 ); TEST($$);
SIZE($$) = ( SIZE($1)>SIZE($3) ? SIZE($1) : SIZE($3) ); }
| bits '|' bits
{ $$ = New_BinOp(lParse, BITSTR, $1, '|', $3 ); TEST($$);
SIZE($$) = ( SIZE($1)>SIZE($3) ? SIZE($1) : SIZE($3) ); }
| bits '+' bits
{
if (SIZE($1)+SIZE($3) >= MAX_STRLEN) {
yyerror(scanner, lParse, "Combined bit string size exceeds " MAX_STRLEN_S " bits");
YYERROR;
}
$$ = New_BinOp(lParse, BITSTR, $1, '+', $3 ); TEST($$);
SIZE($$) = SIZE($1) + SIZE($3);
}
| bits '[' expr ']'
{ $$ = New_Deref(lParse, $1, 1, $3, 0, 0, 0, 0 ); TEST($$); }
| bits '[' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 2, $3, $5, 0, 0, 0 ); TEST($$); }
| bits '[' expr ',' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 3, $3, $5, $7, 0, 0 ); TEST($$); }
| bits '[' expr ',' expr ',' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 4, $3, $5, $7, $9, 0 ); TEST($$); }
| bits '[' expr ',' expr ',' expr ',' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 5, $3, $5, $7, $9, $11 ); TEST($$); }
| NOT bits
{ $$ = New_Unary(lParse, BITSTR, NOT, $2 ); TEST($$); }
| '(' bits ')'
{ $$ = $2; }
;
expr: LONG
{ $$ = New_Const(lParse, LONG, &($1), sizeof(long) ); TEST($$); }
| DOUBLE
{ $$ = New_Const(lParse, DOUBLE, &($1), sizeof(double) ); TEST($$); }
| COLUMN
{ $$ = New_Column(lParse, $1 ); TEST($$); }
| COLUMN '{' expr '}'
{
if( TYPE($3) != LONG
|| OPER($3) != CONST_OP ) {
yyerror(scanner, lParse, "Offset argument must be a constant integer");
YYERROR;
}
$$ = New_Offset(lParse, $1, $3 ); TEST($$);
}
| ROWREF
{ $$ = New_Func(lParse, LONG, row_fct, 0, 0, 0, 0, 0, 0, 0, 0 ); }
| NULLREF
{ $$ = New_Func(lParse, LONG, null_fct, 0, 0, 0, 0, 0, 0, 0, 0 ); }
| expr '%' expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, TYPE($1), $1, '%', $3 );
TEST($$); }
| expr '+' expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, TYPE($1), $1, '+', $3 );
TEST($$); }
| expr '-' expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, TYPE($1), $1, '-', $3 );
TEST($$); }
| expr '*' expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, TYPE($1), $1, '*', $3 );
TEST($$); }
| expr '/' expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, TYPE($1), $1, '/', $3 );
TEST($$); }
| expr '&' expr
{
if (TYPE($1) != LONG ||
TYPE($3) != LONG) {
yyerror(scanner, lParse, "Bitwise operations with incompatible types; only (bit OP bit) and (int OP int) are allowed");
YYERROR;
}
$$ = New_BinOp(lParse, TYPE($1), $1, '&', $3 );
}
| expr '|' expr
{
if (TYPE($1) != LONG ||
TYPE($3) != LONG) {
yyerror(scanner, lParse, "Bitwise operations with incompatible types; only (bit OP bit) and (int OP int) are allowed");
YYERROR;
}
$$ = New_BinOp(lParse, TYPE($1), $1, '|', $3 );
}
| expr XOR expr
{
if (TYPE($1) != LONG ||
TYPE($3) != LONG) {
yyerror(scanner, lParse, "Bitwise operations with incompatible types; only (bit OP bit) and (int OP int) are allowed");
YYERROR;
}
$$ = New_BinOp(lParse, TYPE($1), $1, '^', $3 );
}
| expr POWER expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, TYPE($1), $1, POWER, $3 );
TEST($$); }
| '+' expr %prec UMINUS
{ $$ = $2; }
| '-' expr %prec UMINUS
{ $$ = New_Unary(lParse, TYPE($2), UMINUS, $2 ); TEST($$); }
| '(' expr ')'
{ $$ = $2; }
| expr '*' bexpr
{ $3 = New_Unary(lParse, TYPE($1), 0, $3 );
$$ = New_BinOp(lParse, TYPE($1), $1, '*', $3 );
TEST($$); }
| bexpr '*' expr
{ $1 = New_Unary(lParse, TYPE($3), 0, $1 );
$$ = New_BinOp(lParse, TYPE($3), $1, '*', $3 );
TEST($$); }
| bexpr '?' expr ':' expr
{
PROMOTE($3,$5);
if( ! Test_Dims( lParse, $3,$5) ) {
yyerror(scanner, lParse, "Incompatible dimensions in '?:' arguments");
YYERROR;
}
$$ = New_Func(lParse, 0, ifthenelse_fct, 3, $3, $5, $1,
0, 0, 0, 0 );
TEST($$);
if( SIZE($3)<SIZE($5) ) Copy_Dims( lParse,$$, $5);
TYPE($1) = TYPE($3);
if( ! Test_Dims( lParse, $1,$$) ) {
yyerror(scanner, lParse, "Incompatible dimensions in '?:' condition");
YYERROR;
}
TYPE($1) = BOOLEAN;
if( SIZE($$)<SIZE($1) ) Copy_Dims( lParse,$$, $1);
}
| bexpr '?' bexpr ':' expr
{
PROMOTE($3,$5);
if( ! Test_Dims( lParse, $3,$5) ) {
yyerror(scanner, lParse, "Incompatible dimensions in '?:' arguments");
YYERROR;
}
$$ = New_Func(lParse, 0, ifthenelse_fct, 3, $3, $5, $1,
0, 0, 0, 0 );
TEST($$);
if( SIZE($3)<SIZE($5) ) Copy_Dims( lParse,$$, $5);
TYPE($1) = TYPE($3);
if( ! Test_Dims( lParse, $1,$$) ) {
yyerror(scanner, lParse, "Incompatible dimensions in '?:' condition");
YYERROR;
}
TYPE($1) = BOOLEAN;
if( SIZE($$)<SIZE($1) ) Copy_Dims( lParse,$$, $1);
}
| bexpr '?' expr ':' bexpr
{
PROMOTE($3,$5);
if( ! Test_Dims( lParse, $3,$5) ) {
yyerror(scanner, lParse, "Incompatible dimensions in '?:' arguments");
YYERROR;
}
$$ = New_Func(lParse, 0, ifthenelse_fct, 3, $3, $5, $1,
0, 0, 0, 0 );
TEST($$);
if( SIZE($3)<SIZE($5) ) Copy_Dims( lParse,$$, $5);
TYPE($1) = TYPE($3);
if( ! Test_Dims( lParse, $1,$$) ) {
yyerror(scanner, lParse, "Incompatible dimensions in '?:' condition");
YYERROR;
}
TYPE($1) = BOOLEAN;
if( SIZE($$)<SIZE($1) ) Copy_Dims( lParse,$$, $1);
}
| FUNCTION ')'
{ if (FSTRCMP($1,"RANDOM(") == 0) { /* Scalar RANDOM() */
$$ = New_Func(lParse, DOUBLE, rnd_fct, 0, 0, 0, 0, 0, 0, 0, 0 );
} else if (FSTRCMP($1,"RANDOMN(") == 0) {/*Scalar RANDOMN()*/
$$ = New_Func(lParse, DOUBLE, gasrnd_fct, 0, 0, 0, 0, 0, 0, 0, 0 );
} else {
yyerror(scanner, lParse, "Function() not supported");
YYERROR;
}
TEST($$);
}
| FUNCTION bexpr ')'
{ if (FSTRCMP($1,"SUM(") == 0) {
$$ = New_Func(lParse, LONG, sum_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
} else if (FSTRCMP($1,"NELEM(") == 0) {
$$ = New_Const(lParse, LONG, &( SIZE($2) ), sizeof(long) );
} else if (FSTRCMP($1,"ACCUM(") == 0) {
long zero = 0;
$$ = New_BinOp(lParse, LONG , $2, ACCUM, New_Const(lParse, LONG, &zero, sizeof(zero) ));
} else {
yyerror(scanner, lParse, "Function(bool) not supported");
YYERROR;
}
TEST($$);
}
| FUNCTION bexpr ',' expr ')'
{ if (FSTRCMP($1,"AXISELEM(") == 0) { /* AXISELEM(V,n) */
if (OPER($4) != CONST_OP
|| SIZE($4) != 1) {
yyerror(scanner, lParse, "AXISELEM second argument must be a scalar constant");
YYERROR;
}
if (OPER($2) == CONST_OP) {
long one = 1;
$$ = New_Const(lParse, LONG, &one, sizeof(one) );
} else {
if ( TYPE($4) != LONG ) $4 = New_Unary(lParse, LONG, 0, $4);
$$ = New_Func(lParse, 0, axiselem_fct, 2, $2, $4, 0, 0, 0, 0, 0 );
TEST($$);
TYPE($$) = LONG;
}
} else if (FSTRCMP($1,"NAXES(") == 0) { /* NAXES(V,n) */
if (OPER($4) != CONST_OP
|| SIZE($4) != 1) {
yyerror(scanner, lParse, "NAXES second argument must be a scalar constant");
YYERROR;
}
if (OPER($2) == CONST_OP) { /* if V is constant, return 1 in every case */
long one = 1;
$$ = New_Const(lParse, LONG, &one, sizeof(one) );
} else { /* determine now the dimension of the expression */
long iaxis;
int naxis;
if ( TYPE($4) != LONG ) $4 = New_Unary(lParse, LONG, 0, $4);
/* Since it is already constant, we can extract long value directly */
iaxis = (lParse->Nodes[$4].value.data.lng);
naxis = lParse->Nodes[$2].value.naxis;
if (iaxis == 0) iaxis = naxis; /* NAXIS(V,0) = NAXIS */
else if (iaxis <= naxis) iaxis = lParse->Nodes[$2].value.naxes[iaxis-1]; /* NAXIS(V,n) = NAXISn */
else iaxis = 1; /* Out of bounds use 1 */
$$ = New_Const(lParse, LONG, &iaxis, sizeof(iaxis) );
TEST($$);
}
} else if (FSTRCMP($1,"ARRAY(") == 0) { /* NAXES(bexpr,n) */
$$ = New_Array(lParse, $2, $4);
TEST($$);
} else {
yyerror(scanner, lParse, "Function(bool,expr) not supported");
YYERROR;
}
TEST($$);
}
| FUNCTION sexpr ')'
{ if (FSTRCMP($1,"NELEM(") == 0) {
$$ = New_Const(lParse, LONG, &( SIZE($2) ), sizeof(long) );
} else if (FSTRCMP($1,"NVALID(") == 0) {
$$ = New_Func(lParse, LONG, nonnull_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
} else {
yyerror(scanner, lParse, "Function(str) not supported");
YYERROR;
}
TEST($$);
}
| FUNCTION bits ')'
{ if (FSTRCMP($1,"NELEM(") == 0) {
$$ = New_Const(lParse, LONG, &( SIZE($2) ), sizeof(long) );
} else if (FSTRCMP($1,"NVALID(") == 0) { /* Bit arrays do not have NULL */
$$ = New_Const(lParse, LONG, &( SIZE($2) ), sizeof(long) );
} else if (FSTRCMP($1,"SUM(") == 0) {
$$ = New_Func(lParse, LONG, sum_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
} else if (FSTRCMP($1,"MIN(") == 0) {
$$ = New_Func(lParse, TYPE($2), /* Force 1D result */
min1_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
/* Note: $2 is a vector so the result can never
be a constant. Therefore it will never be set
inside New_Func(), and it is safe to set SIZE() */
SIZE($$) = 1;
} else if (FSTRCMP($1,"ACCUM(") == 0) {
long zero = 0;
$$ = New_BinOp(lParse, LONG , $2, ACCUM, New_Const(lParse, LONG, &zero, sizeof(zero) ));
} else if (FSTRCMP($1,"MAX(") == 0) {
$$ = New_Func(lParse, TYPE($2), /* Force 1D result */
max1_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
/* Note: $2 is a vector so the result can never
be a constant. Therefore it will never be set
inside New_Func(), and it is safe to set SIZE() */
SIZE($$) = 1;
} else {
yyerror(scanner, lParse, "Function(bits) not supported");
YYERROR;
}
TEST($$);
}
| FUNCTION expr ')'
{ if (FSTRCMP($1,"SUM(") == 0)
$$ = New_Func(lParse, TYPE($2), sum_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"AVERAGE(") == 0)
$$ = New_Func(lParse, DOUBLE, average_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"STDDEV(") == 0)
$$ = New_Func(lParse, DOUBLE, stddev_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"MEDIAN(") == 0)
$$ = New_Func(lParse, TYPE($2), median_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"NELEM(") == 0)
$$ = New_Const(lParse, LONG, &( SIZE($2) ), sizeof(long) );
else if (FSTRCMP($1,"NVALID(") == 0)
$$ = New_Func(lParse, LONG, nonnull_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
else if ((FSTRCMP($1,"ACCUM(") == 0) && (TYPE($2) == LONG)) {
long zero = 0;
$$ = New_BinOp(lParse, LONG , $2, ACCUM, New_Const(lParse, LONG, &zero, sizeof(zero) ));
} else if ((FSTRCMP($1,"ACCUM(") == 0) && (TYPE($2) == DOUBLE)) {
double zero = 0;
$$ = New_BinOp(lParse, DOUBLE , $2, ACCUM, New_Const(lParse, DOUBLE, &zero, sizeof(zero) ));
} else if ((FSTRCMP($1,"SEQDIFF(") == 0) && (TYPE($2) == LONG)) {
long zero = 0;
$$ = New_BinOp(lParse, LONG , $2, DIFF, New_Const(lParse, LONG, &zero, sizeof(zero) ));
} else if ((FSTRCMP($1,"SEQDIFF(") == 0) && (TYPE($2) == DOUBLE)) {
double zero = 0;
$$ = New_BinOp(lParse, DOUBLE , $2, DIFF, New_Const(lParse, DOUBLE, &zero, sizeof(zero) ));
} else if (FSTRCMP($1,"ABS(") == 0)
$$ = New_Func(lParse, 0, abs_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"MIN(") == 0)
$$ = New_Func(lParse, TYPE($2), /* Force 1D result */
min1_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"MAX(") == 0)
$$ = New_Func(lParse, TYPE($2), /* Force 1D result */
max1_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"RANDOM(") == 0) { /* Vector RANDOM() */
$$ = New_Func(lParse, 0, rnd_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
TEST($$);
TYPE($$) = DOUBLE;
} else if (FSTRCMP($1,"RANDOMN(") == 0) {
$$ = New_Func(lParse, 0, gasrnd_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
TEST($$);
TYPE($$) = DOUBLE;
} else if (FSTRCMP($1,"ELEMENTNUM(") == 0) {
if (OPER($2) == CONST_OP) {
long one = 1;
$$ = New_Const(lParse, LONG, &one, sizeof(one) );
} else {
$$ = New_Func(lParse, 0, elemnum_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
TEST($$);
TYPE($$) = LONG;
}
} else if (FSTRCMP($1,"NAXIS(") == 0) { /* NAXIS(V) */
if (OPER($2) == CONST_OP) { /* if V is constant, return 1 in every case */
long one = 1;
$$ = New_Const(lParse, LONG, &one, sizeof(one) );
} else { /* determine now the dimension of the expression */
long naxis = lParse->Nodes[$2].value.naxis;
$$ = New_Const(lParse, LONG, &naxis, sizeof(naxis) );
TEST($$);
}
}
else { /* These all take DOUBLE arguments */
if( TYPE($2) != DOUBLE ) $2 = New_Unary(lParse, DOUBLE, 0, $2 );
if (FSTRCMP($1,"SIN(") == 0)
$$ = New_Func(lParse, 0, sin_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"COS(") == 0)
$$ = New_Func(lParse, 0, cos_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"TAN(") == 0)
$$ = New_Func(lParse, 0, tan_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"ARCSIN(") == 0
|| FSTRCMP($1,"ASIN(") == 0)
$$ = New_Func(lParse, 0, asin_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"ARCCOS(") == 0
|| FSTRCMP($1,"ACOS(") == 0)
$$ = New_Func(lParse, 0, acos_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"ARCTAN(") == 0
|| FSTRCMP($1,"ATAN(") == 0)
$$ = New_Func(lParse, 0, atan_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"SINH(") == 0)
$$ = New_Func(lParse, 0, sinh_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"COSH(") == 0)
$$ = New_Func(lParse, 0, cosh_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"TANH(") == 0)
$$ = New_Func(lParse, 0, tanh_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"EXP(") == 0)
$$ = New_Func(lParse, 0, exp_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"LOG(") == 0)
$$ = New_Func(lParse, 0, log_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"LOG10(") == 0)
$$ = New_Func(lParse, 0, log10_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"SQRT(") == 0)
$$ = New_Func(lParse, 0, sqrt_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"ROUND(") == 0)
$$ = New_Func(lParse, 0, round_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"FLOOR(") == 0)
$$ = New_Func(lParse, 0, floor_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"CEIL(") == 0)
$$ = New_Func(lParse, 0, ceil_fct, 1, $2, 0, 0, 0, 0, 0, 0 );
else if (FSTRCMP($1,"RANDOMP(") == 0) {
$$ = New_Func(lParse, 0, poirnd_fct, 1, $2,
0, 0, 0, 0, 0, 0 );
TYPE($$) = LONG;
} else {
yyerror(scanner, lParse, "Function(expr) not supported");
YYERROR;
}
}
TEST($$);
}
| IFUNCTION sexpr ',' sexpr ')'
{
if (FSTRCMP($1,"STRSTR(") == 0) {
$$ = New_Func(lParse, LONG, strpos_fct, 2, $2, $4, 0,
0, 0, 0, 0 );
TEST($$);
}
}
| FUNCTION expr ',' expr ')'
{
if (FSTRCMP($1,"DEFNULL(") == 0) {
if( SIZE($2)>=SIZE($4) && Test_Dims( lParse, $2, $4 ) ) {
PROMOTE($2,$4);
$$ = New_Func(lParse, 0, defnull_fct, 2, $2, $4, 0,
0, 0, 0, 0 );
TEST($$);
} else {
yyerror(scanner, lParse, "Dimensions of DEFNULL arguments "
"are not compatible");
YYERROR;
}
} else if (FSTRCMP($1,"ARCTAN2(") == 0) {
if( TYPE($2) != DOUBLE ) $2 = New_Unary(lParse, DOUBLE, 0, $2 );
if( TYPE($4) != DOUBLE ) $4 = New_Unary(lParse, DOUBLE, 0, $4 );
if( Test_Dims( lParse, $2, $4 ) ) {
$$ = New_Func(lParse, 0, atan2_fct, 2, $2, $4, 0, 0, 0, 0, 0 );
TEST($$);
if( SIZE($2)<SIZE($4) ) Copy_Dims( lParse,$$, $4);
} else {
yyerror(scanner, lParse, "Dimensions of arctan2 arguments "
"are not compatible");
YYERROR;
}
} else if (FSTRCMP($1,"MIN(") == 0) {
PROMOTE( $2, $4 );
if( Test_Dims( lParse, $2, $4 ) ) {
$$ = New_Func(lParse, 0, min2_fct, 2, $2, $4, 0, 0, 0, 0, 0 );
TEST($$);
if( SIZE($2)<SIZE($4) ) Copy_Dims( lParse,$$, $4);
} else {
yyerror(scanner, lParse, "Dimensions of min(a,b) arguments "
"are not compatible");
YYERROR;
}
} else if (FSTRCMP($1,"MAX(") == 0) {
PROMOTE( $2, $4 );
if( Test_Dims( lParse, $2, $4 ) ) {
$$ = New_Func(lParse, 0, max2_fct, 2, $2, $4, 0, 0, 0, 0, 0 );
TEST($$);
if( SIZE($2)<SIZE($4) ) Copy_Dims( lParse,$$, $4);
} else {
yyerror(scanner, lParse, "Dimensions of max(a,b) arguments "
"are not compatible");
YYERROR;
}
} else if (FSTRCMP($1,"SETNULL(") == 0) {
if (OPER($2) != CONST_OP
|| SIZE($2) != 1) {
yyerror(scanner, lParse, "SETNULL first argument must be a scalar constant");
YYERROR;
}
/* Make sure first arg is same type as second arg */
if ( TYPE($2) != TYPE($4) ) $2 = New_Unary(lParse, TYPE($4), 0, $2 );
$$ = New_Func(lParse, 0, setnull_fct, 2, $4, $2, 0, 0, 0, 0, 0 );
} else if (FSTRCMP($1,"AXISELEM(") == 0) { /* AXISELEM(V,n) */
if (OPER($4) != CONST_OP
|| SIZE($4) != 1) {
yyerror(scanner, lParse, "AXISELEM second argument must be a scalar constant");
YYERROR;
}
if (OPER($2) == CONST_OP) {
long one = 1;
$$ = New_Const(lParse, LONG, &one, sizeof(one) );
} else {
if ( TYPE($4) != LONG ) $4 = New_Unary(lParse, LONG, 0, $4);
$$ = New_Func(lParse, 0, axiselem_fct, 2, $2, $4, 0, 0, 0, 0, 0 );
TEST($$);
TYPE($$) = LONG;
}
} else if (FSTRCMP($1,"NAXES(") == 0) { /* NAXES(V,n) */
if (OPER($4) != CONST_OP
|| SIZE($4) != 1) {
yyerror(scanner, lParse, "NAXES second argument must be a scalar constant");
YYERROR;
}
if (OPER($2) == CONST_OP) { /* if V is constant, return 1 in every case */
long one = 1;
$$ = New_Const(lParse, LONG, &one, sizeof(one) );
} else { /* determine now the dimension of the expression */
long iaxis;
int naxis;
if ( TYPE($4) != LONG ) $4 = New_Unary(lParse, LONG, 0, $4);
/* Since it is already constant, we can extract long value directly */
iaxis = (lParse->Nodes[$4].value.data.lng);
naxis = lParse->Nodes[$2].value.naxis;
if (iaxis == 0) iaxis = naxis; /* NAXIS(V,0) = NAXIS */
else if (iaxis <= naxis) iaxis = lParse->Nodes[$2].value.naxes[iaxis-1]; /* NAXIS(V,n) = NAXISn */
else iaxis = 1; /* Out of bounds use 1 */
$$ = New_Const(lParse, LONG, &iaxis, sizeof(iaxis) );
TEST($$);
}
} else if (FSTRCMP($1,"ARRAY(") == 0) { /* NAXES(expr,n) */
$$ = New_Array(lParse, $2, $4);
TEST($$);
} else {
yyerror(scanner, lParse, "Function(expr,expr) not supported");
YYERROR;
}
}
| FUNCTION expr ',' expr ',' expr ',' expr ')'
{
if (FSTRCMP($1,"ANGSEP(") == 0) {
if( TYPE($2) != DOUBLE ) $2 = New_Unary(lParse, DOUBLE, 0, $2 );
if( TYPE($4) != DOUBLE ) $4 = New_Unary(lParse, DOUBLE, 0, $4 );
if( TYPE($6) != DOUBLE ) $6 = New_Unary(lParse, DOUBLE, 0, $6 );
if( TYPE($8) != DOUBLE ) $8 = New_Unary(lParse, DOUBLE, 0, $8 );
if( Test_Dims( lParse, $2, $4 ) && Test_Dims( lParse, $4, $6 ) &&
Test_Dims( lParse, $6, $8 ) ) {
$$ = New_Func(lParse, 0, angsep_fct, 4, $2, $4, $6, $8,0,0,0 );
TEST($$);
if( SIZE($2)<SIZE($4) ) Copy_Dims( lParse,$$, $4);
if( SIZE($4)<SIZE($6) ) Copy_Dims( lParse,$$, $6);
if( SIZE($6)<SIZE($8) ) Copy_Dims( lParse,$$, $8);
} else {
yyerror(scanner, lParse, "Dimensions of ANGSEP arguments "
"are not compatible");
YYERROR;
}
} else {
yyerror(scanner, lParse, "Function(expr,expr,expr,expr) not supported");
YYERROR;
}
}
| GTIOVERLAP STRING ',' expr ',' expr ')'
{ $$ = New_GTI(lParse, gtiover_fct, $2, $4, $6, "*START*", "*STOP*");
TEST($$); }
| GTIOVERLAP STRING ',' expr ',' expr ',' STRING ',' STRING ')'
{ $$ = New_GTI(lParse, gtiover_fct, $2, $4, $6, $8, $10 );
TEST($$); }
| expr '[' expr ']'
{ $$ = New_Deref(lParse, $1, 1, $3, 0, 0, 0, 0 ); TEST($$); }
| expr '[' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 2, $3, $5, 0, 0, 0 ); TEST($$); }
| expr '[' expr ',' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 3, $3, $5, $7, 0, 0 ); TEST($$); }
| expr '[' expr ',' expr ',' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 4, $3, $5, $7, $9, 0 ); TEST($$); }
| expr '[' expr ',' expr ',' expr ',' expr ',' expr ']'
{ $$ = New_Deref(lParse, $1, 5, $3, $5, $7, $9, $11 ); TEST($$); }
| INTCAST expr
{ $$ = New_Unary(lParse, LONG, INTCAST, $2 ); TEST($$); }
| INTCAST bexpr
{ $$ = New_Unary(lParse, LONG, INTCAST, $2 ); TEST($$); }
| FLTCAST expr
{ $$ = New_Unary(lParse, DOUBLE, FLTCAST, $2 ); TEST($$); }
| FLTCAST bexpr
{ $$ = New_Unary(lParse, DOUBLE, FLTCAST, $2 ); TEST($$); }
;
bexpr: BOOLEAN
{ $$ = New_Const(lParse, BOOLEAN, &($1), sizeof(char) ); TEST($$); }
| BCOLUMN
{ $$ = New_Column(lParse, $1 ); TEST($$); }
| BCOLUMN '{' expr '}'
{
if( TYPE($3) != LONG
|| OPER($3) != CONST_OP ) {
yyerror(scanner, lParse, "Offset argument must be a constant integer");
YYERROR;
}
$$ = New_Offset(lParse, $1, $3 ); TEST($$);
}
| bits EQ bits
{ $$ = New_BinOp(lParse, BOOLEAN, $1, EQ, $3 ); TEST($$);
SIZE($$) = 1; }
| bits NE bits
{ $$ = New_BinOp(lParse, BOOLEAN, $1, NE, $3 ); TEST($$);
SIZE($$) = 1; }
| bits LT bits
{ $$ = New_BinOp(lParse, BOOLEAN, $1, LT, $3 ); TEST($$);
SIZE($$) = 1; }
| bits LTE bits
{ $$ = New_BinOp(lParse, BOOLEAN, $1, LTE, $3 ); TEST($$);
SIZE($$) = 1; }
| bits GT bits
{ $$ = New_BinOp(lParse, BOOLEAN, $1, GT, $3 ); TEST($$);
SIZE($$) = 1; }
| bits GTE bits
{ $$ = New_BinOp(lParse, BOOLEAN, $1, GTE, $3 ); TEST($$);
SIZE($$) = 1; }
| expr GT expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, BOOLEAN, $1, GT, $3 );
TEST($$); }
| expr LT expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, BOOLEAN, $1, LT, $3 );
TEST($$); }
| expr GTE expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, BOOLEAN, $1, GTE, $3 );
TEST($$); }
| expr LTE expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, BOOLEAN, $1, LTE, $3 );
TEST($$); }
| expr '~' expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, BOOLEAN, $1, '~', $3 );
TEST($$); }
| expr EQ expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, BOOLEAN, $1, EQ, $3 );
TEST($$); }
| expr NE expr
{ PROMOTE($1,$3); $$ = New_BinOp(lParse, BOOLEAN, $1, NE, $3 );
TEST($$); }
| sexpr EQ sexpr
{ $$ = New_BinOp(lParse, BOOLEAN, $1, EQ, $3 ); TEST($$);
SIZE($$) = 1; }
| sexpr NE sexpr
{ $$ = New_BinOp(lParse, BOOLEAN, $1, NE, $3 ); TEST($$);
SIZE($$) = 1; }
| sexpr GT sexpr
{ $$ = New_BinOp(lParse, BOOLEAN, $1, GT, $3 ); TEST($$);
SIZE($$) = 1; }
| sexpr GTE sexpr
{ $$ = New_BinOp(lParse, BOOLEAN, $1, GTE, $3 ); TEST($$);