Skip to content
Snippets Groups Projects
Commit b51e1850 authored by Martin Kočička's avatar Martin Kočička Committed by Jan Trávníček
Browse files

added label for LR(0) automaton states

parent cee127d1
No related branches found
No related tags found
1 merge request!18Bp kocicma3
/*
* LR0ItemsLabel.cpp
*
* Created on: 29. 4. 2016
* Author: Martin Kocicka
*/
#include "LR0ItemsLabel.h"
#include <sax/FromXMLParserHelper.h>
#include "Label.h"
#include <object/Object.h>
#include <XmlApi.hpp>
#include "UniqueLabel.h"
#include "../container/ObjectsMap.h"
#include "../container/ObjectsSet.h"
#include "../container/ObjectsVector.h"
#include "../primitive/Unsigned.h"
namespace label {
LR0ItemsLabel::LR0ItemsLabel ( grammar::parsing::LR0Items items ) : items ( items ) {
}
LR0ItemsLabel::LR0ItemsLabel ( ) {
}
LabelBase* LR0ItemsLabel::clone ( ) const {
return new LR0ItemsLabel ( *this );
}
LabelBase* LR0ItemsLabel::plunder ( ) && {
return new LR0ItemsLabel ( std::move ( *this ) );
}
bool LR0ItemsLabel::operator < ( const LR0ItemsLabel & other ) const {
return this->compare(other) < 0;
}
int LR0ItemsLabel::compare ( const LR0ItemsLabel & other ) const {
if ( items < other.items ) {
return -1;
} else if ( items > other.items ) {
return 1;
} else {
return 0;
}
}
void LR0ItemsLabel::operator>>(std::ostream & out) const {
out << "(LR0ItemsLabel " << items << ")";
}
LR0ItemsLabel::operator std::string ( ) const {
std::stringstream ss;
ss << *this;
return ss.str ( );
}
const std::string LR0ItemsLabel::XML_TAG_NAME = "LR0ItemsLabel";
LR0ItemsLabel LR0ItemsLabel::parse ( std::deque<sax::Token>::iterator& input ) {
sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, LR0ItemsLabel::XML_TAG_NAME );
LR0ItemsLabel data ( alib::xmlApi < grammar::parsing::LR0Items > ::parse ( input ) );
sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, LR0ItemsLabel::XML_TAG_NAME );
return data;
}
void LR0ItemsLabel::compose(std::deque<sax::Token>& out) const {
out.emplace_back ( LR0ItemsLabel::XML_TAG_NAME, sax::Token::TokenType::START_ELEMENT );
alib::xmlApi < grammar::parsing::LR0Items > ::compose ( out, items );
out.emplace_back ( LR0ItemsLabel::XML_TAG_NAME, sax::Token::TokenType::END_ELEMENT );
}
LabelBase* LR0ItemsLabel::next ( ) const {
return new UniqueLabel ( Label ( *this ), primitive::Integer ( 0 ) );
}
LabelBase* LR0ItemsLabel::inc ( ) && {
return new UniqueLabel ( Label ( std::move ( *this ) ), primitive::Integer ( 0 ) );
}
} /* namespace label */
namespace alib {
auto lr0ItemsLabelParserRegister = xmlApi < label::Label > ::ParserRegister < label::LR0ItemsLabel > ( );
auto lr0ItemsLabelParserRegister2 = xmlApi < alib::Object > ::ParserRegister < label::LR0ItemsLabel > ( );
} /* namespace alib */
/*
* LR0ItemsLabel.h
*
* Created on: 29. 4. 2016
* Author: Martin Kocicka
*/
#ifndef LR0ITEMS_LABEL_H_
#define LR0ITEMS_LABEL_H_
#include <map>
#include <set>
#include <vector>
#include <object/Object.h>
#include "LabelBase.h"
#include "Label.h"
#include "../alphabet/Symbol.h"
#include "../grammar/parsing/LRParserTypes.h"
namespace label {
/**
* Represents symbol in an alphabet.
*/
class LR0ItemsLabel : public LabelBase {
protected:
grammar::parsing::LR0Items items;
public:
/**
* Creates new symbol with given name.
* @param symbol name of the symbol
*/
explicit LR0ItemsLabel ( grammar::parsing::LR0Items items );
/**
* Creates new symbol with given name.
* @param symbol name of the symbol
*/
explicit LR0ItemsLabel ( );
virtual LabelBase * clone ( ) const;
virtual LabelBase * plunder ( ) &&;
const grammar::parsing::LR0Items & getItems ( ) const {
return items;
}
grammar::parsing::LR0Items & getItems ( ) {
return items;
}
virtual int compare ( const ObjectBase & other ) const {
if ( std::type_index ( typeid ( * this ) ) == std::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other );
return std::type_index ( typeid ( * this ) ) - std::type_index ( typeid ( other ) );
}
virtual int compare ( const LR0ItemsLabel & other ) const;
bool operator < (const LR0ItemsLabel& other) const;
virtual void operator >>( std::ostream & ) const;
virtual explicit operator std::string ( ) const;
const static std::string XML_TAG_NAME;
static LR0ItemsLabel parse ( std::deque < sax::Token >::iterator & input );
void compose ( std::deque < sax::Token > & out ) const;
virtual LabelBase * next ( ) const;
virtual LabelBase * inc ( ) &&;
};
} /* namespace label */
namespace std {
template < >
struct compare < label::LR0ItemsLabel > {
int operator ()( const label::LR0ItemsLabel & first, const label::LR0ItemsLabel & second ) const {
return first.compare ( second );
}
};
} /* namespace std */
#endif /* LR0ITEMS_LABEL_H_ */
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