diff --git a/aconvert.regexp/src/RegExpParser.cpp b/aconvert.regexp/src/RegExpParser.cpp index cf070c07a50f0e5645f7efbc6b84c1a737d58efe..faf7fc8a3643e8bd293e3b1dc33736d24c34fbf3 100644 --- a/aconvert.regexp/src/RegExpParser.cpp +++ b/aconvert.regexp/src/RegExpParser.cpp @@ -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; diff --git a/aconvert.regexp/src/aconvert.regexp.cpp b/aconvert.regexp/src/aconvert.regexp.cpp index 417a1ff111b6bbd8eca2d69438e7676ef140e451..aa963b7ec3ddb9e5260eea8ac8fb86a59d2fb29f 100644 --- a/aconvert.regexp/src/aconvert.regexp.cpp +++ b/aconvert.regexp/src/aconvert.regexp.cpp @@ -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