Fixed some build warnings in release mode
[amule.git] / src / Parser.y
blob443af7adb5e74c89c0d139490bf807cb77ff634c
1 %{
2 #include "SearchExpr.h"
3 #include "Scanner.h.in"
4 #include "Scanner.h"
5 #include "OtherFunctions.h"
7 #include "libs/common/StringFunctions.h"
9 #ifdef _DEBUG
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
14 extern wxArrayString _astrParserErrors;
16 void ParsedSearchExpression(const CSearchExpr* pexpr);
17 int yyerror(const char* errstr);
18 int yyerror(wxString errstr);
22 %union {
23 wxString* pstr;
24 CSearchExpr* pexpr;
27 %token TOK_STRING
28 %token TOK_AND TOK_OR TOK_NOT
29 %token TOK_ED2K_LINK
31 %type <pexpr> searchexpr and_strings
32 %type <pstr> TOK_STRING TOK_ED2K_LINK
34 %left TOK_OR
35 %left TOK_AND
36 %left TOK_NOT
39 /*-------------------------------------------------------------------*/
41 action : searchexpr
43 ParsedSearchExpression($1);
44 delete $1;
45 return 0;
47 | TOK_ED2K_LINK
49 CSearchExpr* pexpr = new CSearchExpr(*$1);
50 ParsedSearchExpression(pexpr);
51 delete pexpr;
52 delete $1;
53 return 0;
55 /* --------- Error Handling --------- */
56 | searchexpr error
58 yyerror(wxT("Undefined search expression error"));
59 delete $1;
60 return 1;
65 searchexpr : and_strings
66 | searchexpr TOK_AND searchexpr
68 CSearchExpr* pexpr = new CSearchExpr;
69 pexpr->Add(SEARCHOP_AND);
70 pexpr->Add($1);
71 pexpr->Add($3);
72 $$ = pexpr;
73 delete $1;
74 delete $3;
76 | searchexpr TOK_OR searchexpr
78 CSearchExpr* pexpr = new CSearchExpr;
79 pexpr->Add(SEARCHOP_OR);
80 pexpr->Add($1);
81 pexpr->Add($3);
82 $$ = pexpr;
83 delete $1;
84 delete $3;
86 | searchexpr TOK_NOT searchexpr
88 CSearchExpr* pexpr = new CSearchExpr;
89 pexpr->Add(SEARCHOP_NOT);
90 pexpr->Add($1);
91 pexpr->Add($3);
92 $$ = pexpr;
93 delete $1;
94 delete $3;
96 | '(' searchexpr ')'
98 $$ = $2;
100 /* --------- Error Handling --------- */
101 | searchexpr TOK_OR error
103 yyerror(wxT("Missing right operand for OR on search expression"));
104 delete $1;
105 return 1;
107 | searchexpr TOK_NOT error
109 yyerror(wxT("Missing operand for NOT on search expression"));
110 delete $1;
111 return 1;
113 | '(' error
115 yyerror(wxT("Missing left parenthesis on search expression"));
116 return 1;
118 | '(' searchexpr error
120 yyerror(wxT("Missing closing parenthesis on search expression"));
121 delete $2;
122 return 1;
124 | TOK_AND error
126 yyerror(wxT("Missing left operand for AND on search expression"));
127 return 1;
129 | TOK_OR error
131 yyerror(wxT("Missing left operand for OR on search expression"));
132 return 1;
134 | TOK_NOT error
136 yyerror(wxT("Missing left operand for NOT on search expression (?)"));
137 return 1;
141 and_strings : TOK_STRING
143 $$ = new CSearchExpr(*$1);
144 delete $1;
146 | and_strings TOK_STRING
148 /*$1->Concatenate($2);
149 delete $2;*/
150 CSearchExpr* pexpr = new CSearchExpr;
151 pexpr->Add(SEARCHOP_AND);
152 pexpr->Add($1);
153 pexpr->Add(*$2);
154 $$ = pexpr;
155 delete $1;
156 delete $2;
162 int yyerror(const char* errstr)
164 // Errors created by yacc generated code
165 //yyerror ("syntax error: cannot back up");
166 //yyerror ("syntax error; also virtual memory exhausted");
167 //yyerror ("syntax error");
168 //yyerror ("parser stack overflow");
170 _astrParserErrors.Add(char2unicode(errstr));
171 return EXIT_FAILURE;
174 int yyerror(wxString errstr)
176 _astrParserErrors.Add(errstr);
177 return EXIT_FAILURE;