File: GAFFCESParserParser.y

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 239,848 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 93
file content (223 lines) | stat: -rw-r--r-- 7,539 bytes parent folder | download | duplicates (8)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
%{

#include <BALL/MOLMEC/AMBER/GAFFCESParser.h>

#include <iostream>
#include <cstdlib>

using namespace BALL;
using namespace std;

extern int yylex();
extern void yyerror(const char* s);

%}

%union {
	char*		text;
	int			number;
}


%token						TK_OPEN
%token						TK_END
%token						TK_AND
%token						TK_MATCH_TRUE
%token	<text>		ATOMSTRING
%token	<number>	OPTIONAL_NUMBER

%token						TK_APS_START
%token						TK_APS_END
%token						TK_APS_AND_TERM
%token						TK_APS_OR_TERM
%token						TK_APS_DELOCALIZED
%token					  TK_APS_PURE_SINGLE_BOND
%token					  TK_APS_PURE_DOUBLE_BOND
%token					  TK_APS_TRIPLE_BOND
%token					  TK_APS_AROMATIC_BOND
%token					  TK_APS_ALL_SINGLE_BONDS
%token					  TK_APS_ALL_DOUBLE_BONDS
%token					  TK_APS_NOT_BOUND_TO_PARENT
%token					  TK_APS_BOUND_TO_PARENT
%token					  TK_APS_PURE_AROMATIC_RING
%token					  TK_APS_PLANAR_RING
%token					  TK_APS_PLANAR_RING_WITH_DB
%token					  TK_APS_OTHER_RING_ATOM
%token					  TK_APS_PURE_ALIPHATIC_RING
%token					  TK_APS_THREE_RING
%token					  TK_APS_FOUR_RING
%token					  TK_APS_FIVE_RING
%token					  TK_APS_SIX_RING
%token					  TK_APS_SEVEN_RING
%token					  TK_APS_EIGHT_RING
%token					  TK_APS_NINE_RING
%token					  TK_APS_RING
%token					  TK_APS_NON_RING
%token					  TK_APS_TRUE
%token<number>  	TK_APS_NUMBER

%type	<number>				connection

%%

ces_string:	/* empty */ {
		Log.error() << "Warning: Empty String" << std::endl;
	}
	| ces_part {}
	| aps ces_part {}
	| aps {}
  ;

ces_part: open atomlist close {}
	| TK_MATCH_TRUE { 
		GAFFCESParser::state.current_parser->current_root_predicate->addTruePredicate(); 
	};

aps: TK_APS_START aps_and_terms TK_APS_END { }
	; 

aps_and_terms: aps_or_terms aps_and aps_and_terms {
	}
	| aps_or_terms { }
	;

aps_and: TK_APS_AND_TERM {
		 GAFFCESParser::state.current_parser->current_predicate->addNewAND(); 
	};

aps_or_terms: aps_or_term TK_APS_OR_TERM aps_or_terms { }
	| aps_or_term { }
	;

aps_or_term: aps_term { 
		GAFFCESParser::state.current_parser->current_predicate->addNewOR(GAFFCESParser::state.current_aps_type, GAFFCESParser::state.feature_number); 
	};


