-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPredicate.cpp
More file actions
executable file
·91 lines (82 loc) · 1.89 KB
/
Predicate.cpp
File metadata and controls
executable file
·91 lines (82 loc) · 1.89 KB
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
#include "stdafx.h"
/*/////////////////copy right AmoiesisNQ ////////////////////
*
* Robocup 3D Soccer Simulation Team AmoiesisNQ
* the automation department of Xiamen University China
*
* 用于解析的基础类
*
*change log
*2007年8月22日 完成初期框架
*
*////////////////////////////////////////////////////////////
#include "Predicate.h"
#include "Logger.h"
bool Parser::Parse(const string& line, Predicate& pred, int& head)
{
if (line[head] != '(')
{
//LOG_PARSE << "Column" << head << " Syntax error. '(' Missing" << END;
return false;
}
for (++ head; head < (int)line.size(); ++ head)
{
if (string(" \t\r\n").find(line[head]) != -1) continue;
if (line[head] == ')') break;
if (line[head] == '(')
{
Predicate pp;
if (Parse(line, pp, head) == false)
{
return false;
}
if (pp.name != "")
{
pred.AddChild(pp.name, pp);
}
}
else
{
int tail = head + 1;
while (tail < (int)line.size() && string(" \t\r\n)").find(line[tail]) == -1)
++ tail;
if (pred.name == "")
{
pred.name = line.substr(head, tail - head);
}
else
{
pred.AddValue(line.substr(head, tail - head));
}
head = tail;
if (head >= (int)line.size() || line[head] == ')') break;
}
}
if (line[head] != ')')
{
//LOG_PARSE << "Column" << head << " Syntax error. ')' Missing" << END;
return false;
}
return true;
}
bool Parser::Parse(const string& line, Predicate& pred)
{
int head = 0;
pred.name = "";
pred.attr.clear();
pred.child.clear();
return Parse(line, pred, head);
}
bool Parser::Parse(const string& line, vector<Predicate>& preds)
{
preds.clear();
for (int head = 0; head < (int) line.size(); ++ head)
{
preds.push_back(Predicate());
if (Parse(line, preds[preds.size() - 1], head) == false)
{
return false;
}
}
return true;
}