diff --git a/alib2/src/alphabet/BlankSymbol.h b/alib2/src/alphabet/BlankSymbol.h index 25bfcb4a3426683348fae384140d7535de097256..7f330893e7ea9d6a017e281033a7df19f0848721 100644 --- a/alib2/src/alphabet/BlankSymbol.h +++ b/alib2/src/alphabet/BlankSymbol.h @@ -2,7 +2,7 @@ * BlankSymbol.h * * Created on: Mar 26, 2013 - * Author: Jan TrávnĂÄŤek + * Author: Jan Travnicek */ #ifndef BLANK_SYMBOL_H_ diff --git a/alib2/src/alphabet/BottomOfTheStackSymbol.cpp b/alib2/src/alphabet/BottomOfTheStackSymbol.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7aa1015591df86eb7286e9ef27c148b0fa40b606 --- /dev/null +++ b/alib2/src/alphabet/BottomOfTheStackSymbol.cpp @@ -0,0 +1,54 @@ +/* + * BottomOfTheStackSymbol.cpp + * + * Created on: Jun 19, 2014 + * Author: Jan Travnicek + */ + +#include "BottomOfTheStackSymbol.h" + +namespace alphabet { + +BottomOfTheStackSymbol::BottomOfTheStackSymbol() { + +} + +SymbolBase* BottomOfTheStackSymbol::clone() const { + return new BottomOfTheStackSymbol(*this); +} + +SymbolBase* BottomOfTheStackSymbol::plunder() && { + return new BottomOfTheStackSymbol(std::move(*this)); +} + +bool BottomOfTheStackSymbol::operator <(const SymbolBase& other) const { + return other > *this; +} + +bool BottomOfTheStackSymbol::operator ==(const SymbolBase& other) const { + return other == *this; +} + +bool BottomOfTheStackSymbol::operator >(const SymbolBase& other) const { + return other < *this; +} + +bool BottomOfTheStackSymbol::operator ==(const BottomOfTheStackSymbol&) const { + return true; +} + +bool BottomOfTheStackSymbol::operator <(const BottomOfTheStackSymbol&) const { + return false; +} + +void BottomOfTheStackSymbol::operator>>(std::ostream& out) const { + out << "(Blank symbol)"; +} + +BottomOfTheStackSymbol::operator std::string () const { + return ""; +} + +BottomOfTheStackSymbol BottomOfTheStackSymbol::BOTTOM_OF_THE_STACK = BottomOfTheStackSymbol(); + +} /* namespace alphabet */ diff --git a/alib2/src/alphabet/BottomOfTheStackSymbol.h b/alib2/src/alphabet/BottomOfTheStackSymbol.h new file mode 100644 index 0000000000000000000000000000000000000000..eebc152cca9d73f6665ccf505e810fecc2c88c71 --- /dev/null +++ b/alib2/src/alphabet/BottomOfTheStackSymbol.h @@ -0,0 +1,45 @@ +/* + * BottomOfTheStackSymbol.h + * + * Created on: Jun 19, 2014 + * Author: Jan Travnicek + */ + +#ifndef BOTTOM_OF_THE_STACK_SYMBOL_H_ +#define BOTTOM_OF_THE_STACK_SYMBOL_H_ + +#include "Symbol.h" + +namespace alphabet { + +/** + * Represents blank symbol in an alphabet. + */ +class BottomOfTheStackSymbol : public std::element<BottomOfTheStackSymbol, SymbolBase> { +public: + /** + * Creates a blank symbol. + * @param symbol name of the symbol + */ + BottomOfTheStackSymbol(); + + virtual SymbolBase* clone() const; + virtual SymbolBase* plunder() &&; + + virtual bool operator <(const SymbolBase& other) const; + virtual bool operator ==(const SymbolBase& other) const; + virtual bool operator >(const SymbolBase& other) const; + + virtual bool operator ==(const BottomOfTheStackSymbol& other) const; + virtual bool operator <(const BottomOfTheStackSymbol& other) const; + + virtual void operator>>(std::ostream& out) const; + + virtual operator std::string () const; + + static BottomOfTheStackSymbol BOTTOM_OF_THE_STACK; +}; + +} /* namespace alphabet */ + +#endif /* BOTTOM_OF_THE_STACK_SYMBOL_H_ */ diff --git a/alib2/src/alphabet/SymbolBase.cpp b/alib2/src/alphabet/SymbolBase.cpp index 58e7c3300ec84b0bfc9261ffffc2d6f34ce66221..9027bb867202d7e09bad09342187231ae0f5ba1b 100644 --- a/alib2/src/alphabet/SymbolBase.cpp +++ b/alib2/src/alphabet/SymbolBase.cpp @@ -10,6 +10,7 @@ #include "LabeledSymbol.h" #include "BlankSymbol.h" +#include "BottomOfTheStackSymbol.h" namespace alphabet { @@ -34,6 +35,10 @@ bool SymbolBase::operator==(const BlankSymbol&) const { return false; } +bool SymbolBase::operator==(const BottomOfTheStackSymbol&) const { + return false; +} + bool SymbolBase::operator<(const LabeledSymbol& other) const { return typeid(*this).before(typeid(other)); } @@ -42,4 +47,8 @@ bool SymbolBase::operator<(const BlankSymbol& other) const { return typeid(*this).before(typeid(other)); } +bool SymbolBase::operator<(const BottomOfTheStackSymbol& other) const { + return typeid(*this).before(typeid(other)); +} + } /* namespace alphabet */ diff --git a/alib2/src/alphabet/SymbolBase.h b/alib2/src/alphabet/SymbolBase.h index 8b61aa1e2a13e5a5a79e7d7d89c8a0dd8e7d6f01..7aee1dd6768166e1fff53830ee6af5fe36fd1aa6 100644 --- a/alib2/src/alphabet/SymbolBase.h +++ b/alib2/src/alphabet/SymbolBase.h @@ -15,11 +15,12 @@ namespace alphabet { class LabeledSymbol; class BlankSymbol; +class BottomOfTheStackSymbol; /** * Represents symbol in an alphabet. */ -class SymbolBase : public std::elementBase<LabeledSymbol, BlankSymbol> { +class SymbolBase : public std::elementBase<LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol> { public: virtual ~SymbolBase() noexcept; @@ -33,9 +34,11 @@ public: virtual bool operator==(const LabeledSymbol& other) const; virtual bool operator==(const BlankSymbol& other) const; + virtual bool operator==(const BottomOfTheStackSymbol& other) const; virtual bool operator<(const LabeledSymbol& other) const; virtual bool operator<(const BlankSymbol& other) const; + virtual bool operator<(const BottomOfTheStackSymbol& other) const; friend std::ostream& operator<<(std::ostream&, const SymbolBase&); diff --git a/alib2/src/alphabet/SymbolFromStringLexer.cpp b/alib2/src/alphabet/SymbolFromStringLexer.cpp index 281064ae2ad4222ab813858b95ed40afc066c67c..aad58e353c3bb1803e48685dd1dd521449264e32 100644 --- a/alib2/src/alphabet/SymbolFromStringLexer.cpp +++ b/alib2/src/alphabet/SymbolFromStringLexer.cpp @@ -37,6 +37,9 @@ L1: } else if(character == 'B') { m_Current.type = TokenType::BLANK; return *this; + } else if(character == 'Z') { + m_Current.type = TokenType::BOTTOM; + return *this; } else { m_In.seekg(pos); m_Current.type = TokenType::ERROR; diff --git a/alib2/src/alphabet/SymbolFromStringLexer.h b/alib2/src/alphabet/SymbolFromStringLexer.h index 5667d05ebed16ca1dafa6241eaf679f75103d33b..83f46d61ad88dd3cd8906204b1999d7cd9e07a1b 100644 --- a/alib2/src/alphabet/SymbolFromStringLexer.h +++ b/alib2/src/alphabet/SymbolFromStringLexer.h @@ -10,6 +10,7 @@ class SymbolFromStringLexer { public: enum class TokenType { BLANK, + BOTTOM, TEOF, ERROR, }; diff --git a/alib2/src/alphabet/SymbolFromStringParser.cpp b/alib2/src/alphabet/SymbolFromStringParser.cpp index cf1cd464dab1d11efee2b10b8e87edbad1ceae1f..66a8635e1d96d34476ea470a8132264fe1308c21 100644 --- a/alib2/src/alphabet/SymbolFromStringParser.cpp +++ b/alib2/src/alphabet/SymbolFromStringParser.cpp @@ -1,6 +1,7 @@ #include "SymbolFromStringParser.h" #include "../AlibException.h" #include "BlankSymbol.h" +#include "BottomOfTheStackSymbol.h" #include "LabeledSymbol.h" namespace alphabet { @@ -14,6 +15,8 @@ Symbol* SymbolFromStringParser::parse() { switch(token.type) { case SymbolFromStringLexer::TokenType::BLANK: return new Symbol(BlankSymbol()); + case SymbolFromStringLexer::TokenType::BOTTOM: + return new Symbol(BottomOfTheStackSymbol()); case SymbolFromStringLexer::TokenType::ERROR: { label::Label* label = m_LabelParser.parse(); if(label != NULL) { diff --git a/alib2/src/alphabet/SymbolFromXMLParser.cpp b/alib2/src/alphabet/SymbolFromXMLParser.cpp index 92bbfa6b419d37173e88b86dcfa28f6037653edd..650cd201ccdeced3c6af2121904fe8f9dadbc03e 100644 --- a/alib2/src/alphabet/SymbolFromXMLParser.cpp +++ b/alib2/src/alphabet/SymbolFromXMLParser.cpp @@ -9,6 +9,7 @@ #include "../sax/ParserException.h" #include "BlankSymbol.h" +#include "BottomOfTheStackSymbol.h" #include "LabeledSymbol.h" #include "../label/Label.h" @@ -26,6 +27,10 @@ Symbol SymbolFromXMLParser::parse(std::list<sax::Token>& input) const { popToken(input, sax::Token::TokenType::START_ELEMENT, "BlankSymbol"); popToken(input, sax::Token::TokenType::END_ELEMENT, "BlankSymbol"); return Symbol(BlankSymbol()); + } else if(isToken(input, sax::Token::TokenType::START_ELEMENT, "BottomOfTheStackSymbol")) { + popToken(input, sax::Token::TokenType::START_ELEMENT, "BottomOfTheStackSymbol"); + popToken(input, sax::Token::TokenType::END_ELEMENT, "BottomOfTheStackSymbol"); + return Symbol(BlankSymbol()); } else { throw sax::ParserException(sax::Token("", sax::Token::TokenType::START_ELEMENT), input.front()); } diff --git a/alib2/src/alphabet/SymbolToStringComposer.cpp b/alib2/src/alphabet/SymbolToStringComposer.cpp index 5c49ef29687be52b87ccebf7f033a5fafe27410c..3788626c9486b0eb4bdcd954c66890616a577492 100644 --- a/alib2/src/alphabet/SymbolToStringComposer.cpp +++ b/alib2/src/alphabet/SymbolToStringComposer.cpp @@ -8,7 +8,6 @@ #include "SymbolToStringComposer.h" #include "../label/LabelToStringComposer.h" #include <algorithm> -#include "../label/Label.h" #include "LabeledSymbol.h" namespace alphabet { @@ -26,6 +25,12 @@ void SymbolToStringComposer::Visit(void* userData, const BlankSymbol&) { out << "#B"; } +void SymbolToStringComposer::Visit(void* userData, const BottomOfTheStackSymbol&) { + std::stringstream &out = *((std::stringstream*) userData); + + out << "#Z"; +} + void SymbolToStringComposer::Visit(void* userData, const Symbol& symbol) { symbol.getSymbol().Accept(userData, *this); diff --git a/alib2/src/alphabet/SymbolToStringComposer.h b/alib2/src/alphabet/SymbolToStringComposer.h index 4f4b16837d64cbe0e35f2ccf58a9b0061263bd44..237e61f69c9876c07b4ccc10fbcfb9739410b7d4 100644 --- a/alib2/src/alphabet/SymbolToStringComposer.h +++ b/alib2/src/alphabet/SymbolToStringComposer.h @@ -22,6 +22,8 @@ class SymbolToStringComposer : public SymbolBase::visitor_type { void Visit(void*, const Symbol& symbol); void Visit(void*, const LabeledSymbol& symbol); void Visit(void*, const BlankSymbol& symbol); + void Visit(void*, const BottomOfTheStackSymbol& symbol); + public: /** * Prints text representation of Symbol to the output stream. diff --git a/alib2/src/alphabet/SymbolToXMLComposer.cpp b/alib2/src/alphabet/SymbolToXMLComposer.cpp index f6a25fc10a8594d2ea87fdd8a628b23f7125d51c..cd6e06dd38859cbda7291994e1f5648a31afb8ee 100644 --- a/alib2/src/alphabet/SymbolToXMLComposer.cpp +++ b/alib2/src/alphabet/SymbolToXMLComposer.cpp @@ -6,7 +6,6 @@ */ #include "SymbolToXMLComposer.h" -#include "LabeledSymbol.h" #include "../ToXMLComposers.h" @@ -19,6 +18,13 @@ void SymbolToXMLComposer::Visit(void* userData, const BlankSymbol&) const { out.push_back(sax::Token("BlankSymbol", sax::Token::TokenType::END_ELEMENT)); } +void SymbolToXMLComposer::Visit(void* userData, const BottomOfTheStackSymbol&) const { + std::list<sax::Token> &out = *((std::list<sax::Token>*) userData); + + out.push_back(sax::Token("BottomOfTheStackSymbol", sax::Token::TokenType::START_ELEMENT)); + out.push_back(sax::Token("BottomOfTheStackSymbol", sax::Token::TokenType::END_ELEMENT)); +} + void SymbolToXMLComposer::Visit(void* userData, const LabeledSymbol& symbol) const { std::list<sax::Token> &out = *((std::list<sax::Token>*) userData); diff --git a/alib2/src/alphabet/SymbolToXMLComposer.h b/alib2/src/alphabet/SymbolToXMLComposer.h index ab826bfd79ff6778322b3fe2a2a597fcb4614150..e83d301fb06b16f8bcf5b599cf08b9864589d90c 100644 --- a/alib2/src/alphabet/SymbolToXMLComposer.h +++ b/alib2/src/alphabet/SymbolToXMLComposer.h @@ -22,6 +22,7 @@ class SymbolToXMLComposer : public SymbolBase::const_visitor_type { void Visit(void*, const Symbol& symbol) const; void Visit(void*, const LabeledSymbol& symbol) const; void Visit(void*, const BlankSymbol& symbol) const; + void Visit(void*, const BottomOfTheStackSymbol& symbol) const; public: /** diff --git a/alib2/src/label/LabelFromXMLParser.cpp b/alib2/src/label/LabelFromXMLParser.cpp index 66b345c04035c47992ffa212961400e3d3d40ca6..43995a545d69a6cde423ec080b168b5c5791031a 100644 --- a/alib2/src/label/LabelFromXMLParser.cpp +++ b/alib2/src/label/LabelFromXMLParser.cpp @@ -35,4 +35,4 @@ Label LabelFromXMLParser::parse(std::list<sax::Token>& input) const { } } -} /* namespace string */ +} /* namespace label */