Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
DotConverterRTEPart.hxx
Go to the documentation of this file.
1
6#pragma once
7
10
11namespace convert {
12
14public:
15 template < class SymbolType >
16 static void convertInternal ( ext::ostream & oss, const rte::FormalRTE < SymbolType > & rte, const std::string & nodePrefix = "" );
17
18 template < class SymbolType >
19 class Formal {
20 public:
21 static unsigned visit ( const rte::FormalRTEAlternation < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
22 static unsigned visit ( const rte::FormalRTESubstitution < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
23 static unsigned visit ( const rte::FormalRTEIteration < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
24 static unsigned visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
25 static unsigned visit ( const rte::FormalRTESymbolSubst < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
26 static unsigned visit ( const rte::FormalRTEEmpty < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
27 };
28};
29
30template < class SymbolType >
31void DotConverterRTE::convertInternal ( ext::ostream & oss, const rte::FormalRTE < SymbolType > & rte, const std::string & nodePrefix ) {
32 unsigned nodeIdCounter = 0;
33 rte.getRTE ( ).getStructure ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
34}
35
36template < class SymbolType >
37unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEAlternation < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
38 unsigned id = nodeIdCounter ++;
39
40 oss << nodePrefix << id << "[label=\"+\", shape=plaintext];" << std::endl;
41
42 size_t lId = node.getLeftElement ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
43 size_t rId = node.getRightElement ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
44
45 oss << nodePrefix << id << " -> " << nodePrefix << lId << ";" << std::endl;
46 oss << nodePrefix << id << " -> " << nodePrefix << rId << ";" << std::endl;
47 return id;
48}
49
50template < class SymbolType >
51unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESubstitution < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
52 unsigned id = nodeIdCounter ++;
53
54 oss << nodePrefix << id << "[label=\". " << node.getSubstitutionSymbol( ).getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
55
56 size_t lId = node.getLeftElement ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
57 size_t rId = node.getRightElement ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
58
59 oss << nodePrefix << id << " -> " << nodePrefix << lId << ";" << std::endl;
60 oss << nodePrefix << id << " -> " << nodePrefix << rId << ";" << std::endl;
61 return id;
62}
63
64template < class SymbolType >
65unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEIteration < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
66 unsigned id = nodeIdCounter ++;
67
68 oss << nodePrefix << id << "[label=\"* " << node.getSubstitutionSymbol( ).getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
69
70 unsigned childId = node.getElement ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
71
72 oss << nodePrefix << id << " -> " << nodePrefix << childId << ";" << std::endl;
73 return id;
74}
75
76template < class SymbolType >
77unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
78 unsigned id = nodeIdCounter ++;
79
80 oss << nodePrefix << id << "[label=\"" << node.getSymbol( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
81
82 for ( const auto & child : node.getChildren ( ) ) {
83 unsigned childId = child.template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
84 oss << nodePrefix << id << " -> " << nodePrefix << childId << ";" << std::endl;
85 }
86
87 return id;
88}
89
90template < class SymbolType >
91unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESymbolSubst < SymbolType > & node, ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
92 oss << nodePrefix << nodeIdCounter << "[label=\"" << node.getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
93 return nodeIdCounter ++;
94}
95
96template < class SymbolType >
97unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEEmpty < SymbolType > & , ext::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
98 oss << nodePrefix << nodeIdCounter << "[label=\"#0\", shape=plaintext];" << std::endl;
99 return nodeIdCounter ++;
100}
101
102} /* namespace convert */
103
Definition: DotConverterRTEPart.hxx:19
static unsigned visit(const rte::FormalRTEAlternation< SymbolType > &node, ext::ostream &oss, unsigned &nodeIdCounter, const std::string &nodePrefix)
Definition: DotConverterRTEPart.hxx:37
Definition: DotConverterRTEPart.hxx:13
static void convertInternal(ext::ostream &oss, const rte::FormalRTE< SymbolType > &rte, const std::string &nodePrefix="")
Definition: DotConverterRTEPart.hxx:31
Definition: ostream.h:14
Represents the alternation operator in the regular tree expression. The node must have exactly two ch...
Definition: FormalRTEAlternation.h:44
Represents the empty expression in the regular tree expression. The node can't have any children.
Definition: FormalRTEEmpty.h:40
Represents the iteration operator in the regular tree expression. The node has exactly one child.
Definition: FormalRTEIteration.h:45
Represents the concatenation operator in the regular tree expression. The node must have exactly two ...
Definition: FormalRTESubstitution.h:44
Represents the terminal symbol in the regular tree expression. The number of children must be the sam...
Definition: FormalRTESymbolAlphabet.h:44
Represents the substitution symbol in the regular tree expression. The node can't have any children.
Definition: FormalRTESymbolSubst.h:43
Formal regular tree expression represents regular tree expression. It describes regular tree language...
Definition: FormalRTE.h:71
Definition: converterCommon.hpp:8
Definition: Node.cpp:11
Definition: ToFTAGlushkov.h:22