aps_term: TK_APS_TRUE {
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::APS_TRUE);
	}
	| optional_aps_number TK_APS_DELOCALIZED connection { 
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::DELOCALIZED_BOND + $3);
	}
	|	optional_aps_number TK_APS_PURE_SINGLE_BOND connection {
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::PURE_SINGLE_BOND + $3);
	}
	|	optional_aps_number TK_APS_PURE_DOUBLE_BOND connection {
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::PURE_DOUBLE_BOND + $3);
	}
	|	optional_aps_number TK_APS_TRIPLE_BOND connection {
		// NOTE: GAFF does not distinguish between different kinds of triple bonds!
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::TRIPLE_BOND + $3);
	}
	|	optional_aps_number TK_APS_AROMATIC_BOND connection {
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::AROMATIC_BOND + $3);
	}
	|	optional_aps_number TK_APS_ALL_SINGLE_BONDS connection {
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::SINGLE_BOND + $3);
	}
	|	optional_aps_number TK_APS_ALL_DOUBLE_BONDS connection {
		GAFFCESParser::state.current_aps_type = (GAFFCESParser::APSMatcher::APSType) (GAFFCESParser::APSMatcher::DOUBLE_BOND + $3);
	}
	|	optional_aps_number TK_APS_PURE_AROMATIC_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_PURELY_AROMATIC;
	}
	|	optional_aps_number TK_APS_PLANAR_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_PLANAR;
	}
	|	optional_aps_number TK_APS_PLANAR_RING_WITH_DB {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_PLANAR_WITH_DB_TO_NR;
	}
	|	optional_aps_number TK_APS_OTHER_RING_ATOM {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_OTHER_RING;
	}
	|	optional_aps_number TK_APS_PURE_ALIPHATIC_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_PURELY_ALIPHATIC;
	}
	|	optional_aps_number TK_APS_THREE_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_3_RING_ATOM;
	}
	|	optional_aps_number TK_APS_FOUR_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_4_RING_ATOM;
	}
	|	optional_aps_number TK_APS_FIVE_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_5_RING_ATOM;
	}
	|	optional_aps_number TK_APS_SIX_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_6_RING_ATOM;
	}
	|	optional_aps_number TK_APS_SEVEN_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_7_RING_ATOM;
	}
	|	optional_aps_number TK_APS_EIGHT_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_8_RING_ATOM;
	}
	|	optional_aps_number TK_APS_NINE_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_9_RING_ATOM;
	}
	|	optional_aps_number TK_APS_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_RING_ATOM;
	}
	|	optional_aps_number TK_APS_NON_RING {
		GAFFCESParser::state.current_aps_type = GAFFCESParser::APSMatcher::IS_NON_RING_ATOM;
	}
	;

optional_aps_number: /* empty */ { GAFFCESParser::state.feature_number = -1; }
	| TK_APS_NUMBER {  GAFFCESParser::state.feature_number = $1; }
	;

connection: /* empty */ {  $$ = 0; }
	|	TK_APS_BOUND_TO_PARENT {  $$ = 1; }
	| TK_APS_NOT_BOUND_TO_PARENT { $$ = 2; }
	;

open:	TK_OPEN {
		GAFFCESParser::state.current_parser->startChildPredicates();
	};

close:	TK_END {
		GAFFCESParser::state.current_parser->endChildPredicates();
	};	

atomlist:	atomsymbol optional_atomlist	{}
	| atomlist TK_AND atomsymbol optional_atomlist	{};

optional_atomlist: /* empty */	{}
	| open atomlist close	{};

atomsymbol: atom_definition { }
	| atom_definition aps { };
	
atom_definition:	ATOMSTRING {
		const set<String>& element_symbols = GAFFCESParser::state.current_parser->getElementSymbols();
		if((element_symbols.find($1)) != element_symbols.end())
		{
			GAFFCESParser::state.current_parser->current_root_predicate->addCESelementPredicate($1);
		}
		else if( ((GAFFCESParser::state.current_parser->current_predicate->getStringToWildcard()).find($1)) != ((GAFFCESParser::state.current_parser->current_predicate->getStringToWildcard()).end()) )
		{	
			GAFFCESParser::state.current_parser->current_root_predicate->addCESwildcardsPredicate($1);
		}
	}
	|	ATOMSTRING  OPTIONAL_NUMBER	{
		const set<String>& element_symbols = GAFFCESParser::state.current_parser->getElementSymbols();
		if((element_symbols.find($1)) != element_symbols.end())
		{
			GAFFCESParser::state.current_parser->current_root_predicate->addCESelementConnectionPredicate($2, $1);
		}
		else if( ((GAFFCESParser::state.current_parser->current_predicate->getStringToWildcard()).find($1)) != ((GAFFCESParser::state.current_parser->current_predicate->getStringToWildcard()).end()) )
		{	
			GAFFCESParser::state.current_parser->current_root_predicate->addCESwildcardsConnectionPredicate($1, $2);
		}
		else
		{
			Log.error() << "No valid Atomsymbol found" << std::endl;
		}
	};

%%
void yyerror(const char* s)
{
	printf("Parse Error! %s\n", s);
}