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

overal firstfirst conflict removal tests

parent eb58879c
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,6 @@ namespace parsing {
 
void Substitute::substitute ( const grammar::CFG & orig, grammar::CFG & res, const alphabet::Symbol & origLHS, const std::vector < alphabet::Symbol > & origRHS, std::vector < alphabet::Symbol >::const_iterator nonterminal ) {
auto iter = orig.getRules ( ).find ( * nonterminal );
std::cout << * nonterminal << std::endl;
 
if ( iter == orig.getRules ( ).end ( ) ) return;
 
......
......@@ -25,8 +25,7 @@ void CornerSubstitution::testCornerSubstitution ( ) {
grammar::CFG grammar ( A );
 
grammar.setTerminalAlphabet ( { a, b, c, d } );
grammar.setNonterminalAlphabet ( { { A, B, C }
} );
grammar.setNonterminalAlphabet ( { A, B, C } );
grammar.setInitialSymbol ( A );
 
grammar.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
......@@ -42,8 +41,7 @@ void CornerSubstitution::testCornerSubstitution ( ) {
grammar::CFG comp ( A );
 
comp.setTerminalAlphabet ( { a, b, c, d } );
comp.setNonterminalAlphabet ( { { A, B, C }
} );
comp.setNonterminalAlphabet ( { A, B, C } );
comp.setInitialSymbol ( A );
 
comp.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
......@@ -72,8 +70,7 @@ void CornerSubstitution::testCornerSubstitution2 ( ) {
grammar::CFG grammar ( A );
 
grammar.setTerminalAlphabet ( { a, b, c, d } );
grammar.setNonterminalAlphabet ( { { A, B, C }
} );
grammar.setNonterminalAlphabet ( { A, B, C } );
grammar.setInitialSymbol ( A );
 
grammar.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
......@@ -90,8 +87,7 @@ void CornerSubstitution::testCornerSubstitution2 ( ) {
grammar::CFG comp ( A );
 
comp.setTerminalAlphabet ( { a, b, c, d } );
comp.setNonterminalAlphabet ( { { A, B, C }
} );
comp.setNonterminalAlphabet ( { A, B, C } );
comp.setInitialSymbol ( A );
 
comp.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
......
#include "HandleFirstFirstConflict.h"
#include "grammar/ContextFree/CFG.h"
#include "grammar/parsing/HandleFirstFirstConflict.h"
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( HandleFirstFirstConflict, "grammar" );
CPPUNIT_TEST_SUITE_REGISTRATION ( HandleFirstFirstConflict );
void HandleFirstFirstConflict::setUp ( ) {
}
void HandleFirstFirstConflict::tearDown ( ) {
}
void HandleFirstFirstConflict::testHandleFirstFirstConflict ( ) {
alphabet::Symbol A = alphabet::symbolFrom ( "A" );
alphabet::Symbol Ap = alphabet::symbolFrom ( "A'" );
alphabet::Symbol B = alphabet::symbolFrom ( "B" );
alphabet::Symbol C = alphabet::symbolFrom ( "C" );
alphabet::Symbol a = alphabet::symbolFrom ( 'a' );
alphabet::Symbol b = alphabet::symbolFrom ( 'b' );
alphabet::Symbol c = alphabet::symbolFrom ( 'c' );
alphabet::Symbol d = alphabet::symbolFrom ( 'd' );
grammar::CFG grammar ( A );
grammar.setTerminalAlphabet ( { a, b, c, d } );
grammar.setNonterminalAlphabet ( { A, B, C } );
grammar.setInitialSymbol ( A );
grammar.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
grammar.addRule ( A, std::vector < alphabet::Symbol > { C, B } );
grammar.addRule ( B, std::vector < alphabet::Symbol > { c, B } );
grammar.addRule ( B, std::vector < alphabet::Symbol > { d } );
grammar.addRule ( C, std::vector < alphabet::Symbol > { a, C } );
grammar.addRule ( C, std::vector < alphabet::Symbol > { b, B } );
grammar::CFG res = grammar;
grammar::parsing::HandleFirstFirstConflict::handleFirstFirstConflict ( res, a, A, { {a, B }, {C ,B} } );
grammar::CFG comp ( A );
comp.setTerminalAlphabet ( { a, b, c, d } );
comp.setNonterminalAlphabet ( { A, B, C } );
comp.setInitialSymbol ( A );
comp.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
comp.addRule ( A, std::vector < alphabet::Symbol > { a, C, B } );
comp.addRule ( A, std::vector < alphabet::Symbol > { b, B, B } );
comp.addRule ( B, std::vector < alphabet::Symbol > { c, B } );
comp.addRule ( B, std::vector < alphabet::Symbol > { d } );
comp.addRule ( C, std::vector < alphabet::Symbol > { a, C } );
comp.addRule ( C, std::vector < alphabet::Symbol > { b, B } );
std::cout << res << std::endl << comp << std::endl;
CPPUNIT_ASSERT ( res == comp );
grammar::parsing::HandleFirstFirstConflict::handleFirstFirstConflict ( res, a, A, { {a, B }, {a, C, B} } );
grammar::CFG comp2 ( A );
comp2.setTerminalAlphabet ( { a, b, c, d } );
comp2.setNonterminalAlphabet ( { A, Ap, B, C } );
comp2.setInitialSymbol ( A );
comp2.addRule ( A, std::vector < alphabet::Symbol > { a, Ap } );
comp2.addRule ( A, std::vector < alphabet::Symbol > { b, B, B } );
comp2.addRule ( Ap, std::vector < alphabet::Symbol > { B } );
comp2.addRule ( Ap, std::vector < alphabet::Symbol > { C, B } );
comp2.addRule ( B, std::vector < alphabet::Symbol > { c, B } );
comp2.addRule ( B, std::vector < alphabet::Symbol > { d } );
comp2.addRule ( C, std::vector < alphabet::Symbol > { a, C } );
comp2.addRule ( C, std::vector < alphabet::Symbol > { b, B } );
std::cout << res << std::endl << comp2 << std::endl;
CPPUNIT_ASSERT ( res == comp2 );
}
void HandleFirstFirstConflict::testHandleFirstFirstConflict2 ( ) {
alphabet::Symbol A = alphabet::symbolFrom ( "A" );
alphabet::Symbol Ap = alphabet::symbolFrom ( "A'" );
alphabet::Symbol B = alphabet::symbolFrom ( "B" );
alphabet::Symbol C = alphabet::symbolFrom ( "C" );
alphabet::Symbol a = alphabet::symbolFrom ( 'a' );
alphabet::Symbol b = alphabet::symbolFrom ( 'b' );
alphabet::Symbol c = alphabet::symbolFrom ( 'c' );
alphabet::Symbol d = alphabet::symbolFrom ( 'd' );
grammar::CFG grammar ( A );
grammar.setTerminalAlphabet ( { a, b, c, d } );
grammar.setNonterminalAlphabet ( { A, B, C } );
grammar.setInitialSymbol ( A );
grammar.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
grammar.addRule ( A, std::vector < alphabet::Symbol > { C, B } );
grammar.addRule ( B, std::vector < alphabet::Symbol > { c, B } );
grammar.addRule ( B, std::vector < alphabet::Symbol > { a } );
grammar.addRule ( C, std::vector < alphabet::Symbol > { a, C } );
grammar.addRule ( C, std::vector < alphabet::Symbol > { B, b } );
grammar::CFG res = grammar;
grammar::parsing::HandleFirstFirstConflict::handleFirstFirstConflict ( res, a, A, { {a, B}, {C, B}});
grammar::parsing::HandleFirstFirstConflict::handleFirstFirstConflict ( res, a, A, { {a, B}, {a, C, B}, {B, b, B}});
grammar::CFG comp ( A );
comp.setTerminalAlphabet ( { a, b, c, d } );
comp.setNonterminalAlphabet ( { A, B, C } );
comp.setInitialSymbol ( A );
comp.addRule ( A, std::vector < alphabet::Symbol > { a, B } );
comp.addRule ( A, std::vector < alphabet::Symbol > { a, C, B } );
comp.addRule ( A, std::vector < alphabet::Symbol > { a, b, B } );
comp.addRule ( A, std::vector < alphabet::Symbol > { c, B, b, B } );
comp.addRule ( B, std::vector < alphabet::Symbol > { c, B } );
comp.addRule ( B, std::vector < alphabet::Symbol > { a } );
comp.addRule ( C, std::vector < alphabet::Symbol > { a, C } );
comp.addRule ( C, std::vector < alphabet::Symbol > { B, b } );
std::cout << res << std::endl << comp << std::endl;
CPPUNIT_ASSERT ( res == comp );
grammar::parsing::HandleFirstFirstConflict::handleFirstFirstConflict ( res, a, A, { {a, B}, {a, C, B}, {a, b, B}});
grammar::CFG comp2 ( A );
comp2.setTerminalAlphabet ( { a, b, c, d } );
comp2.setNonterminalAlphabet ( { A, Ap, B, C } );
comp2.setInitialSymbol ( A );
comp2.addRule ( A, std::vector < alphabet::Symbol > { a, Ap } );
comp2.addRule ( A, std::vector < alphabet::Symbol > { c, B, b, B } );
comp2.addRule ( Ap, std::vector < alphabet::Symbol > { B } );
comp2.addRule ( Ap, std::vector < alphabet::Symbol > { C, B } );
comp2.addRule ( Ap, std::vector < alphabet::Symbol > { b, B } );
comp2.addRule ( B, std::vector < alphabet::Symbol > { c, B } );
comp2.addRule ( B, std::vector < alphabet::Symbol > { a } );
comp2.addRule ( C, std::vector < alphabet::Symbol > { a, C } );
comp2.addRule ( C, std::vector < alphabet::Symbol > { B, b } );
std::cout << res << std::endl << comp2 << std::endl;
CPPUNIT_ASSERT ( res == comp2 );
}
#ifndef CORNER_SUBSTITUTION_TEST_H_
#define CORNER_SUBSTITUTION_TEST_H_
#include <cppunit/extensions/HelperMacros.h>
class HandleFirstFirstConflict : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE ( HandleFirstFirstConflict );
CPPUNIT_TEST ( testHandleFirstFirstConflict );
CPPUNIT_TEST ( testHandleFirstFirstConflict2 );
CPPUNIT_TEST_SUITE_END ( );
public:
void setUp ( );
void tearDown ( );
void testHandleFirstFirstConflict ( );
void testHandleFirstFirstConflict2 ( );
};
#endif /* CORNER_SUBSTITUTION_TEST_H_ */
......@@ -27,7 +27,7 @@ void LeftFactorize::testLeftFactorize ( ) {
grammar::CFG grammar ( S );
 
grammar.setTerminalAlphabet ( { a, b, c } );
grammar.setNonterminalAlphabet ( { { S, B, C } } );
grammar.setNonterminalAlphabet ( { S, B, C } );
grammar.setInitialSymbol ( S );
 
grammar.addRule ( S, std::vector < alphabet::Symbol > { a, B } );
......@@ -45,7 +45,7 @@ void LeftFactorize::testLeftFactorize ( ) {
grammar::CFG comp ( S );
 
comp.setTerminalAlphabet ( { a, b, c } );
comp.setNonterminalAlphabet ( { { S, Sp, B, Bp, C, Cp } } );
comp.setNonterminalAlphabet ( { S, Sp, B, Bp, C, Cp } );
comp.setInitialSymbol ( S );
 
comp.addRule ( S, std::vector < alphabet::Symbol > { a, Sp } );
......@@ -80,7 +80,7 @@ void LeftFactorize::testLeftFactorize2 ( ) {
grammar::CFG grammar ( S );
 
grammar.setTerminalAlphabet ( { a, b, c, d } );
grammar.setNonterminalAlphabet ( { { S, B, C, D } } );
grammar.setNonterminalAlphabet ( { S, B, C, D } );
grammar.setInitialSymbol ( S );
 
grammar.addRule ( S, std::vector < alphabet::Symbol > { a, B } );
......@@ -101,7 +101,7 @@ void LeftFactorize::testLeftFactorize2 ( ) {
grammar::CFG comp ( S );
 
comp.setTerminalAlphabet ( { a, b, c, d } );
comp.setNonterminalAlphabet ( { { S, Sp, B, Bp, C, Cp, D} } );
comp.setNonterminalAlphabet ( { S, Sp, B, Bp, C, Cp, D} );
comp.setInitialSymbol ( S );
 
comp.addRule ( S, std::vector < alphabet::Symbol > { a, Sp } );
......
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