Skip to content
Snippets Groups Projects
Commit 0b99fc57 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

fix rule filtering

parent 670d2e41
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ obj/makefile: makefile
echo "SRCDIR:=" >> $@
echo "DEPTH:=" >> $@
echo "" >> $@
echo "CXXFLAGS:= -std=c++11 -Og -g -c -Wall -pedantic -Wextra -fPIC -I/usr/include/libxml2/" >> $@
echo "CXXFLAGS:= -std=c++11 -O0 -g -c -Wall -pedantic -Wextra -fPIC -I/usr/include/libxml2/" >> $@
echo "" >> $@
echo "SOURCES:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@
echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@
......@@ -79,7 +79,7 @@ test-obj/makefile: makefile
echo "SRCDIR:=" >> $@
echo "DEPTH:=" >> $@
echo "" >> $@
echo "CXXFLAGS:= -std=c++11 -Og -g -c -Wall -pedantic -Wextra -I../\$$(DEPTH)src/ -I/usr/include/libxml2/" >> $@
echo "CXXFLAGS:= -std=c++11 -O0 -g -c -Wall -pedantic -Wextra -I../\$$(DEPTH)src/ -I/usr/include/libxml2/" >> $@
echo "" >> $@
echo "SOURCES:= \$$(shell find ../\$$(DEPTH)test-src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@
echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)test-src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)test-obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@
......
......@@ -73,13 +73,13 @@ bool UnrestrictedGrammar::addRule(const std::vector<alphabet::Symbol>& leftHandS
for(lContext = 0; lContext < lSize - 1 && leftHandSide[lContext] == rightHandSide[lContext]; lContext++);
for(rContext = 0; rContext < lSize - 1 && leftHandSide[lSize - rContext] == rightHandSide[rSize - rContext]; rContext++);
 
if(lContext + rContext + 1 < lSize)
if(lContext + rContext + 1 < lSize) {
throw GrammarException("Rule must rewrite only one symbol");
if(lContext + rContext + 1 == lSize && !nonterminalAlphabet.count(leftHandSide[lContext]))
throw GrammarException("Rule must rewrite nonterminal symbol");
if(/* lContext + rContext + 1 > lSize */ std::all_of(leftHandSide.begin(), leftHandSide.end(), [&](const alphabet::Symbol symbol) {return !nonterminalAlphabet.count(symbol);}))
} else
if(lContext + rContext + 1 == lSize) {
if(!nonterminalAlphabet.count(leftHandSide[lContext])) throw GrammarException("Rule must rewrite nonterminal symbol");
} else
if(/* lContext + rContext + 1 > lSize */ std::all_of(leftHandSide.end() - rContext + 1, leftHandSide.begin() + lContext - 1, [&](const alphabet::Symbol symbol) {return !nonterminalAlphabet.count(symbol);}))
throw GrammarException("Rule must rewrite nonterminal symbol");
 
 
......
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