forked from DOMjudge/checktestdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsetype.cc
55 lines (48 loc) · 1.35 KB
/
parsetype.cc
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
#include "parsetype.hpp"
std::ostream &operator<<(std::ostream &out, const parse_t &obj)
{
char op = obj.op;
// '#' should never be output as operator
switch ( op ) {
case 'I':
case 'F':
case 'f':
case ' ': out << obj.val; op = ','; break;
case 'n': out << '-'; op = '#'; break;
case '!': out << '!'; op = '#'; break;
case '(': op = '#'; break;
case 'E': out << "ISEOF"; op = '#'; break;
case 'M': out << "MATCH"; op = '#'; break;
case 'U': out << "UNIQUE"; op = ','; break;
case 'A': out << "INARRAY"; op = ','; break;
}
// Special case quote strings
if ( op=='S' ) return out << '"' << obj.val << '"';
// Special case compare operators, as these are not stored in 'op'
if ( op=='?' ) {
if ( obj.nargs()!=2 ) return out << "#error in compare#";
out << obj.args[0] << obj.val << obj.args[1];
return out;
}
// Special case array variable using []
if ( op=='v' ) {
out << obj.val;
if ( obj.nargs()>0 ) {
out << '[' << obj.args[0];
for(size_t i=1; i<obj.nargs(); i++) out << ',' << obj.args[i];
out << ']';
}
return out;
}
// Special case variable assignment
if ( op=='a' ) {
out << obj.args[0] << '=' << obj.args[1];
return out;
}
if ( obj.nargs()>0 ) {
out << '(' << obj.args[0];
for(size_t i=1; i<obj.nargs(); i++) out << op << obj.args[i];
out << ')';
}
return out;
}