//---------------------------------------------------------------------------

#ifndef benchH
#define benchH
#include <string>
#include <list>
#include <set>

#include "lexan_bench.h"
#include "import.h"

class TVnejsi;

class Pole {
	int velikost;
	void Zvetsi() {
		std::string *pom = new std::string[velikost*2];
		for (int i = 0; i<velikost; i++) pom[i] = p[i];
		velikost *= 2;
		delete[] p;
		p = pom;
	}
  public:
	int index;
	std::string *p;
	Pole() {
		index = 0;
		velikost = 10;
		p = new std::string[10];
	}
	~Pole() {
		delete[] p;
	}
	void Vloz(std::string co) {
		if (index >=velikost) Zvetsi();
		p[index++] = co;
	}
};

struct Hradlo {
	std::string typ;  // or,and,...
	list<std::string> inputs;
	TVnejsi *hotove_hradlo[2];  // pole dvou ukazatelu na TVnejsi, podle promenne negace, kdyz  false tak [0], true tak polozka [1]
};


// --------------------------------------------------------------------------
class BenchParserClient { 
public:
	Pole *input;
	list<std::string> output;
	map<std::string,Hradlo> hradla;
	multiset<std::string> vystup_hradla;

    // ---- interface to semantic classes - callbacks
    virtual void haveDesign (void);
    virtual void endDesign (void);
    virtual void haveInPort  (const std::string& portName);
    virtual void haveOutPort (const std::string& portName);
    virtual void haveAssign (const std::string& outputName, 
			     int function,		// lexical symbol 
			     const list<std::string> listInputNames);
	BenchParserClient() {
		input = new Pole();
	}
    virtual ~BenchParserClient ();
};

// --------------------------------------------------------------------------
class BenchParser {
    // ----- link to semantic actions
	BenchParserClient* client_;
    
    // ----- actions
    void inputs();
    void outputs();
    void assigns();
    void hradlo(list<std::string> *);
    void idents(list<std::string> *);
    void r_o_idents(list<std::string> *);

public:
    // ---- lexical analysis and current token
    LexanBench l;
    int token;

    // ---- start import
    void run (const std::string&);	// start the analysis with filename
    BenchParser(BenchParserClient* client): client_(client) {}
    ~BenchParser() {}
};
//---------------------------------------------------------------------------
#endif
