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

wip za2pda

parent b5f14472
No related branches found
No related tags found
No related merge requests found
Pipeline #200805 passed with warnings
#include <registration/AlgoRegistration.hpp>
#include "ZAToPDA.h"
namespace {
auto ZAToPDA = registration::AbstractRegister<automaton::transform::ZAToPDA, automaton::NPDA<DefaultSymbolType, DefaultStateType, char>, const automaton::ArcFactoredNondeterministicZAutomaton<DefaultSymbolType, DefaultStateType>&>(automaton::transform::ZAToPDA::convert);
} /* namespace */
/*
* This file is part of Algorithms library toolkit.
* Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
* Algorithms library toolkit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Algorithms library toolkit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <alphabet/Bar.h>
#include <alphabet/BottomOfTheStack.h>
#include <automaton/PDA/NPDA.h>
#include <automaton/TA/ArcFactoredNondeterministicZAutomaton.h>
namespace automaton::transform {
/**
* Transforms real-time height-deterministic pushdown automaton (RHPDA) to a pushdown automaton (PDA).
*/
class ZAToPDA {
public:
/**
* Transformation of a AFNZA to a PDA.
* @param zautomaton automaton to transform
* @return (non) deterministic PDA equivalent to @p automaton reading prefix bar notation
*/
template <class SymbolType, class StateType>
static automaton::NPDA<SymbolType, StateType, char> convert(const automaton::ArcFactoredNondeterministicZAutomaton<SymbolType, StateType>& zautomaton);
};
template <class SymbolType, class StateType>
automaton::NPDA<SymbolType, StateType, char> ZAToPDA::convert(const automaton::ArcFactoredNondeterministicZAutomaton<SymbolType, StateType>& zautomaton)
{
auto bots = alphabet::BottomOfTheStack::instance<StateType>();
auto bar = alphabet::Bar::instance<SymbolType>();
auto inputAlphabet = zautomaton.getInputAlphabet();
inputAlphabet.insert(bar);
auto pushdownAlphabet = zautomaton.getStates();
pushdownAlphabet.insert(bots);
automaton::NPDA<SymbolType, StateType, char> res({'q', 'r'}, inputAlphabet, pushdownAlphabet, 'q', bots, {'r'});
for (const auto& transition : zautomaton.getTransitions()) {
if (transition.first.template is<ext::pair<StateType, StateType>>()) {
const auto& trf = transition.first.template get<ext::pair<StateType, StateType>>();
res.addTransition('q', bar, {trf.first, trf.second}, 'q', {transition.second});
} else {
res.addTransition('q', transition.first.template get<SymbolType>(), {}, 'q', {transition.second});
}
}
res.addTransition('r', {}, 'q', {});
for (const auto& finalState : zautomaton.getFinalStates()) {
res.addTransition('q', bar, {finalState, bots}, 'r', {});
}
return res;
}
} /* namespace automaton::transform */
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