//---------------------------------------------------------------------------
#include "pla_parser.h"
//---------------------------------------------------------------------------
void PlaParser::run(std::istream& istr, const std::string& fn) {
    int inputNo, outputNo, i;
    std::list<std::string> plaMatrix;
    std::list<std::string> inputNames;
    std::list<std::string> outputNames;
    std::string type;

    l.init(istr, fn);
    token = l.NextToken();
    while (token != LEX_PLA_NULL ) {
        switch (token) {
        case LEX_PLA_INPUT:
            token = l.CheckNextToken(LEX_PLA_NUMB);
            inputNo = l.Lex_AInt;
            token = l.NextToken();
            break;

        case LEX_PLA_OUTPUT:
            token = l.CheckNextToken(LEX_PLA_NUMB);
            outputNo = l.Lex_AInt;
            token = l.NextToken();
            break;

        case LEX_PLA_INPUTNAMES:
            for( i = 0; i < inputNo; i++ ) {
                token = l.CheckNextToken(LEX_PLA_IDENT);
                inputNames.push_back(l.Lex_AStr);
            }
            token = l.NextToken();
            break;

        case LEX_PLA_OUTPUTNAMES:
            for( i = 0; i < outputNo; i++ ) {
                token = l.CheckNextToken(LEX_PLA_IDENT);
                outputNames.push_back(l.Lex_AStr);
            }
            token = l.NextToken();
            break;

        case LEX_PLA_TYPE:
            token = l.CheckNextToken(LEX_PLA_IDENT);
            type = l.Lex_AStr;
            token = l.NextToken();
            break;

        case LEX_PLA_MATRIXROW:
            while( token == LEX_PLA_MATRIXROW ) {
                plaMatrix.push_back(l.Lex_AStr);
                token = l.NextToken();
            }
            break;

        default:
            token = l.NextToken();
            break;
        }
    }
    if( type.empty() ) type = "fd";  //default
    client_->haveDescription(type, inputNo, outputNo, inputNames, outputNames, plaMatrix);
}
//---------------------------------------------------------------------------
void PlaParserClient::haveDescription(std::string& type, int inNo, int outNo, std::list<std::string>& a, 
							   std::list<std::string>& b, std::list<std::string> &matrix) {}
void PlaParserClient::haveInPorts(int portsCount, std::list<std::string> portsNames) {}
void PlaParserClient::haveOutPorts(int portsCount, std::list<std::string> portsNames) {}

