1 /* A recursive-descent parser generated by peg 0.1.2 */
18 /* TBD: use separate function to parse dates differently */
20 make_number (char *text
)
22 value_t
*tmp
= malloc(sizeof(*tmp
));
26 tmp
->as_num
= strtoll(text
,NULL
,10);
33 make_string (char *text
, type_t t
)
35 value_t
*tmp
= malloc(sizeof(*tmp
));
39 tmp
->as_str
= strdup(text
);
46 make_tree (type_t t
, value_t
*left
, value_t
*right
)
48 value_t
*tmp
= malloc(sizeof(*tmp
));
52 tmp
->as_tree
.left
= left
;
53 tmp
->as_tree
.right
= right
;
60 make_comp (comp_t c
, value_t
*left
, value_t
*right
)
62 value_t
*tmp
= make_tree(T_COMP
,left
,right
);
71 #if defined(UNIT_TEST)
72 struct { char *name
; char *value
; } hacked_obj_fields
[] = {
73 { "a", "2" }, { "b", "7" }, { "c", "11" },
78 unit_oget (char *text
)
82 for (i
= 0; hacked_obj_fields
[i
].name
; ++i
) {
83 if (!strcmp(hacked_obj_fields
[i
].name
,text
)) {
84 return hacked_obj_fields
[i
].value
;
92 unit_sget (char *text
)
99 string_value (value_t
*v
, getter_t
*oget
, getter_t
*sget
)
105 return oget
? (*oget
)(v
->as_str
) : "";
107 return oget
? (*sget
)(v
->as_str
) : "";
114 compare (value_t
*left
, comp_t op
, value_t
*right
,
115 getter_t
*oget
, getter_t
*sget
)
122 lstr
= string_value(left
,oget
,sget
);
123 rstr
= string_value(right
,oget
,sget
);
126 lval
= strcmp(lstr
,rstr
);
131 lval
= strtoll(lstr
,NULL
,0);
133 else if (left
->type
== T_NUMBER
) {
137 lval
= eval(left
,oget
,sget
);
143 rval
= strtoll(rstr
,NULL
,0);
145 else if (right
->type
== T_NUMBER
) {
146 rval
= right
->as_num
;
149 rval
= eval(right
,oget
,sget
);
157 case C_LESSTHAN
: return (lval
< rval
);
158 case C_LESSOREQ
: return (lval
<= rval
);
159 case C_EQUAL
: return (lval
== rval
);
160 case C_DIFFERENT
: return (lval
!= rval
);
161 case C_GREATEROREQ
: return (lval
>= rval
);
162 case C_GREATERTHAN
: return (lval
> rval
);
169 _print_value (value_t
*v
, int level
)
172 printf("%*sNULL\n",level
,"");
178 printf("%*sNUMBER %lld\n",level
,"",v
->as_num
);
181 printf("%*sSTRING %s\n",level
,"",v
->as_str
);
184 #if defined(UNIT_TEST)
185 printf("%*sOBJECT FIELD %s (%s)\n",level
,"",v
->as_str
,
186 unit_oget(v
->as_str
));
188 printf("%*sOBJECT FIELD %s\n",level
,"",v
->as_str
);
192 #if defined(UNIT_TEST)
193 printf("%*sSERVER FIELD %s (%s)\n",level
,"",v
->as_str
,
194 unit_sget(v
->as_str
));
196 printf("%*sSERVER FIELD %s\n",level
,"",v
->as_str
);
200 printf("%*sCOMPARISON (%d)\n",level
,"",v
->as_num
);
201 _print_value(v
->as_tree
.left
,level
+2);
202 _print_value(v
->as_tree
.right
,level
+2);
205 printf("%*sNOT\n",level
,"");
206 _print_value(v
->as_tree
.left
,level
+2);
209 printf("%*sAND\n",level
,"");
210 _print_value(v
->as_tree
.left
,level
+2);
211 _print_value(v
->as_tree
.right
,level
+2);
214 printf("%*sOR\n",level
,"");
215 _print_value(v
->as_tree
.left
,level
+2);
216 _print_value(v
->as_tree
.right
,level
+2);
219 printf("%*sUNKNOWN %d\n",v
->type
,level
,"");
224 print_value (value_t
*v
)
230 free_value (value_t
*v
)
247 free_value(v
->as_tree
.right
);
250 free_value(v
->as_tree
.left
);
258 eval (value_t
*v
, getter_t
*oget
, getter_t
*sget
)
264 return v
->as_num
!= 0;
270 return compare(v
->as_tree
.left
,(comp_t
)v
->as_tree
.op
,
271 v
->as_tree
.right
, oget
, sget
);
273 res
= eval(v
->as_tree
.left
,oget
,sget
);
274 return (res
>= 0) ? !res
: res
;
276 res
= eval(v
->as_tree
.left
,oget
,sget
);
278 res
= eval(v
->as_tree
.right
,oget
,sget
);
282 res
= eval(v
->as_tree
.left
,oget
,sget
);
286 return eval(v
->as_tree
.right
,oget
,sget
);
292 #define YY_INPUT(buf,result,max) { \
293 result = (arg_off < arg_len) ? (*buf = arg_buf[arg_off++], 1) \
294 : (arg_off == arg_len) ? (*buf = '\n', ++arg_off, 1) : 0; \
297 #define YYSTYPE value_t *
300 #define YY_VARIABLE(T) static T
303 #define YY_LOCAL(T) static T
306 #define YY_ACTION(T) static T
309 #define YY_RULE(T) static T
312 #define YY_PARSE(T) T
315 #define YYPARSE yyparse
318 #define YYPARSEFROM yyparsefrom
321 #define YY_INPUT(buf, result, max_size) \
323 int yyc= getchar(); \
324 result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
325 yyprintf((stderr, "<%c>", yyc)); \
329 #define YY_BEGIN ( yybegin= yypos, 1)
332 #define YY_END ( yyend= yypos, 1)
335 # define yyprintf(args) fprintf args
337 # define yyprintf(args)
345 typedef void (*yyaction
)(char *yytext
, int yyleng
);
346 typedef struct _yythunk
{ int begin
, end
; yyaction action
; struct _yythunk
*next
; } yythunk
;
348 YY_VARIABLE(char * ) yybuf
= 0;
349 YY_VARIABLE(int ) yybuflen
= 0;
350 YY_VARIABLE(int ) yypos
= 0;
351 YY_VARIABLE(int ) yylimit
= 0;
352 YY_VARIABLE(char * ) yytext
= 0;
353 YY_VARIABLE(int ) yytextlen
= 0;
354 YY_VARIABLE(int ) yybegin
= 0;
355 YY_VARIABLE(int ) yyend
= 0;
356 YY_VARIABLE(int ) yytextmax
= 0;
357 YY_VARIABLE(yythunk
*) yythunks
= 0;
358 YY_VARIABLE(int ) yythunkslen
= 0;
359 YY_VARIABLE(int ) yythunkpos
= 0;
360 YY_VARIABLE(YYSTYPE
) yy
;
361 YY_VARIABLE(YYSTYPE
*) yyval
= 0;
362 YY_VARIABLE(YYSTYPE
*) yyvals
= 0;
363 YY_VARIABLE(int ) yyvalslen
= 0;
365 YY_LOCAL(int) yyrefill(void)
368 while (yybuflen
- yypos
< 512)
371 yybuf
= realloc(yybuf
, yybuflen
);
373 YY_INPUT((yybuf
+ yypos
), yyn
, (yybuflen
- yypos
));
379 YY_LOCAL(int) yymatchDot(void)
381 if (yypos
>= yylimit
&& !yyrefill()) return 0;
386 YY_LOCAL(int) yymatchChar(int c
)
388 if (yypos
>= yylimit
&& !yyrefill()) return 0;
389 if (yybuf
[yypos
] == c
)
392 yyprintf((stderr
, " ok yymatchChar(%c) @ %s\n", c
, yybuf
+yypos
));
395 yyprintf((stderr
, " fail yymatchChar(%c) @ %s\n", c
, yybuf
+yypos
));
399 YY_LOCAL(int) yymatchString(char *s
)
404 if (yypos
>= yylimit
&& !yyrefill()) return 0;
405 if (yybuf
[yypos
] != *s
)
416 YY_LOCAL(int) yymatchClass(unsigned char *bits
)
419 if (yypos
>= yylimit
&& !yyrefill()) return 0;
421 if (bits
[c
>> 3] & (1 << (c
& 7)))
424 yyprintf((stderr
, " ok yymatchClass @ %s\n", yybuf
+yypos
));
427 yyprintf((stderr
, " fail yymatchClass @ %s\n", yybuf
+yypos
));
431 YY_LOCAL(void) yyDo(yyaction action
, int begin
, int end
)
433 while (yythunkpos
>= yythunkslen
)
436 yythunks
= realloc(yythunks
, sizeof(yythunk
) * yythunkslen
);
438 yythunks
[yythunkpos
].begin
= begin
;
439 yythunks
[yythunkpos
].end
= end
;
440 yythunks
[yythunkpos
].action
= action
;
444 YY_LOCAL(int) yyText(int begin
, int end
)
446 int yyleng
= end
- begin
;
451 while (yytextlen
< (yyleng
- 1))
454 yytext
= realloc(yytext
, yytextlen
);
456 memcpy(yytext
, yybuf
+ begin
, yyleng
);
458 yytext
[yyleng
]= '\0';
462 YY_LOCAL(void) yyDone(void)
465 for (pos
= 0; pos
< yythunkpos
; ++pos
)
467 yythunk
*thunk
= &yythunks
[pos
];
468 int yyleng
= thunk
->end
? yyText(thunk
->begin
, thunk
->end
) : thunk
->begin
;
469 yyprintf((stderr
, "DO [%d] %p %s\n", pos
, thunk
->action
, yytext
));
470 thunk
->action(yytext
, yyleng
);
475 YY_LOCAL(void) yyCommit()
477 if ((yylimit
-= yypos
))
479 memmove(yybuf
, yybuf
+ yypos
, yylimit
);
483 yypos
= yythunkpos
= 0;
486 YY_LOCAL(int) yyAccept(int tp0
)
490 fprintf(stderr
, "accept denied at %d\n", tp0
);
501 YY_LOCAL(void) yyPush(char *text
, int count
) { yyval
+= count
; }
502 YY_LOCAL(void) yyPop(char *text
, int count
) { yyval
-= count
; }
503 YY_LOCAL(void) yySet(char *text
, int count
) { yyval
[count
]= yy
; }
507 #define YYACCEPT yyAccept(yythunkpos0)
509 YY_RULE(int) yy_CLOSE(); /* 24 */
510 YY_RULE(int) yy_OPEN(); /* 23 */
511 YY_RULE(int) yy_WAFFLE(); /* 22 */
512 YY_RULE(int) yy_ID(); /* 21 */
513 YY_RULE(int) yy_DOLLAR(); /* 20 */
514 YY_RULE(int) yy_TIME(); /* 19 */
515 YY_RULE(int) yy_STRING(); /* 18 */
516 YY_RULE(int) yy_NUMBER(); /* 17 */
517 YY_RULE(int) yy_ParenExpr(); /* 16 */
518 YY_RULE(int) yy_Field(); /* 15 */
519 YY_RULE(int) yy_Literal(); /* 14 */
520 YY_RULE(int) yy_Atom(); /* 13 */
521 YY_RULE(int) yy_GREATER(); /* 12 */
522 YY_RULE(int) yy_NOT(); /* 11 */
523 YY_RULE(int) yy_EQUAL(); /* 10 */
524 YY_RULE(int) yy_LESS(); /* 9 */
525 YY_RULE(int) yy_Unary(); /* 8 */
526 YY_RULE(int) yy_OR(); /* 7 */
527 YY_RULE(int) yy_AND(); /* 6 */
528 YY_RULE(int) yy_CompExpr(); /* 5 */
529 YY_RULE(int) yy_EOL(); /* 4 */
530 YY_RULE(int) yy_BoolExpr(); /* 3 */
531 YY_RULE(int) yy__(); /* 2 */
532 YY_RULE(int) yy_Stmt(); /* 1 */
534 YY_ACTION(void) yy_1_ID(char *yytext
, int yyleng
)
536 yyprintf((stderr
, "do yy_1_ID\n"));
537 yy
= (YYSTYPE
)yytext
; ;
539 YY_ACTION(void) yy_1_TIME(char *yytext
, int yyleng
)
541 yyprintf((stderr
, "do yy_1_TIME\n"));
542 yy
= make_number(yytext
); ;
544 YY_ACTION(void) yy_1_STRING(char *yytext
, int yyleng
)
546 yyprintf((stderr
, "do yy_1_STRING\n"));
547 yy
= make_string(yytext
,T_STRING
); ;
549 YY_ACTION(void) yy_1_NUMBER(char *yytext
, int yyleng
)
551 yyprintf((stderr
, "do yy_1_NUMBER\n"));
552 yy
= make_number(yytext
); ;
554 YY_ACTION(void) yy_1_ParenExpr(char *yytext
, int yyleng
)
557 yyprintf((stderr
, "do yy_1_ParenExpr\n"));
561 YY_ACTION(void) yy_2_Field(char *yytext
, int yyleng
)
564 yyprintf((stderr
, "do yy_2_Field\n"));
565 yy
= make_string((char *)yy
,T_SFIELD
); ;
568 YY_ACTION(void) yy_1_Field(char *yytext
, int yyleng
)
571 yyprintf((stderr
, "do yy_1_Field\n"));
572 yy
= make_string((char *)yy
,T_OFIELD
); ;
575 YY_ACTION(void) yy_2_Unary(char *yytext
, int yyleng
)
578 yyprintf((stderr
, "do yy_2_Unary\n"));
579 yy
= make_tree(T_NOT
,e
,NULL
); ;
582 YY_ACTION(void) yy_1_Unary(char *yytext
, int yyleng
)
585 yyprintf((stderr
, "do yy_1_Unary\n"));
586 yy
= make_tree(T_NOT
,e
,NULL
); ;
589 YY_ACTION(void) yy_6_CompExpr(char *yytext
, int yyleng
)
593 yyprintf((stderr
, "do yy_6_CompExpr\n"));
594 yy
= make_comp(C_GREATERTHAN
,l
,r
); ;
598 YY_ACTION(void) yy_5_CompExpr(char *yytext
, int yyleng
)
602 yyprintf((stderr
, "do yy_5_CompExpr\n"));
603 yy
= make_comp(C_GREATEROREQ
,l
,r
); ;
607 YY_ACTION(void) yy_4_CompExpr(char *yytext
, int yyleng
)
611 yyprintf((stderr
, "do yy_4_CompExpr\n"));
612 yy
= make_comp(C_DIFFERENT
,l
,r
); ;
616 YY_ACTION(void) yy_3_CompExpr(char *yytext
, int yyleng
)
620 yyprintf((stderr
, "do yy_3_CompExpr\n"));
621 yy
= make_comp(C_EQUAL
,l
,r
); ;
625 YY_ACTION(void) yy_2_CompExpr(char *yytext
, int yyleng
)
629 yyprintf((stderr
, "do yy_2_CompExpr\n"));
630 yy
= make_comp(C_LESSOREQ
,l
,r
); ;
634 YY_ACTION(void) yy_1_CompExpr(char *yytext
, int yyleng
)
638 yyprintf((stderr
, "do yy_1_CompExpr\n"));
639 yy
= make_comp(C_LESSTHAN
,l
,r
); ;
643 YY_ACTION(void) yy_2_BoolExpr(char *yytext
, int yyleng
)
647 yyprintf((stderr
, "do yy_2_BoolExpr\n"));
648 yy
= make_tree(T_OR
,l
,r
); ;
652 YY_ACTION(void) yy_1_BoolExpr(char *yytext
, int yyleng
)
656 yyprintf((stderr
, "do yy_1_BoolExpr\n"));
657 yy
= make_tree(T_AND
,l
,r
); ;
661 YY_ACTION(void) yy_1_Stmt(char *yytext
, int yyleng
)
663 yyprintf((stderr
, "do yy_1_Stmt\n"));
667 YY_RULE(int) yy_CLOSE()
668 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
669 yyprintf((stderr
, "%s\n", "CLOSE")); if (!yymatchChar(')')) goto l1
;
670 yyprintf((stderr
, " ok %s @ %s\n", "CLOSE", yybuf
+yypos
));
672 l1
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
673 yyprintf((stderr
, " fail %s @ %s\n", "CLOSE", yybuf
+yypos
));
676 YY_RULE(int) yy_OPEN()
677 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
678 yyprintf((stderr
, "%s\n", "OPEN")); if (!yymatchChar('(')) goto l2
;
679 yyprintf((stderr
, " ok %s @ %s\n", "OPEN", yybuf
+yypos
));
681 l2
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
682 yyprintf((stderr
, " fail %s @ %s\n", "OPEN", yybuf
+yypos
));
685 YY_RULE(int) yy_WAFFLE()
686 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
687 yyprintf((stderr
, "%s\n", "WAFFLE")); if (!yymatchChar('#')) goto l3
;
688 yyprintf((stderr
, " ok %s @ %s\n", "WAFFLE", yybuf
+yypos
));
690 l3
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
691 yyprintf((stderr
, " fail %s @ %s\n", "WAFFLE", yybuf
+yypos
));
695 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
696 yyprintf((stderr
, "%s\n", "ID")); yyText(yybegin
, yyend
); if (!(YY_BEGIN
)) goto l4
; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\000\000\000\000\000\200\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l4
;
698 { int yypos6
= yypos
, yythunkpos6
= yythunkpos
; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\000\000\000\000\000\200\376\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l6
; goto l5
;
699 l6
:; yypos
= yypos6
; yythunkpos
= yythunkpos6
;
700 } yyText(yybegin
, yyend
); if (!(YY_END
)) goto l4
; yyDo(yy_1_ID
, yybegin
, yyend
);
701 yyprintf((stderr
, " ok %s @ %s\n", "ID", yybuf
+yypos
));
703 l4
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
704 yyprintf((stderr
, " fail %s @ %s\n", "ID", yybuf
+yypos
));
707 YY_RULE(int) yy_DOLLAR()
708 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
709 yyprintf((stderr
, "%s\n", "DOLLAR")); if (!yymatchChar('$')) goto l7
;
710 yyprintf((stderr
, " ok %s @ %s\n", "DOLLAR", yybuf
+yypos
));
712 l7
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
713 yyprintf((stderr
, " fail %s @ %s\n", "DOLLAR", yybuf
+yypos
));
716 YY_RULE(int) yy_TIME()
717 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
718 yyprintf((stderr
, "%s\n", "TIME")); if (!yymatchChar('~')) goto l8
; yyText(yybegin
, yyend
); if (!(YY_BEGIN
)) goto l8
;
720 { int yypos10
= yypos
, yythunkpos10
= yythunkpos
; if (!yymatchClass((unsigned char *)"\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\277\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377")) goto l10
; goto l9
;
721 l10
:; yypos
= yypos10
; yythunkpos
= yythunkpos10
;
722 } yyText(yybegin
, yyend
); if (!(YY_END
)) goto l8
; if (!yymatchChar('~')) goto l8
; yyDo(yy_1_TIME
, yybegin
, yyend
);
723 yyprintf((stderr
, " ok %s @ %s\n", "TIME", yybuf
+yypos
));
725 l8
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
726 yyprintf((stderr
, " fail %s @ %s\n", "TIME", yybuf
+yypos
));
729 YY_RULE(int) yy_STRING()
730 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
731 yyprintf((stderr
, "%s\n", "STRING")); if (!yymatchChar('"')) goto l11
; yyText(yybegin
, yyend
); if (!(YY_BEGIN
)) goto l11
;
733 { int yypos13
= yypos
, yythunkpos13
= yythunkpos
; if (!yymatchClass((unsigned char *)"\377\377\377\377\373\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377")) goto l13
; goto l12
;
734 l13
:; yypos
= yypos13
; yythunkpos
= yythunkpos13
;
735 } yyText(yybegin
, yyend
); if (!(YY_END
)) goto l11
; if (!yymatchChar('"')) goto l11
; yyDo(yy_1_STRING
, yybegin
, yyend
);
736 yyprintf((stderr
, " ok %s @ %s\n", "STRING", yybuf
+yypos
));
738 l11
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
739 yyprintf((stderr
, " fail %s @ %s\n", "STRING", yybuf
+yypos
));
742 YY_RULE(int) yy_NUMBER()
743 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
744 yyprintf((stderr
, "%s\n", "NUMBER")); yyText(yybegin
, yyend
); if (!(YY_BEGIN
)) goto l14
; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l14
;
746 { int yypos16
= yypos
, yythunkpos16
= yythunkpos
; if (!yymatchClass((unsigned char *)"\000\000\000\000\000\000\377\003\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l16
; goto l15
;
747 l16
:; yypos
= yypos16
; yythunkpos
= yythunkpos16
;
748 } yyText(yybegin
, yyend
); if (!(YY_END
)) goto l14
; yyDo(yy_1_NUMBER
, yybegin
, yyend
);
749 yyprintf((stderr
, " ok %s @ %s\n", "NUMBER", yybuf
+yypos
));
751 l14
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
752 yyprintf((stderr
, " fail %s @ %s\n", "NUMBER", yybuf
+yypos
));
755 YY_RULE(int) yy_ParenExpr()
756 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
; yyDo(yyPush
, 1, 0);
757 yyprintf((stderr
, "%s\n", "ParenExpr")); if (!yy_OPEN()) goto l17
; if (!yy_BoolExpr()) goto l17
; yyDo(yySet
, -1, 0); if (!yy_CLOSE()) goto l17
; if (!yy__()) goto l17
; yyDo(yy_1_ParenExpr
, yybegin
, yyend
);
758 yyprintf((stderr
, " ok %s @ %s\n", "ParenExpr", yybuf
+yypos
)); yyDo(yyPop
, 1, 0);
760 l17
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
761 yyprintf((stderr
, " fail %s @ %s\n", "ParenExpr", yybuf
+yypos
));
764 YY_RULE(int) yy_Field()
765 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
; yyDo(yyPush
, 1, 0);
766 yyprintf((stderr
, "%s\n", "Field"));
767 { int yypos19
= yypos
, yythunkpos19
= yythunkpos
; if (!yy_DOLLAR()) goto l20
; if (!yy_ID()) goto l20
; yyDo(yySet
, -1, 0); yyDo(yy_1_Field
, yybegin
, yyend
); goto l19
;
768 l20
:; yypos
= yypos19
; yythunkpos
= yythunkpos19
; if (!yy_WAFFLE()) goto l18
; if (!yy_ID()) goto l18
; yyDo(yySet
, -1, 0); yyDo(yy_2_Field
, yybegin
, yyend
);
771 yyprintf((stderr
, " ok %s @ %s\n", "Field", yybuf
+yypos
)); yyDo(yyPop
, 1, 0);
773 l18
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
774 yyprintf((stderr
, " fail %s @ %s\n", "Field", yybuf
+yypos
));
777 YY_RULE(int) yy_Literal()
778 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
779 yyprintf((stderr
, "%s\n", "Literal"));
780 { int yypos22
= yypos
, yythunkpos22
= yythunkpos
; if (!yy_NUMBER()) goto l23
; goto l22
;
781 l23
:; yypos
= yypos22
; yythunkpos
= yythunkpos22
; if (!yy_STRING()) goto l24
; goto l22
;
782 l24
:; yypos
= yypos22
; yythunkpos
= yythunkpos22
; if (!yy_TIME()) goto l21
;
785 yyprintf((stderr
, " ok %s @ %s\n", "Literal", yybuf
+yypos
));
787 l21
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
788 yyprintf((stderr
, " fail %s @ %s\n", "Literal", yybuf
+yypos
));
791 YY_RULE(int) yy_Atom()
792 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
793 yyprintf((stderr
, "%s\n", "Atom"));
794 { int yypos26
= yypos
, yythunkpos26
= yythunkpos
; if (!yy_Literal()) goto l27
; goto l26
;
795 l27
:; yypos
= yypos26
; yythunkpos
= yythunkpos26
; if (!yy_Field()) goto l28
; goto l26
;
796 l28
:; yypos
= yypos26
; yythunkpos
= yythunkpos26
; if (!yy_ParenExpr()) goto l25
;
798 l26
:; if (!yy__()) goto l25
;
799 yyprintf((stderr
, " ok %s @ %s\n", "Atom", yybuf
+yypos
));
801 l25
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
802 yyprintf((stderr
, " fail %s @ %s\n", "Atom", yybuf
+yypos
));
805 YY_RULE(int) yy_GREATER()
806 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
807 yyprintf((stderr
, "%s\n", "GREATER")); if (!yymatchChar('>')) goto l29
;
808 yyprintf((stderr
, " ok %s @ %s\n", "GREATER", yybuf
+yypos
));
810 l29
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
811 yyprintf((stderr
, " fail %s @ %s\n", "GREATER", yybuf
+yypos
));
814 YY_RULE(int) yy_NOT()
815 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
816 yyprintf((stderr
, "%s\n", "NOT")); if (!yymatchChar('!')) goto l30
;
817 yyprintf((stderr
, " ok %s @ %s\n", "NOT", yybuf
+yypos
));
819 l30
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
820 yyprintf((stderr
, " fail %s @ %s\n", "NOT", yybuf
+yypos
));
823 YY_RULE(int) yy_EQUAL()
824 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
825 yyprintf((stderr
, "%s\n", "EQUAL")); if (!yymatchChar('=')) goto l31
;
826 yyprintf((stderr
, " ok %s @ %s\n", "EQUAL", yybuf
+yypos
));
828 l31
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
829 yyprintf((stderr
, " fail %s @ %s\n", "EQUAL", yybuf
+yypos
));
832 YY_RULE(int) yy_LESS()
833 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
834 yyprintf((stderr
, "%s\n", "LESS")); if (!yymatchChar('<')) goto l32
;
835 yyprintf((stderr
, " ok %s @ %s\n", "LESS", yybuf
+yypos
));
837 l32
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
838 yyprintf((stderr
, " fail %s @ %s\n", "LESS", yybuf
+yypos
));
841 YY_RULE(int) yy_Unary()
842 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
; yyDo(yyPush
, 1, 0);
843 yyprintf((stderr
, "%s\n", "Unary"));
844 { int yypos34
= yypos
, yythunkpos34
= yythunkpos
; if (!yy_Atom()) goto l35
; goto l34
;
845 l35
:; yypos
= yypos34
; yythunkpos
= yythunkpos34
; if (!yy_NOT()) goto l36
; if (!yy__()) goto l36
; if (!yy_Atom()) goto l36
; yyDo(yySet
, -1, 0); if (!yy__()) goto l36
; yyDo(yy_1_Unary
, yybegin
, yyend
); goto l34
;
846 l36
:; yypos
= yypos34
; yythunkpos
= yythunkpos34
; if (!yy_NOT()) goto l33
; if (!yy__()) goto l33
; if (!yy_Unary()) goto l33
; yyDo(yySet
, -1, 0); if (!yy__()) goto l33
; yyDo(yy_2_Unary
, yybegin
, yyend
);
849 yyprintf((stderr
, " ok %s @ %s\n", "Unary", yybuf
+yypos
)); yyDo(yyPop
, 1, 0);
851 l33
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
852 yyprintf((stderr
, " fail %s @ %s\n", "Unary", yybuf
+yypos
));
856 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
857 yyprintf((stderr
, "%s\n", "OR")); if (!yymatchString("||")) goto l37
;
858 yyprintf((stderr
, " ok %s @ %s\n", "OR", yybuf
+yypos
));
860 l37
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
861 yyprintf((stderr
, " fail %s @ %s\n", "OR", yybuf
+yypos
));
864 YY_RULE(int) yy_AND()
865 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
866 yyprintf((stderr
, "%s\n", "AND")); if (!yymatchString("&&")) goto l38
;
867 yyprintf((stderr
, " ok %s @ %s\n", "AND", yybuf
+yypos
));
869 l38
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
870 yyprintf((stderr
, " fail %s @ %s\n", "AND", yybuf
+yypos
));
873 YY_RULE(int) yy_CompExpr()
874 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
; yyDo(yyPush
, 2, 0);
875 yyprintf((stderr
, "%s\n", "CompExpr")); if (!yy_Unary()) goto l39
; yyDo(yySet
, -2, 0);
876 { int yypos40
= yypos
, yythunkpos40
= yythunkpos
;
877 { int yypos42
= yypos
, yythunkpos42
= yythunkpos
; if (!yy_LESS()) goto l43
; if (!yy__()) goto l43
; if (!yy_Unary()) goto l43
; yyDo(yySet
, -1, 0); yyDo(yy_1_CompExpr
, yybegin
, yyend
); goto l42
;
878 l43
:; yypos
= yypos42
; yythunkpos
= yythunkpos42
; if (!yy_LESS()) goto l44
; if (!yy_EQUAL()) goto l44
; if (!yy__()) goto l44
; if (!yy_Unary()) goto l44
; yyDo(yySet
, -1, 0); yyDo(yy_2_CompExpr
, yybegin
, yyend
); goto l42
;
879 l44
:; yypos
= yypos42
; yythunkpos
= yythunkpos42
; if (!yy_EQUAL()) goto l45
; if (!yy_EQUAL()) goto l45
; if (!yy__()) goto l45
; if (!yy_Unary()) goto l45
; yyDo(yySet
, -1, 0); yyDo(yy_3_CompExpr
, yybegin
, yyend
); goto l42
;
880 l45
:; yypos
= yypos42
; yythunkpos
= yythunkpos42
; if (!yy_NOT()) goto l46
; if (!yy_EQUAL()) goto l46
; if (!yy__()) goto l46
; if (!yy_Unary()) goto l46
; yyDo(yySet
, -1, 0); yyDo(yy_4_CompExpr
, yybegin
, yyend
); goto l42
;
881 l46
:; yypos
= yypos42
; yythunkpos
= yythunkpos42
; if (!yy_GREATER()) goto l47
; if (!yy_EQUAL()) goto l47
; if (!yy__()) goto l47
; if (!yy_Unary()) goto l47
; yyDo(yySet
, -1, 0); yyDo(yy_5_CompExpr
, yybegin
, yyend
); goto l42
;
882 l47
:; yypos
= yypos42
; yythunkpos
= yythunkpos42
; if (!yy_GREATER()) goto l40
; if (!yy__()) goto l40
; if (!yy_Unary()) goto l40
; yyDo(yySet
, -1, 0); yyDo(yy_6_CompExpr
, yybegin
, yyend
);
885 l40
:; yypos
= yypos40
; yythunkpos
= yythunkpos40
;
887 l41
:; if (!yy__()) goto l39
;
888 yyprintf((stderr
, " ok %s @ %s\n", "CompExpr", yybuf
+yypos
)); yyDo(yyPop
, 2, 0);
890 l39
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
891 yyprintf((stderr
, " fail %s @ %s\n", "CompExpr", yybuf
+yypos
));
894 YY_RULE(int) yy_EOL()
895 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
896 yyprintf((stderr
, "%s\n", "EOL"));
897 { int yypos49
= yypos
, yythunkpos49
= yythunkpos
; if (!yymatchChar('\n')) goto l50
; goto l49
;
898 l50
:; yypos
= yypos49
; yythunkpos
= yythunkpos49
; if (!yymatchString("\r\n")) goto l51
; goto l49
;
899 l51
:; yypos
= yypos49
; yythunkpos
= yythunkpos49
; if (!yymatchChar('\r')) goto l52
; goto l49
;
900 l52
:; yypos
= yypos49
; yythunkpos
= yythunkpos49
; if (!yymatchChar(';')) goto l48
;
903 yyprintf((stderr
, " ok %s @ %s\n", "EOL", yybuf
+yypos
));
905 l48
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
906 yyprintf((stderr
, " fail %s @ %s\n", "EOL", yybuf
+yypos
));
909 YY_RULE(int) yy_BoolExpr()
910 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
; yyDo(yyPush
, 2, 0);
911 yyprintf((stderr
, "%s\n", "BoolExpr")); if (!yy_CompExpr()) goto l53
; yyDo(yySet
, -2, 0);
913 { int yypos55
= yypos
, yythunkpos55
= yythunkpos
;
914 { int yypos56
= yypos
, yythunkpos56
= yythunkpos
; if (!yy__()) goto l57
; if (!yy_AND()) goto l57
; if (!yy__()) goto l57
; if (!yy_CompExpr()) goto l57
; yyDo(yySet
, -1, 0); yyDo(yy_1_BoolExpr
, yybegin
, yyend
); goto l56
;
915 l57
:; yypos
= yypos56
; yythunkpos
= yythunkpos56
; if (!yy__()) goto l55
; if (!yy_OR()) goto l55
; if (!yy__()) goto l55
; if (!yy_CompExpr()) goto l55
; yyDo(yySet
, -1, 0); yyDo(yy_2_BoolExpr
, yybegin
, yyend
);
918 l55
:; yypos
= yypos55
; yythunkpos
= yythunkpos55
;
919 } if (!yy__()) goto l53
;
920 yyprintf((stderr
, " ok %s @ %s\n", "BoolExpr", yybuf
+yypos
)); yyDo(yyPop
, 2, 0);
922 l53
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
923 yyprintf((stderr
, " fail %s @ %s\n", "BoolExpr", yybuf
+yypos
));
928 yyprintf((stderr
, "%s\n", "_"));
930 { int yypos60
= yypos
, yythunkpos60
= yythunkpos
; if (!yymatchClass((unsigned char *)"\000\002\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000")) goto l60
; goto l59
;
931 l60
:; yypos
= yypos60
; yythunkpos
= yythunkpos60
;
933 yyprintf((stderr
, " ok %s @ %s\n", "_", yybuf
+yypos
));
936 YY_RULE(int) yy_Stmt()
937 { int yypos0
= yypos
, yythunkpos0
= yythunkpos
;
938 yyprintf((stderr
, "%s\n", "Stmt"));
939 { int yypos62
= yypos
, yythunkpos62
= yythunkpos
; if (!yy__()) goto l63
; if (!yy_BoolExpr()) goto l63
; if (!yy_EOL()) goto l63
; yyDo(yy_1_Stmt
, yybegin
, yyend
); goto l62
;
940 l63
:; yypos
= yypos62
; yythunkpos
= yythunkpos62
;
942 { int yypos65
= yypos
, yythunkpos65
= yythunkpos
;
943 { int yypos66
= yypos
, yythunkpos66
= yythunkpos
; if (!yy_EOL()) goto l66
; goto l65
;
944 l66
:; yypos
= yypos66
; yythunkpos
= yythunkpos66
;
945 } if (!yymatchDot()) goto l65
; goto l64
;
946 l65
:; yypos
= yypos65
; yythunkpos
= yythunkpos65
;
947 } if (!yy_EOL()) goto l61
;
950 yyprintf((stderr
, " ok %s @ %s\n", "Stmt", yybuf
+yypos
));
952 l61
:; yypos
= yypos0
; yythunkpos
= yythunkpos0
;
953 yyprintf((stderr
, " fail %s @ %s\n", "Stmt", yybuf
+yypos
));
959 typedef int (*yyrule
)();
961 YY_PARSE(int) YYPARSEFROM(yyrule yystart
)
967 yybuf
= malloc(yybuflen
);
969 yytext
= malloc(yytextlen
);
971 yythunks
= malloc(sizeof(yythunk
) * yythunkslen
);
973 yyvals
= malloc(sizeof(YYSTYPE
) * yyvalslen
);
974 yybegin
= yyend
= yypos
= yylimit
= yythunkpos
= 0;
976 yybegin
= yyend
= yypos
;
999 YY_PARSE(int) YYPARSE(void)
1001 return YYPARSEFROM(yy_Stmt
);
1010 value_t
*expr
= NULL
;
1013 arg_len
= strlen(text
);
1023 #if defined(UNIT_TEST)
1025 main (int argc
, char **argv
)
1030 for (i
= 1; i
< argc
; ++i
) {
1031 expr
= parse(argv
[i
]);
1034 printf("= %d\n",eval(expr
,unit_oget
,unit_sget
));
1037 printf("could not parse '%s'\n",argv
[i
]);