Skip to content
Snippets Groups Projects
Commit 3d175ef1 authored by Tomáš Pecka's avatar Tomáš Pecka
Browse files

aconvert.regexp: fix leaks

parent 8131d5ad
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,10 @@ regexp::RegExp* RegExpParser::parse() {
regexp::RegExpElement* element = this->Alternation();
RegExpLexer::Token token = m_Lexer.token();
if(token.type != RegExpLexer::TEOF) throw ParseError();
return new regexp::RegExp(element);
regexp::RegExp * ret = new regexp::RegExp( );
ret->setRegExp( element );
return ret;
}
 
regexp::RegExpElement* RegExpParser::Alternation() {
......@@ -49,7 +52,7 @@ regexp::RegExpElement* RegExpParser::Concatenation() {
regexp::RegExpElement* RegExpParser::ConcatenationCont(regexp::RegExpElement* left) {
RegExpLexer::Token token = m_Lexer.token();
if(token.type == RegExpLexer::SYMBOL || token.type == RegExpLexer::LPAR || token.type == RegExpLexer::EPS || token.type == RegExpLexer::EMPTY) {
regexp::Concatenation* res = this->ConcatenationContCont(this->Factor());
res->getElements().push_front(left);
return res;
......@@ -61,7 +64,7 @@ regexp::RegExpElement* RegExpParser::ConcatenationCont(regexp::RegExpElement* le
regexp::Concatenation* RegExpParser::ConcatenationContCont(regexp::RegExpElement* left) {
RegExpLexer::Token token = m_Lexer.token();
if(token.type == RegExpLexer::SYMBOL || token.type == RegExpLexer::LPAR || token.type == RegExpLexer::EPS || token.type == RegExpLexer::EMPTY) {
regexp::Concatenation* res = this->ConcatenationContCont(this->Factor());
res->getElements().push_front(left);
return res;
......
......@@ -21,11 +21,12 @@
int fromRegexp(std::istream& in, std::ostream& out) {
RegExpLexer lexer(in);
RegExpParser parser(lexer);
regexp::RegExp* result = parser.parse();
out << *result;
delete result;
return 0;
}
 
......@@ -44,24 +45,24 @@ int toRegexp(std::istream& in, std::ostream& out) {
}
 
int main(int argc, char* argv[]) {
int fromTo = 0;
int c;
while (1) {
static struct option long_options[] = {
{"from", no_argument, &fromTo, FROM},
{"to", no_argument, &fromTo, TO},
{0, 0, 0, 0}
};
int option_index = 0;
c = getopt_long (argc, argv, "", long_options, &option_index);
 
if (c == -1)
break;
switch (c) {
case 0:
break;
......@@ -84,7 +85,7 @@ more:
std::cerr << "error" << std::endl;
res = 1;
}
if(c != -1) delete in;
return res;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment