-
Notifications
You must be signed in to change notification settings - Fork 26
/
checktestdata.y
150 lines (125 loc) · 5.01 KB
/
checktestdata.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
%baseclass-preinclude "parsetype.hpp"
%filenames parser
%scanner scanner.h
%lsp-needed
//%debug
%stype parse_t
%token TEST_EOF TEST_MATCH TEST_UNIQUE TEST_INARRAY
%token CMP_LT CMP_GT CMP_LE CMP_GE CMP_EQ CMP_NE
%token FUN_STRLEN
%token CMD_SPACE CMD_NEWLINE CMD_EOF CMD_INT CMD_FLOAT CMD_FLOATP
%token CMD_STRING CMD_REGEX CMD_ASSERT CMD_SET CMD_UNSET
%token CMD_REP CMD_WHILE CMD_REPI CMD_WHILEI CMD_IF CMD_ELSE CMD_END
%token VARNAME INTEGER FLOAT STRING
%token OPT_FIXED OPT_SCIENTIFIC
// Fake tokens to allow parsing with non-default start symbol:
%token PARSE_ASSIGNLIST
%left LOGIC_AND LOGIC_OR
%left '+' '-'
%left '*' '/' '%'
%left '^'
%%
start:
commands { parseResult = $1; }
| PARSE_ASSIGNLIST assignlist { parseResult = $2; }
;
commands:
/* empty */ { $$ = parse_t('l'); }
| commands command { $$ = parse_t('l',$1,$2); }
;
command:
CMD_SPACE
| CMD_NEWLINE
| CMD_EOF
| CMD_END
| CMD_ELSE
| CMD_INT '(' expr ',' expr ')' { $$ = parse_t($1,$3,$5); }
| CMD_INT '(' expr ',' expr ',' variable ')' { $$ = parse_t($1,$3,$5,$7); }
| CMD_FLOAT '(' expr ',' expr ')' { $$ = parse_t($1,$3,$5); }
| CMD_FLOAT '(' expr ',' expr ',' variable ')' { $$ = parse_t($1,$3,$5,$7); }
| CMD_FLOAT '(' expr ',' expr ',' variable ',' opt_float ')'
{ $$ = parse_t($1,$3,$5,$7,$9); }
| CMD_FLOATP '(' expr ',' expr ',' expr ',' expr ')'
{ $$ = parse_t($1,$3,$5,$7,$9); }
| CMD_FLOATP '(' expr ',' expr ',' expr ',' expr ',' variable ')'
{ $$ = parse_t($1,$3,$5,$7,$9,$11); }
| CMD_FLOATP '(' expr ',' expr ',' expr ',' expr ',' variable ',' opt_float ')'
{ $$ = parse_t($1,$3,$5,$7,$9,$11,$13); }
| CMD_STRING '(' value ')' { $$ = parse_t($1,$3); }
| CMD_REGEX '(' value ')' { $$ = parse_t($1,$3); }
| CMD_REGEX '(' value ',' variable ')' { $$ = parse_t($1,$3,$5); }
| CMD_ASSERT '(' test ')' { $$ = parse_t($1,$3); }
| CMD_SET '(' assignlist ')' { $$ = parse_t('@',$1,$3); }
| CMD_UNSET '(' varlist ')' { $$ = parse_t('@',$1,$3); }
| CMD_REP '(' expr ')' { $$ = parse_t($1,$3); }
| CMD_REP '(' expr ',' command ')' { $$ = parse_t($1,$3,$5); }
| CMD_WHILE '(' test ')' { $$ = parse_t($1,$3); }
| CMD_WHILE '(' test ',' command ')' { $$ = parse_t($1,$3,$5); }
| CMD_IF '(' test ')' { $$ = parse_t($1,$3); }
| CMD_REPI '(' variable ',' expr ')' { $$ = parse_t($1,$3,$5); }
| CMD_REPI '(' variable ',' expr ',' command ')' { $$ = parse_t($1,$3,$5,$7); }
| CMD_WHILEI '(' variable ',' test ')' { $$ = parse_t($1,$3,$5); }
| CMD_WHILEI '(' variable ',' test ',' command ')' { $$ = parse_t($1,$3,$5,$7); }
;
opt_float: OPT_FIXED | OPT_SCIENTIFIC ;
string:
STRING { $$ = parse_t('S',$1); }
;
value:
INTEGER { $$ = parse_t('I',$1); }
| FLOAT { $$ = parse_t('F',$1); }
| string
| variable
| function
;
variable:
VARNAME { $$ = parse_t('v',$1); }
| VARNAME '[' exprlist ']' { $$ = parse_t('v',$1,$3); }
;
exprlist:
expr { $$ = parse_t('l',$1); }
| exprlist ',' expr { $$ = parse_t('l',$1,$3); }
;
varlist:
VARNAME { $$ = parse_t('l',$1); }
| varlist ',' VARNAME { $$ = parse_t('l',$1,$3); }
;
varassign:
variable '=' expr { $$ = parse_t('a',$1,$3); }
;
assignlist:
varassign { $$ = parse_t('l',$1); }
| assignlist ',' varassign { $$ = parse_t('l',$1,$3); }
;
compare: CMP_LT | CMP_GT | CMP_LE | CMP_GE | CMP_EQ | CMP_NE ;
function:
FUN_STRLEN '(' value ')' { $$ = parse_t('f',$1,$3); }
;
expr:
term { $$ = parse_t($1); }
| expr '+' term { $$ = parse_t('+',$1,$3); }
| expr '-' term { $$ = parse_t('-',$1,$3); }
;
term:
fact { $$ = parse_t($1); }
| term '*' fact { $$ = parse_t('*',$1,$3); }
| term '/' fact { $$ = parse_t('/',$1,$3); }
| term '%' fact { $$ = parse_t('%',$1,$3); }
;
fact:
value { $$ = parse_t($1); }
| '-' fact { $$ = parse_t('n',$2); }
| '(' expr ')' { $$ = parse_t($2); }
| fact '^' fact { $$ = parse_t('^',$1,$3); }
;
test:
'!' test { $$ = parse_t('!',$2); }
| '(' test ')' { $$ = parse_t($2); }
| test LOGIC_AND test { $$ = parse_t('&',$1,$3); }
| test LOGIC_OR test { $$ = parse_t('|',$1,$3); }
| expr compare expr { $$ = parse_t('?',$2,$1,$3); }
| TEST_EOF { $$ = parse_t('E'); }
| TEST_MATCH '(' value ')' { $$ = parse_t('M',$3); }
| TEST_UNIQUE '(' varlist ')' { $$ = parse_t('U',$3); }
| TEST_INARRAY '(' expr ',' variable ')' { $$ = parse_t('A',$3,$5); }
;