summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/src/lib/plural_formula.y
blob: 1623f8b2828b1b4d96e681f52eb7630b2d45b9dd (plain)
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
%name pluralParse
%token_type {int}
%extra_argument {struct parse_state *s}

%right T_QMARK.
%left T_OR.
%left T_AND.
%left T_EQ T_NE.
%left T_LT T_LE T_GT T_GE.
%left T_ADD T_SUB.
%left T_MUL T_DIV T_MOD.
%right T_NOT.
%nonassoc T_COLON T_N T_LPAREN T_RPAREN.

%include {
#include <assert.h>

struct parse_state {
	int num;
	int res;
};
}

input ::= expr(A).										{ s->res = A; }

expr(A) ::= expr(B) T_QMARK expr(C) T_COLON expr(D).	{ A = B ? C : D; }
expr(A) ::= expr(B) T_OR expr(C).						{ A = B || C; }
expr(A) ::= expr(B) T_AND expr(C).						{ A = B && C; }
expr(A) ::= expr(B) T_EQ expr(C).						{ A = B == C; }
expr(A) ::= expr(B) T_NE expr(C).						{ A = B != C; }
expr(A) ::= expr(B) T_LT expr(C).						{ A = B < C; }
expr(A) ::= expr(B) T_LE expr(C).						{ A = B <= C; }
expr(A) ::= expr(B) T_GT expr(C).						{ A = B > C; }
expr(A) ::= expr(B) T_GE expr(C).						{ A = B >= C; }
expr(A) ::= expr(B) T_ADD expr(C).						{ A = B + C; }
expr(A) ::= expr(B) T_SUB expr(C).						{ A = B - C; }
expr(A) ::= expr(B) T_MUL expr(C).						{ A = B * C; }
expr(A) ::= expr(B) T_DIV expr(C).						{ A = B / C; }
expr(A) ::= expr(B) T_MOD expr(C).						{ A = B % C; }
expr(A) ::= T_NOT expr(B).								{ A = !B; }
expr(A) ::= T_N.										{ A = s->num; }
expr(A) ::= T_NUM(B).									{ A = B; }
expr(A) ::= T_LPAREN expr(B) T_RPAREN.					{ A = B; }